Giter Club home page Giter Club logo

adafruit_circuitpython_ina260's Introduction

Introduction

Documentation Status Discord Build Status Code Style: Black

CircuitPython driver for the TI INA260 current and power sensor

Dependencies

This driver depends on:

Please ensure all dependencies are available on the CircuitPython filesystem. This is easily achieved by downloading the Adafruit library and driver bundle.

Installing from PyPI

Note

This library is not available on PyPI yet. Install documentation is included as a standard element. Stay tuned for PyPI availability! If the library is not planned for PyPI, remove the entire 'Installing from PyPI' section. On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally from PyPI. To install for current user:

pip3 install adafruit-circuitpython-ina260

To install system-wide (this may be required in some cases):

sudo pip3 install adafruit-circuitpython-ina260

To install in a virtual environment in your current project:

mkdir project-name && cd project-name
python3 -m venv .venv
source .venv/bin/activate
pip3 install adafruit-circuitpython-ina260

Usage Example

import time
import board
import adafruit_ina260

i2c = board.I2C()
ina260 = adafruit_ina260.INA260(i2c)
while True:
    print("Current: %.2f Voltage: %.2f Power:%.2f"
        %(ina260.current, ina260.voltage, ina260.power))
    time.sleep(1)

Documentation

API documentation for this library can be found on Read the Docs.

For information on building library documentation, please check out this guide.

Contributing

Contributions are welcome! Please read our Code of Conduct before contributing to help this project stay welcoming.

adafruit_circuitpython_ina260's People

Contributors

dhalbert avatar elee-msft avatar evaherrada avatar foamyguy avatar gpongelli avatar jepler avatar kattni avatar ladyada avatar siddacious avatar sommersoft avatar tannewt avatar tcfranks avatar tekktrik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

adafruit_circuitpython_ina260's Issues

using INA260 with Rpi zero

Not sure how to word this. Im trying to read volts/amps using 12v DC brick and a lamp or a dc motor and I am getting odd results and not 12v etc from the basic code example.
running the code...
:~ $ python3 ina60.py Current: 0.00 mA Voltage: 0.00 V Power:0.00 mW Current: 0.00 mA Voltage: 1.04 V Power:0.00 mW Current: 0.00 mA Voltage: 0.17 V Power:0.00 mW Current: -2.50 mA Voltage: 0.00 V Power:0.00 mW Current: 0.00 mA Voltage: 0.00 V Power:0.00 mW Current: 17.50 mA Voltage: 0.14 V Power:10.00 mW Current: 48.75 mA Voltage: 1.02 V Power:40.00 mW Current: 22.50 mA Voltage: 2.22 V Power:10.00 mW Current: 25.00 mA Voltage: 0.02 V Power:10.00 mW Current: 30.00 mA Voltage: 1.13 V Power:30.00 mW Current: 40.00 mA Voltage: 0.84 V Power:10.00 mW Current: 43.75 mA Voltage: 0.29 V Power:10.00 mW Current: 38.75 mA Voltage: 0.35 V Power:30.00 mW Current: 41.25 mA Voltage: 0.43 V Power:40.00 mW Current: 27.50 mA Voltage: 2.44 V Power:10.00 mW Current: 41.25 mA Voltage: 0.02 V Power:10.00 mW Current: 36.25 mA Voltage: 0.69 V Power:10.00 mW Current: 30.00 mA Voltage: 0.17 V Power:10.00 mW Current: -2.50 mA Voltage: 0.00 V Power:0.00 mW Current: -1.25 mA Voltage: 0.37 V Power:0.00 mW Current: -1.25 mA Voltage: 0.01 V Power:0.00 mW Current: 1.25 mA Voltage: 0.00 V Power:0.00 mW Current: -1.25 mA Voltage: 0.73 V Power:0.00 mW Current: 0.00 mA Voltage: 0.00 V Power:0.00 mW ^CTraceback (most recent call last): File "ina60.py", line 15, in <module> time.sleep(1) KeyboardInterrupt
Wiring as as per guidance, attached picture...
SensorWiring
Sorry if this is the wrong place for help but I'm stuck.

Some issues with INA260

  • Arduino board: ** Raspberry Pi 4 **

  • Arduino IDE version (found in Arduino -> About Arduino menu): ** Ubuntu 20.10 **

  • List the steps to reproduce the problem below (if possible attach a sketch or
    copy the sketch code in too): LIST REPRO STEPS BELOW

Hi, I use the ina260_simplest.py to obtain the current. From the terminal, under Current, the values printed on the screen always have one of the following endings: .00, .25, .50, .75. Why it does not have other higher resolution values?

Also, could you please tell me how to set the conversion time to 140us? I asked a few times. Support told me to use:

ina260.ConversionTime = ConversionTime.TIME_140_us

I copied and pasted the above line but python3 gave me

NameError: name 'ConversionTime' is not defined.

Also, under what situations do we set such fast conversion time rather than just use the default value of 1.1ms? Any disadvantages in using the fastest conversion time of 140us?

Thank you

Missing Type Annotations

There are missing type annotations for some functions in this library.

The typing module does not exist on CircuitPython devices so the import needs to be wrapped in try/except to catch the error for missing import. There is an example of how that is done here:

try:
    from typing import List, Tuple
except ImportError:
    pass

Once imported the typing annotations for the argument type(s), and return type(s) can be added to the function signature. Here is an example of a function that has had this done already:

def wrap_text_to_pixels(
    string: str, max_width: int, font=None, indent0: str = "", indent1: str = ""
) -> List[str]:

If you are new to Git or Github we have a guide about contributing to our projects here: https://learn.adafruit.com/contribute-to-circuitpython-with-git-and-github

There is also a guide that covers our CI utilities and how to run them locally to ensure they will pass in Github Actions here: https://learn.adafruit.com/creating-and-sharing-a-circuitpython-library/check-your-code In particular the pages: Sharing docs on ReadTheDocs and Check your code with pre-commit contain the tools to install and commands to run locally to run the checks.

If you are attempting to resolve this issue and need help, you can post a comment on this issue and tag both @FoamyGuy and @kattni or reach out to us on Discord: https://adafru.it/discord in the #circuitpython-dev channel.

The following locations are reported by mypy to be missing type annotations:

  • adafruit_ina260.py:104
  • adafruit_ina260.py:154
  • adafruit_ina260.py:171

Installing the Library on my pi5 bookworm breaks my python GPIO calls

For my project we have a relay hat on the pi that is controlled by python code.

I use it with a pi4 and a pi5. If i install the INA260 library on the pi4 everything is fine.

if I install the INA260 library on a pi5 like this:

sudo pip3 install adafruit-circuitpython-ina260 --break-system-packages

(using the break packages flag was the only way i could figure out how to get it installed)

immediately the GPIO stops works and i get this error

Traceback (most recent call last):
  File "/home/pi/Desktop/Mothbox/TakePhoto.py", line 54, in <module>
    GPIO.setup(Relay_Ch1,GPIO.OUT)
RuntimeError: Cannot determine SOC peripheral base address

now the pi5 does have weird stuff with its GPIO pins, and this error comes up for instance if using the regular GPIO libraries. and so in the past i got around it by installing the lgpio library.

but now it doesn't matter if i have the lgpio library or not, whenever the ina260 library is installed it permanently breaks the setup.

also i cannot do pip3 uninstall either. it keeps it being broke. I have to flash a new image.

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.