2020-02-06, 05:39 PM
I decided to order an INA219 board and to connect it directly to the pi, and not use an ESP8266 or Arduino to send the values to the Pi, but connect it directly to I2c / SDA and SDL. Hardware works and when I run the following script I get the readings:
Readings:
So, the board works.
I can't however for the life of me get these values into SignalK. The current available tools scripts for INA219 seem to be designed for usage with the ESP8266. What script do I use to use the INA219 directly on i2C of the pi?
Hope someone can help.
Regards,
Jamos
Code:
#!/usr/bin/env python
import logging
from ina219 import INA219
SHUNT_OHMS = 0.01
MAX_EXPECTED_AMPS = 10
def read():
ina = INA219(SHUNT_OHMS, MAX_EXPECTED_AMPS, log_level=logging.INFO)
ina.configure(ina.RANGE_16V, ina.GAIN_AUTO)
print("Bus Voltage : %.3f V" % ina.voltage())
print("Bus Current : %.3f mA" % ina.current())
print("Supply Voltage : %.3f V" % ina.supply_voltage())
print("Shunt voltage : %.3f mV" % ina.shunt_voltage())
print("Power : %.3f mW" % ina.power())
if __name__ == "__main__":
read()
Readings:
Code:
2020-02-06 17:25:28,198 - INFO - INA219 gain set to 0.16V
2020-02-06 17:25:28,200 - INFO - INA219 calibrate called with: bus max volts: 16V, max shunt volts: 0.16V, max expected amps: 10.000A
2020-02-06 17:25:28,201 - INFO - INA219 max possible current: 16.000A
2020-02-06 17:25:28,201 - INFO - INA219 max expected current: 10.000A
2020-02-06 17:25:28,202 - INFO - INA219 current LSB: 6.250e-05 A/bit
2020-02-06 17:25:28,202 - INFO - INA219 power LSB: 1.250e-03 W/bit
2020-02-06 17:25:28,203 - INFO - INA219 max current before overflow: 2.0480A
2020-02-06 17:25:28,204 - INFO - INA219 max shunt voltage before overflow: 20.4800mV
2020-02-06 17:25:28,205 - INFO - INA219 calibration: 0xfffe (65534)
Bus Voltage : 12.464 V
Bus Current : 108.003 mA
Supply Voltage : 12.453 V
Shunt voltage : 1.140 mV
Power : 1542.547 mW
So, the board works.
I can't however for the life of me get these values into SignalK. The current available tools scripts for INA219 seem to be designed for usage with the ESP8266. What script do I use to use the INA219 directly on i2C of the pi?
Hope someone can help.
Regards,
Jamos