Coder Social home page Coder Social logo

Comments (12)

barbudor avatar barbudor commented on July 21, 2024

Hi @kkellner
The easiest way is to extract from the zip the folder barbudor_ina3221\ and to copy/move it into your current directory.

-- your project dir\
        +-- your own files.py
        +-- barbudor_ina3221\
                   +-- __init__.py
                   +-- lite.py
                   +-- full.py

And then you can use it exactly as described

I never generated a PiPy package right now but if you know a simple library similar to this one that supports it, let me know and I can look at it and implement it over the week-end.

Best regards

from circuitpython_ina3221.

kkellner avatar kkellner commented on July 21, 2024

Thanks, I'll do it that way and embed it into my project.

An example Pypi that comes to mind in the Alexa python library. Its on gitlab but that shouldn't make a difference. Hopefully it has the example bits you need.

Lib on Pypi: https://pypi.org/project/alexapy/
Code: https://gitlab.com/keatontaylor/alexapy

from circuitpython_ina3221.

barbudor avatar barbudor commented on July 21, 2024

I've done the PyPi package
I've tested that I can install it but not with the hardware
Can you check ?
pip install [--user] barbudor-circuitpython-ina3221

Let me know
Cheers

from circuitpython_ina3221.

kkellner avatar kkellner commented on July 21, 2024

I will not be able to test the library for a few days while I await the delivery of an ina3221 device, but the install appears to have worked:

$ sudo pip3 install  barbudor-circuitpython-ina3221
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting barbudor-circuitpython-ina3221
  Downloading https://www.piwheels.org/simple/barbudor-circuitpython-ina3221/barbudor_circuitpython_ina3221-1.2.0-py3-none-any.whl
Requirement already satisfied: adafruit-circuitpython-busdevice in /usr/local/lib/python3.7/dist-packages (from barbudor-circuitpython-ina3221) (5.0.1)
Requirement already satisfied: Adafruit-Blinka in /usr/local/lib/python3.7/dist-packages (from barbudor-circuitpython-ina3221) (5.9.2)
Requirement already satisfied: rpi-ws281x>=4.0.0 in /usr/local/lib/python3.7/dist-packages (from Adafruit-Blinka->barbudor-circuitpython-ina3221) (4.2.5)
Requirement already satisfied: pyftdi>=0.40.0 in /usr/local/lib/python3.7/dist-packages (from Adafruit-Blinka->barbudor-circuitpython-ina3221) (0.52.0)
Requirement already satisfied: Adafruit-PureIO>=1.1.7 in /usr/local/lib/python3.7/dist-packages (from Adafruit-Blinka->barbudor-circuitpython-ina3221) (1.1.8)
Requirement already satisfied: sysv-ipc in /usr/local/lib/python3.7/dist-packages (from Adafruit-Blinka->barbudor-circuitpython-ina3221) (1.0.1)
Requirement already satisfied: RPi.GPIO in /usr/lib/python3/dist-packages (from Adafruit-Blinka->barbudor-circuitpython-ina3221) (0.7.0)
Requirement already satisfied: Adafruit-PlatformDetect>=2.18.1 in /usr/local/lib/python3.7/dist-packages (from Adafruit-Blinka->barbudor-circuitpython-ina3221) (2.23.0)
Requirement already satisfied: pyusb>=1.0.0 in /usr/local/lib/python3.7/dist-packages (from pyftdi>=0.40.0->Adafruit-Blinka->barbudor-circuitpython-ina3221) (1.1.0)
Requirement already satisfied: pyserial>=3.0 in /usr/local/lib/python3.7/dist-packages (from pyftdi>=0.40.0->Adafruit-Blinka->barbudor-circuitpython-ina3221) (3.5)
Installing collected packages: barbudor-circuitpython-ina3221
Successfully installed barbudor-circuitpython-ina3221-1.2.0

from circuitpython_ina3221.

barbudor avatar barbudor commented on July 21, 2024

Cool
Kindly keep me posted
Cheers

from circuitpython_ina3221.

kkellner avatar kkellner commented on July 21, 2024

I believe the pip install worked however I'm getting the following error
when trying to run the ina3221_simpletest.py code

$ sudo python3 ina3221_simpletest.py
full API sample: improve accuracy
Traceback (most recent call last):
  File "ina3221_simpletest.py", line 32, in <module>
    C_MODE_SHUNT_AND_BUS_CONTINOUS)
  File "/usr/local/lib/python3.7/dist-packages/barbudor_ina3221/full.py",
line 185, in update
    regvalue = self.read(reg)
  File "/usr/local/lib/python3.7/dist-packages/barbudor_ina3221/full.py",
line 178, in read
    i2c.write(buf, end=1, stop=False)
TypeError: write() got an unexpected keyword argument 'stop'

The device is visible from the I2C bus:

$ sudo i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: 40 -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

This is the board I'm using: https://www.amazon.com/gp/product/B07X524KSK

Thoughts?

from circuitpython_ina3221.

kkellner avatar kkellner commented on July 21, 2024

I'm not seeing a stop param to the i2c write method. Do I have the wrong version of the adafruit lab?

i2c write method ref:
https://circuitpython.readthedocs.io/projects/busdevice/en/latest/api.html#adafruit_bus_device.i2c_device.I2CDevice.write

Call from this lib:
https://github.com/barbudor/CircuitPython_INA3221/blob/master/barbudor_ina3221/full.py#L178

from circuitpython_ina3221.

barbudor avatar barbudor commented on July 21, 2024

I wrote this library in time of CircuitPython v3.0 and never re-used it since, and apparently no-one else before youself.
The stop parameter was here until 4.3.2 : https://circuitpython.readthedocs.io/projects/busdevice/en/4.3.2/api.html#adafruit_bus_device.i2c_device.I2CDevice.write

Apparently this call sequence :

            i2c.write(buf, end=1, stop=False)
            i2c.readinto(buf, start=1)

should be replaced with

            i2c.write_then_readinto(buf, buf, out_start=1, in_end=1)

However, it's late now here (I'm @gmt+1) so I'll have a look tomorrow but you may try it yourself by copying the code into your project and editing the occurrence of the call.
Sorry for the inconvenience.

from circuitpython_ina3221.

kkellner avatar kkellner commented on July 21, 2024

I tried the following but it didn't work. The values come back but are incorrect.

            i2c.write_then_readinto(buf, buf, out_start=1, in_end=1)

I then tried this and all is working:

            i2c.write(buf, end=1)

So it seems just removing the stop=False did the trick. I've been running for a few hours and the values seem accurate.

from circuitpython_ina3221.

barbudor avatar barbudor commented on July 21, 2024

So I just mis-understood in and out
The correct syntax is

i2c.write_then_readinto(buf, buf, out_end=1, in_start=1)

I will change for this in the lib and publish a new release on PyPi
I'll let you know

from circuitpython_ina3221.

barbudor avatar barbudor commented on July 21, 2024

Lib v2.0.0 published on PyPi
Thanks for pointing the problems and helping testing.

from circuitpython_ina3221.

kkellner avatar kkellner commented on July 21, 2024

Confirmed v2.0.0 is working on Raspberry Pi4b + Python3. Thank you so much for updating the library. I was just happy to find a CircuitPython compatible library for the INA3221.

from circuitpython_ina3221.

Related Issues (3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.