Page 2 of 3

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

Posted: Sat Jun 13, 2020 6:13 pm
by elschopi
Hello everyone,

and thank you all for your help (and sorry for the long time of being quiet). I've had to deal with a few work and study issues :mrgreen: which did consume most of my time and/or motivation.
I've managed to adapt https://github.com/robert-hh/INA219 to work with my INA226. I have yet to figure out the calibration of values, but so far it looks promising - measured and computed values are not too far off of what my DMM tell me. So far I have only modified the calibration routine for 32V and 2A, but will change the rest soon accordingly.
@Roberthh: I have no experience in publishing modified libraries or such, what do I need to add or delete in my version of your library so I fulfill licenses? I do want to make it available to the public, but I also do not want to violate any licensing.
As I see it, I'd need to include credits to you in the header, as well as keep the existing "MIT License" header, and the "Adafruit" stuff too?

Greetings

Chris

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

Posted: Sat Jun 13, 2020 8:09 pm
by Roberthh
Hi @elschopi, glad that it's working and that I could help. Looking at my drivers file, it seems to need some edit. Especially the hardware and software dependencies are not vaild.
About licensing: You have to copy/keep the header of file. And you have to include the first Authors copyright note. Do you not have to include me. I just changed the I2C access method, and that's just tiny change, way less than the work you have to adapt it to a INA226 device.

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

Posted: Sun Jun 14, 2020 5:35 pm
by elschopi
Thanks again for your help =)
I'm in the middle of re-arranging the config register values, after I just figured out the differences. Interestingly, even though the differences are quite significant, it works even with the config register values for the INA219 device.
As soon as I have implemented these changes (and tested them), I'll be able to release the library into the wild :lol:
Maybe I can put together a small helper tool in Google sheets or something like that for the configuration register.
Anyhow, I'm learning very much from this, which I am very happy about. I've never been too involved with anything software-ish, so programming concepts and bit/byte operations are not exactly my best field :lol: I'm more a hardware / circuit-design kind of guy.

Thanks everyone, and a nice rest of the sunday (which here is a rainday)

Best regards
Chris

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

Posted: Mon Jun 15, 2020 5:08 pm
by elschopi
Hello everyone,

I've managed to put it all together and am now proudly serving it on github under
https://github.com/elschopi/TI_INA226_micropython
I have a Google spreadsheet prepared for calculations and stuff, if anyone's interested - link is in the github readme.
Please feel free to educate me where and how I've done stupid things, as I'm not too experienced with this :lol:

Have a great day, and thanks to all for the great support

Best regards

Chris

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

Posted: Mon Jun 15, 2020 6:32 pm
by Roberthh
Hello Chris,
the driver looks fine. One comment: I just removed from my driver these lines at the header:

Code: Select all

Implementation Notes
--------------------
**Hardware:**
* `Adafruit INA219 High Side DC Current Sensor Breakout
   <https://www.adafruit.com/product/904>`_
* `Adafruit INA219 FeatherWing <https://www.adafruit.com/product/3650>`_
**Software and Dependencies:**
* Adafruit CircuitPython firmware (2.2.0+) for the ESP8622 and M0-based boards:
  https://github.com/adafruit/circuitpython/releases
* Adafruit's Bus Device library:
  https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
They simply do not apply. You copied these too, and in your driver they fit even worse.

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

Posted: Tue Jun 16, 2020 7:04 am
by elschopi
Hello Robert,

thanks for the feedback. I've removed these lines now, too.

Best regards,

Chris

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

Posted: Sun Jul 04, 2021 6:25 am
by zyghom
my dears, I am searching for INA260 library for Pico (micropython) but no success
I am assuming the libs you are mentioning here for other INAs are not compatible, right?
any hint please what to adjust in the existing libraries to have INA260 working on my Pico?

thank you

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

Posted: Sun Jul 04, 2021 6:46 am
by chrisb2
Seems like one option would be Circuitpython which has a ina260 library see:

https://learn.adafruit.com/getting-star ... cuitpython

https://learn.adafruit.com/adafruit-ina ... cuitpython

Chris

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

Posted: Sat Apr 29, 2023 9:29 am
by jcf
Hi Chris,
thanks a lot for the INA226 driver, and especially for the example in the code.
If I had seen that at the beginning I could have progressed much faster!
The datasheet is a pain to read, very confusing, mixing register values and electrical values, neglecting the units etc.
Once I had discovered your example, I got my chip to work.
:D

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

Posted: Mon May 01, 2023 7:06 pm
by jcf
Now as I wanted to document my work I noticed that I had done an error when calculating the Calibration value.

I have Rs = 0.002 Ohm and Imax = 15A.
That gives 0.5mA (rounded) for Current_LSB and 12.5mW for Power_LSB.
From that I deduce CAL = 5.12mV / (Current_LSB) = 5.12/ (0.5 * 0.002) = 5120
With this value I get wrong results for current and power.

The day before I had not paid attention and used a value of 25600 for the CAL, and this wrong value gave me the right results.

Strange, isn't it!?