INA219 directly on i2c of Pi without ESP8266 - Printable Version +- OpenMarine (https://forum.openmarine.net) +-- Forum: OpenPlotter (https://forum.openmarine.net/forumdisplay.php?fid=1) +--- Forum: How do I...? (https://forum.openmarine.net/forumdisplay.php?fid=3) +--- Thread: INA219 directly on i2c of Pi without ESP8266 (/showthread.php?tid=2305) Pages:
1
2
|
INA219 directly on i2c of Pi without ESP8266 - jamos.tan@gmail.com - 2020-02-06 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: Code: #!/usr/bin/env python Readings: Code: 2020-02-06 17:25:28,198 - INFO - INA219 gain set to 0.16V 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 RE: INA219 directly on i2c of Pi without ESP8266 - Sailoog - 2020-02-06 This is a good candidate to be added to openplotter-i2c app. Do you know what is the most used module? RE: INA219 directly on i2c of Pi without ESP8266 - jamos.tan@gmail.com - 2020-02-06 (2020-02-06, 06:05 PM)Sailoog Wrote: This is a good candidate to be added to openplotter-i2c app. Do you know what is the most used module? It is the one from this tutorial: https://www.youtube.com/watch?v=BgShCD7xT_A RE: INA219 directly on i2c of Pi without ESP8266 - Sailoog - 2020-02-06 OK, I see. It seems that addresses can be defined but default is 40. the problem is that some extra settings are needed: SHUNT_OHMS = 0.01 MAX_EXPECTED_AMPS = 10 I should add changes in i2c app to allow extra settings but it will be useful for future sensors. I will try to do something soon. RE: INA219 directly on i2c of Pi without ESP8266 - jamos.tan@gmail.com - 2020-02-06 Thanks! The default values for this is: SHUNT_OHMS = 0.1 MAX_EXPECTED_AMPS = 0.3 But I changed them too 0.01 and 10 because of an extra shunt to measure more current in my setup: SHUNT_OHMS = 0.01 MAX_EXPECTED_AMPS = 10 RE: INA219 directly on i2c of Pi without ESP8266 - jamos.tan@gmail.com - 2020-02-07 By the way, maybe slightly off topic, but do you ever receive the error "ImportError: cannot import name INA219" I am having this error with the original INA219.py script downloadable from https://github.com/sailoog/openplotter/blob/master/tools/analog_ina219.py Hope you can assist. RE: INA219 directly on i2c of Pi without ESP8266 - Sailoog - 2020-02-07 buff I did not remember we had already done this forget that script, that is for OP1 and pyhon2 For OP2 you have to install ina219 module for python3: sudo pip3 install pi-ina219 RE: INA219 directly on i2c of Pi without ESP8266 - jamos.tan@gmail.com - 2020-02-07 (2020-02-07, 12:37 PM)Sailoog Wrote: buff I did not remember we had already done this Haha! No worries, happens to the best of us. I am running 1.2.0 alpha, and installed both: sudo pip install pi-ina219 sudo pip3 install pi-ina219 When trying the corresponding commands I get: Python command: Code: pi@openplotter:~/.openplotter/tools/ina219 $ sudo python ina219.py Python3 command: Code: pi@openplotter:~/.openplotter/tools/ina219 $ python3 ina219.py Can I still make it work in 1.2.0. alpha? I can't upgrade that easily to 2. Have it running on a Pi 4 with 4GB to test, but my main system is still 1.2.0 for a while. Hope you can help! RE: INA219 directly on i2c of Pi without ESP8266 - e-sailing - 2020-02-09 The code example for python3 openplotter 2.0 is: Code: #!/usr/bin/env python3 And you have to setup a signalk connection on port 20220. For 1.2: I think the library has changed. You have to change line 45 /home/pi/.config/openplotter/tools/analog_ina219/analog_ina219.py to Code: ina = INA219(SHUNT_OHMS,1.0,1,0x41) There is also a chance to read ina219 by node-red (advantage less cpu power consumption) cd .signalk/red npm install ina219 git clone https://github.com/easybotics/node-red-contrib-easybotics-ina219.git cd node-red-contrib-easybotics-ina219 npm install sudo npm link This link must be moved or copied to .signalk/red/node_modules cp /usr/lib/node_modules/node-red-contrib-easybotics-ina219-sensor /home/pi/.signalk/red/node_modules Code: [{"id":"9dd53318.b65b58","type":"ina-sensor","z":"413e23b8.c0b474","name":"","handle":"cd4c02a9.2f45b","x":510,"y":120,"wires":[["4ac9724a.23dc94"],["f3918cff.9c8ab8"]]},{"id":"5d9fe981.6e7708","type":"signalk-send-pathvalue","z":"413e23b8.c0b474","name":"","source":"","x":1030,"y":120,"wires":[]},{"id":"f3918cff.9c8ab8","type":"function","z":"413e23b8.c0b474","name":"current&power","func":"msg.topic = \"electrical.batteries.rpi.current\";\nmsg.payload = Number(msg.payload)/1000;\nnode.send(msg);\nmsg.topic = \"electrical.batteries.rpi.power\";\nmsg.payload = Number(flow.get('voltage'))*Number(msg.payload);\nreturn msg;","outputs":1,"noerr":0,"x":740,"y":180,"wires":[["5d9fe981.6e7708"]]},{"id":"4ac9724a.23dc94","type":"function","z":"413e23b8.c0b474","name":"voltage","func":"msg.topic = \"electrical.batteries.rpi.voltage\";\nflow.set('voltage', msg.payload);\nreturn msg;","outputs":1,"noerr":0,"x":720,"y":120,"wires":[["5d9fe981.6e7708"]]},{"id":"cd4c02a9.2f45b","type":"ina-sensor-manager","z":"","address":"0x41","delay":"1000","ohms":"0.01","customResistor":false}] RE: INA219 directly on i2c of Pi without ESP8266 - jamos.tan@gmail.com - 2020-02-09 Thanks for the clarification e-sailing! Tried the modifications, but still get the ImportError: cannot import name INA219 |