Page 1 of 1

INA3221 driver missing. Translate from CircuitPython?

Posted: Wed Dec 30, 2020 11:00 pm
by Roanyg
INA3221 is a 3 channels current sensor. Driver for circuitpython is made, but I cannot manage to make it work with Micropython.

https://github.com/barbudor/CircuitPython_INA3221

Can anyoune helpe me fix that i2c translation job?

Re: INA3221 driver missing. Translate from CircuitPython?

Posted: Thu Dec 31, 2020 6:40 am
by pythoncoder
The approach I use is to pass an initialised I2C bus to the constructor, in this case as the i2c_bus arg. This means that the caller must set baudrate and suchlike, but this facilitates sharing the bus with other devices which may use different args.

You'll need to rewrite the .write method to use i2c.writeto(self.i2c_addr, ...) and .read to use i2c.readfrominto(self.i2c_addr, buf).

In general, porting drivers from CircuitPython to MicroPython is not hard. Converting that to optimised MicroPython can be rather more involved, but may be unnecessary in this instance.

If you get this working you might want to post it on GitHub for others to use. It looks like a useful and impressive chip.

Re: INA3221 driver missing. Translate from CircuitPython?

Posted: Fri Jan 01, 2021 8:50 am
by Roanyg
I made this clone https://github.com/roarnyg/INA3221-Micropython. I have never ported any driver, so if I succseed, it will take some time / weeks. If you have any examples of ported I2C drivers from Circuitpython to Micropython, it could help me a lot.

Re: INA3221 driver missing. Translate from CircuitPython?

Posted: Fri Jan 01, 2021 1:12 pm
by pythoncoder
You could look at this one.

A beauty of MicroPython and I2C is that you can test it at the REPL. Use scan() to see if your hardware is detected and then fire commands at it, reading the responses. Once you understand how MicroPython uses I2C, swapping out the Adafruit code is easy.

Re: INA3221 driver missing. Translate from CircuitPython?

Posted: Fri Jan 01, 2021 1:28 pm
by Roanyg
Thanx. I will investigate this scan() function even more.

Libraries forRaspberry Pi / Python and the sensor INA3221 is allso written, https://github.com/search?q=ina3221. Will it be easier to port from python to micropython rather than from circuitpython?

Re: INA3221 driver missing. Translate from CircuitPython?

Posted: Sat Jan 02, 2021 5:42 am
by pythoncoder
My personal view is that CircuitPython is easier, but that may just be down to familiarity.