Micropython library for the TI INA219 voltage/current sensor

Discuss development of drivers for external hardware and components, such as LCD screens, sensors, motor drivers, etc.
Target audience: Users and developers of drivers.
chrisb2
Posts: 22
Joined: Sat Apr 01, 2017 4:19 am

Micropython library for the TI INA219 voltage/current sensor

Post by chrisb2 » Tue May 16, 2017 8:29 am

https://github.com/chrisb2/pyb_ina219

I have written this library based on one I wrote for the Raspberry Pi. It supports the INA219 voltage, current and power monitor sensor from Texas Instruments. The intent of the library is to make it easy to use the quite complex functionality of this sensor.

Its currently under development, with the next step being porting the unit tests from the Raspberry Pi version. Manual testing shows the functionality working as expected.

Feedback and suggestions welcome. I am quite new to MicroPython.

Chris

chrisb2
Posts: 22
Joined: Sat Apr 01, 2017 4:19 am

Re: Micropython library for the TI INA219 voltage/current sensor

Post by chrisb2 » Sat May 20, 2017 9:55 am

I have updated this library to use machine.I2C instead of pyb.I2C, so it should now work on all MicroPython hardware, though I have only have a pyboard to test with. Let me know if you successfully use it with other hardware.

Chris

User avatar
deshipu
Posts: 1364
Joined: Thu May 28, 2015 5:54 pm

Re: Micropython library for the TI INA219 voltage/current sensor

Post by deshipu » Sun May 28, 2017 6:14 am

Very nice! I wonder if we could move this thread to the "Drivers for External Components" section?

chrisb2
Posts: 22
Joined: Sat Apr 01, 2017 4:19 am

Re: Micropython library for the TI INA219 voltage/current sensor

Post by chrisb2 » Sun May 28, 2017 6:53 am

I looked around for an option to do that, but could not find one, maybe an Admin can do it?

thanks,
Chris

torwag
Posts: 219
Joined: Fri Dec 13, 2013 9:25 am

Re: Micropython library for the TI INA219 voltage/current sensor

Post by torwag » Sun May 28, 2017 6:59 am

Moved to driver section...

chrisb2
Posts: 22
Joined: Sat Apr 01, 2017 4:19 am

Re: Micropython library for the TI INA219 voltage/current sensor

Post by chrisb2 » Sun Jun 25, 2017 3:55 am

I have now verified this library works with an esp8266 (NodeMCU clone), see Using the Library on an ESP8266

chrisb2
Posts: 22
Joined: Sat Apr 01, 2017 4:19 am

Re: Micropython library for the TI INA219 voltage/current sensor

Post by chrisb2 » Thu Sep 28, 2017 7:20 am

I have now verified this library works with an esp32 (Lolin32 Lite), see Using the Library on an ESP32

Online
elschopi
Posts: 9
Joined: Tue May 12, 2020 5:12 am
Location: Bavaria, Germany

Re: Micropython library for the TI INA219 voltage/current sensor

Post by elschopi » Wed May 20, 2020 1:16 pm

Hello all,
I am searching for a micropython driver for the TI INA226, and as this is its little brother, I guessed I might as well ask here instead of opening a new thread.
I'm quite new to (micro)python (or programming in itself), so writing my own library is out of the question :)
On another note, would it be possible to convert a python library to a micropython one, or vice versa?

Best regards and thanks in advance,
Chris

chrisb2
Posts: 22
Joined: Sat Apr 01, 2017 4:19 am

Re: Micropython library for the TI INA219 voltage/current sensor

Post by chrisb2 » Thu May 21, 2020 8:25 am

I had a quick look at ina226 datasheet and it seems to me to be pretty similar to ina219, it might not be to hard to make appropriate changes to my library by carefully reading both data sheets. I would pay particular attention to the calibration algorithm.

Micropython to Python should not be hard, but going the other way can be tricky due to resource limitations on mcu. I wrote the ina219 library for Raspberry Pi ( https://github.com/chrisb2/pi_ina219) first, it was easy to convert. Perhaps start by looking at my two libraries will help you convert https://github.com/neutronstriker/INA22 ... ardvark.py.

Regards,
Chris

User avatar
Roberthh
Posts: 2055
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Micropython library for the TI INA219 voltage/current sensor

Post by Roberthh » Thu May 21, 2020 9:28 am

I derived once an Adafruit driver to work with the INA219. At that time, the Adafruit stuff was still easy to deal with. So the only thing to change was the way of reading and writing to I2C. I uploaded my version to https://github.com/robert-hh/INA219.

Post Reply