User Tools

Site Tools


raspberrypi:ina219

This is an old revision of the document!


INA219 I2C Zero Drift Bi-directional Current Power Supply Sensor Breakout Monitoring Module

matuoja voltus ir amperus, galima nustatyti kiek naudoja jėgos tavo variklis ir ar toli baterijai iki mirties

labai gerai valdosi su python:

https://pypi.python.org/pypi/pi-ina219/1.1.0

galima panaudoti matuoti baterijos talpą, ta ir bandau padaryti:

#!/usr/bin/env 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 "Power: %.3f mW" % ina.power()
        print "Shunt voltage: %.3f mV" % ina.shunt_voltage()
 
        with open("curr_volt_read_log.csv", "a") as myfile:
            myfile.write(datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S.%f') + "," + '%.3f' % ina.voltage() + "," + '%.3f' % ina.current() + "," + '%.3f' % ina.power() + "," + '%.3f' % ina.shunt_voltage() + '\n')
 
    except DeviceRangeError as e:
        # Current out of device range with specified shunt resister
        print e
 
    threading.Timer(1, read).start()
 
if __name__ == "__main__":
    read()

piesiai matlab:

%% read temperature log file and plot chart
fileID = fopen('\\aistis\pihome\home\pi\ina219\curr_volt_read_log.csv','r');
C = textscan(fileID,'%s %f %f %f %f','Delimiter',',');
fclose(fileID);
 
d.date = datenum(C{1},'yyyy-mm-dd HH:MM:SS.FFF');
d.voltage = C{2};
d.current = C{3};
d.power = C{4};
d.shunt_voltage = C{5};
 
figure(1);clf; title('NighKonic NCR18650 battery discharge');
subplot(3,1,1);plot(d.date,d.voltage);dynamicDateTicks;grid on; xlabel('time'); ylabel('voltage (V)');
subplot(3,1,2);plot(d.date,d.current);dynamicDateTicks;grid on; xlabel('time'); ylabel('current (mA)');
subplot(3,1,3);plot(d.date,d.power);dynamicDateTicks;grid on; xlabel('time'); ylabel('power (mW)');
raspberrypi/ina219.1489838762.txt.gz · Last modified: by aistis