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.
Contributing¶
Contributions are welcome! Please read our Code of Conduct before contributing to help this project stay welcoming.
Building locally¶
To build this library locally you’ll need to install the circuitpython-build-tools package.
python3 -m venv .env
source .env/bin/activate
pip install circuitpython-build-tools
Once installed, make sure you are in the virtual environment:
source .env/bin/activate
Then run the build:
circuitpython-build-bundles --filename_prefix adafruit-circuitpython-ina219 --library_location .
Sphinx documentation¶
Sphinx is used to build the documentation based on rST files and comments in the code. First, install dependencies (feel free to reuse the virtual environment from above):
python3 -m venv .env
source .env/bin/activate
pip install Sphinx sphinx-rtd-theme
Now, once you have the virtual environment activated:
cd docs
sphinx-build -E -W -b html . _build/html
This will output the documentation to docs/_build/html
. Open the index.html in your browser to
view them. It will also (due to -W) error out on any warning like Travis will. This is a good way to
locally verify it will pass.
Table of Contents¶
Simple test¶
Ensure your device works with this simple test.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | import time
from board import SCL, SDA
import busio
import adafruit_ina219
i2c_bus = busio.I2C(SCL, SDA)
ina219 = adafruit_ina219.INA219(i2c_bus)
print("ina219 test")
while True:
print("Bus Voltage: {} V".format(ina219.bus_voltage))
print("Shunt Voltage: {} mV".format(ina219.shunt_voltage / 1000))
print("Load Voltage: {} V".format(ina219.bus_voltage + ina219.shunt_voltage))
print("Current: {} mA".format(ina219.current))
print("")
time.sleep(2)
|
adafruit_ina219
¶
CircuitPython driver for the INA219 current sensor.
- Author(s): Dean Miller
Implementation Notes¶
Hardware:
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
-
class
adafruit_ina219.
INA219
(i2c_bus, addr=64)[source]¶ Driver for the INA219 current sensor
-
bus_voltage
¶ The bus voltage (between V- and GND) in Volts
-
current
¶ The current through the shunt resistor in milliamps.
-
set_calibration_16V_400mA
()[source]¶ Configures to INA219 to be able to measure up to 16V and 400mA of current. Counter overflow occurs at 1.6A.
Note
These calculations assume a 0.1 ohm shunt resistor is present
-
set_calibration_32V_1A
()[source]¶ Configures to INA219 to be able to measure up to 32V and 1A of current. Counter overflow occurs at 1.3A.
Note
These calculations assume a 0.1 ohm shunt resistor is present
-
set_calibration_32V_2A
()[source]¶ Configures to INA219 to be able to measure up to 32V and 2A of current. Counter overflow occurs at 3.2A.
..note :: These calculations assume a 0.1 shunt ohm resistor is present
-
shunt_voltage
¶ The shunt voltage (between V+ and V-) in Volts (so +-.327V)
-