Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
README for INA219 library for MicroPython on ESP8266

Using the Library on an ESP8266

On the NodeMCU clone I used to test with I got an out of memory error when trying to import the ina219 module, this is due to there being insufficient RAM to compile this module to byte code. If you encounter this issue then you can use the frozen byte code as explained below.


This is an example script:

from machine import Pin, I2C
from ina219 import INA219
from logging import INFO


i2c = I2C(-1, Pin(5), Pin(4))
ina = INA219(SHUNT_OHMS, i2c, log_level=INFO)

print("Bus Voltage: %.3f V" % ina.voltage())
print("Current: %.3f mA" % ina.current())
print("Power: %.3f mW" % ina.power())

Frozen Byte Code

This directory contains two frozen byte code modules; ina219.mpy and logging.mpy compiled with v1.9.1 of the micropython esp8266 tool chain. Copy these to the flash drive of your esp8266 in place of the source code modules, logging.mpy is only required if you want to see log output. Restart the esp8266.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.