raspberrypi:ina219
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| raspberrypi:ina219 [2017/03/18 14:02] – created aistis | raspberrypi:ina219 [2017/03/18 14:09] (current) – aistis | ||
|---|---|---|---|
| Line 5: | Line 5: | ||
| matuoja voltus ir amperus, galima nustatyti kiek naudoja jėgos tavo variklis ir ar toli baterijai iki mirties | matuoja voltus ir amperus, galima nustatyti kiek naudoja jėgos tavo variklis ir ar toli baterijai iki mirties | ||
| + | labai gerai valdosi su python | ||
| + | instaliuoti biblioteka: | ||
| + | sudo pip uninstall pi-ina219 | ||
| + | sudo pip install pi-ina219 | ||
| + | https:// | ||
| + | |||
| + | Galima panaudoti matuoti baterijos talpą, ta ir bandau padaryti. Pajungiau apie 340 mA magneta kuris kaist po truputi ir valgo baterijos energija. Testuoju baterija: | ||
| + | |||
| + | {{: | ||
| + | |||
| + | {{: | ||
| + | |||
| + | <code python> | ||
| + | # | ||
| + | from ina219 import INA219 | ||
| + | from ina219 import DeviceRangeError | ||
| + | |||
| + | from datetime import datetime | ||
| + | import time, threading | ||
| + | |||
| + | SHUNT_OHMS = 0.1 | ||
| + | |||
| + | def read(): | ||
| + | ina = INA219(SHUNT_OHMS) | ||
| + | ina.configure() | ||
| + | |||
| + | print "Bus Voltage: %.3f V" % ina.voltage() | ||
| + | try: | ||
| + | print "Bus Current: %.3f mA" % ina.current() | ||
| + | print " | ||
| + | print "Shunt voltage: %.3f mV" % ina.shunt_voltage() | ||
| + | |||
| + | with open(" | ||
| + | myfile.write(datetime.utcnow().strftime(' | ||
| + | |||
| + | except DeviceRangeError as e: | ||
| + | # Current out of device range with specified shunt resister | ||
| + | print e | ||
| + | | ||
| + | threading.Timer(1, | ||
| + | |||
| + | if __name__ == " | ||
| + | read() | ||
| + | </ | ||
| + | |||
| + | |||
| + | piesiai matlab: | ||
| + | |||
| + | <code matlab> | ||
| + | %% read temperature log file and plot chart | ||
| + | fileID = fopen(' | ||
| + | C = textscan(fileID,' | ||
| + | fclose(fileID); | ||
| + | |||
| + | d.date = datenum(C{1},' | ||
| + | d.voltage = C{2}; | ||
| + | d.current = C{3}; | ||
| + | d.power = C{4}; | ||
| + | d.shunt_voltage = C{5}; | ||
| + | |||
| + | figure(1); | ||
| + | subplot(3, | ||
| + | subplot(3, | ||
| + | subplot(3, | ||
| + | </ | ||
raspberrypi/ina219.1489838528.txt.gz · Last modified: by aistis
