Skip to content

Instantly share code, notes, and snippets.

@unforgiven512
Created July 18, 2019 21:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unforgiven512/d59afb582310d5d0128e33d25bbc9692 to your computer and use it in GitHub Desktop.
Save unforgiven512/d59afb582310d5d0128e33d25bbc9692 to your computer and use it in GitHub Desktop.
INA219 library (example) for MicroPython
"""Example script.
Edit the I2C interface constant to match the one you have
connected the sensor to.
"""
from ina219 import INA219
from machine import I2C
# Edit to match interface the sensor is connect to (1 or 2).
I2C_INTERFACE_NO = 2
SHUNT_OHMS = 0.1
ina = INA219(SHUNT_OHMS, I2C(I2C_INTERFACE_NO))
ina.configure()
print("Bus Voltage: %.3f V" % ina.voltage())
print("Current: %.3f mA" % ina.current())
print("Power: %.3f mW" % ina.power())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment