Skip to main content

TI INA228 library for MicroPython

The INA228 is an 85V precise power monitor from Texas Instruments More information can be found at https://www.ti.com/product/INA228

Basic Usage

from machine import Pin, I2C
import ina228

ina = ina228.INA228(
    I2C(0,sda=Pin(21), scl=Pin(22), freq=400000),
    shunt_resistance=0.015,
    max_current=10,
)

print(f'Bus Voltage: {ina.voltage:.3f} V')
print(f'Current: {ina.current:.3f} A')
print(f'Shunt Voltage: {ina.shunt_voltage/ 1000:.3f} mV')
print(f'Temperature: {ina.temperature:.3f} °C')
print(f'Power: {ina.power:.3f} W')
print(f'Energy: {ina.energy:.3f} J')
print(f'Charge: {ina.charge:.3f} C')
print(f'Manufacturer: {ina.manufacturer_id}')
print(f'Device: {ina.device_id}')

There's a lot more you can do and I tried to make it as user-friendly and complete as possible. Just read the datasheet and anything you want to do, you should be able to do it with this library. Most of the calculations are automatic so you can don't have to worry about converting values to fit in the fields.

For example, you may want to configure the adc. Familiarize yourself with this in the datasheet and then run something similar to the following.

ina.configure_adc(
    mode=ina228.ADCMode.CONT_VBUS_VSHUNT,
    vbusct=ina228.CONVERSION_TIME[540],
    vshct=ina228.CONVERSION_TIME[540],
    vtct=ina228.CONVERSION_TIME[50],
    avg=ina228.AVERAGING_COUNT[4]
)

Or if you want to set a temperature threshold of 50 °C

    ina.temp_limit = 50.0
    print(f'Temperature limit configured for {ina.temp_limit}')

And then to restore the device to the default configuration

ina.reset()

Metadata

Release files for micropython-ina228 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for micropython-ina228 0.1.0
File Size Uploaded
micropython_ina228-0.1.0.tar.gz 14.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for micropython-ina228 0.1.0
File Interpreter ABI Platform
micropython_ina228-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 27.4 kB

Release files / micropython_ina228-0.1.0.tar.gz

Download URL micropython_ina228-0.1.0.tar.gz
Size 14.1 kB
Tags Source
SHA-256 checksum
How to use checksums
0ece28b33fc7fd1416531f7fe967571c414a76a2cc4d6753e2827a14efb3230a
BLAKE2b-256 checksum
How to use checksums
bf2e9587c146429ab982a4e924f9b0dd4eccef7a10d4b541f13931bce928f74e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.5

Release files / micropython_ina228-0.1.0-py3-none-any.whl

Download URL micropython_ina228-0.1.0-py3-none-any.whl
Size 13.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
662e988aa3a188fa11abc498cc901af74ef2d9f16c5c1fdc043d19a7261ad714
BLAKE2b-256 checksum
How to use checksums
0c670bdbe4f0bdf984e40319fcd14577cecd609a3617932814ca713d065e0b05
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.5

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page