Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/robert-hh/INA219
INA219 Micropython driver
https://github.com/robert-hh/INA219
Last synced: 25 days ago
JSON representation
INA219 Micropython driver
- Host: GitHub
- URL: https://github.com/robert-hh/INA219
- Owner: robert-hh
- Created: 2020-05-21T09:21:34.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-06-15T18:27:37.000Z (over 4 years ago)
- Last Synced: 2024-04-22T12:36:01.158Z (8 months ago)
- Language: Python
- Size: 6.84 KB
- Stars: 8
- Watchers: 4
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-micropython - INA219 - INA219 MicroPython driver. (Libraries / Sensors)
README
# INA219 Micropython driver
This driver is a clone of an early version of the Adafruit CircuitPython driver, when these were still readable and simple.
The only thing changed was the way of reading and writing to the I2C device.## Class
ina = INA219(i2c, \*, address=0x40)
Create an instance of the ina219 object.
*i2c* The I2C object used for communication
*address* The I2C address. The default value is 0x40The INA219 device will be initialized with the range of 1A/32V.
## Methods and properties
### current = ina.current
Return the current though the shunt at the configured range.
### bus_voltage = ina.bus_voltage
Return the voltage between the shunt's V- connection and GND.
### shunt_voltage = ina.shunt_voltage
Return the voltage between the shunt's V+ and V- connections.
### set_calibration_32V_2A()
Set the measurement range to 32V and 2A.
### set_calibration_32V_1A()
Set the measurement range to 32V and 1A.
### set_calibration_16V_400mA()
Set the measurement range to 16V and 400mA.
## Example
```
from machine import I2C
from ina219 import INA219
import time# Depending on the port, the Pins for SDA and SCL must be specified
# See the MicroPython documentation for your port.
# I2C requires pull-up resistors at SDA and SCL.i2c = I2C(1)
ina = INA219(i2c)set_calibration_32V_1A()
while True:
current = ina.current
voltage = ina.bus_voltage
print("{} mA {} V".format(current, voltage))
time.sleep(1)
```