Skip to main content

INA228

Driver for TI INA228 voltage/current sensor located on SMBus.

Installation

Module is available on PyPi. So just pip install ina228 should be enough, if you're not up to contributing.

Typical usage

    from ina228 import INA228
    ina228 = INA228(bus, addr)
    ina228.configure()
    time.sleep(1)
    print('Voltage: ', ina228.get_vbus_voltage())
    print('Current: ', ina228.get_current())
    print('Power: ', ina228.get_power())

To use the module, just import INA228 class from there, and Alert if needed. You probably don't need anything else.

Create the instance of INA228 class, specifying the device location on SMBus. By default, it uses INA228 at bus 1 slave address 0x45, with 0.025 Ohm shunt and disabled temperature correction; you may set your own values while creating the instance.

Then, initialize it by calling configure() method, and now it is ready to work.

After configuring, don't forget to leave device some time for the first measurement. 1 second should be enough.

Then you may use every method you want to get measurement results and do other tasks.

Useful methods

  • reset_all(): Perform the power-on reset of the chip.
  • reset_energy(): Reset energy and charge counters.
  • get_shunt_voltage(): Read voltage on the shunt resistor.
  • get_vbus_voltage(): Read voltage on the V+/V- terminals.
  • get_temp(): Read die temperature.
  • get_current(): Read current through I+/I- terminals.
  • get_power(): Read calculated power (a product of voltage and current).
  • get_energy(): Read integral energy (a product of power and time since last reset).
  • get_charge(): Read charge spent (a product of current and time since last reset).
  • get_diag_alerts(): Read alerts.
  • alert_message(): Get text message for specific alert.
  • set_alert_bits(): Set alert configuration.
  • set_shunt_overvoltage(): Set high alert threshold of the shunt resistor voltage.
  • set_shunt_undervoltage(): Set low alert threshold of the shunt resistor voltage.
  • set_bus_overvoltage(): Set high alert threshold of the V+/V- terminals voltage.
  • set_bus_undervoltage(): Set low alert threshold of the V+/V- terminals voltage.
  • set_temp_limit(): Set high alert threshold of the die temperature.
  • set_power_overlimit(): Set high alert threshold of the load power.
  • get_manufacturer_id(): Read manufacturer ID.
  • get_deviceid(): Read device ID.

Detailed documentation can be found in the docstrings in api.py.

Building from source

Just run:

python3 -m build

It will create dist subdirectory and put sdist and bdist (wheel) there.

Requirements

For now, it relies on smbus2 module (see requirements.txt).

Testing

See corresponding README.

Known bugs and TODO list

  • Value of VSHUNT is needed to be multiplied by 10 to get correct value.

Credits

Original code by @megalloid. Python module created and maintained by @makise_homura.

Metadata

Release files for 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 ina228 0.1.0
File Size Uploaded Provenance Actions
ina228-0.1.0.tar.gz 10.9 kB Without provenance Details for ina228-0.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 20.5 kB

Release files / ina228-0.1.0.tar.gz

Download URL ina228-0.1.0.tar.gz
Size 10.9 kB
Tags Source
SHA-256 checksum
How to use checksums
94f17d89d8ebee374a3bfbffadef65cfa00c04b69f76f439f19dcfed7b7885b7
BLAKE2b-256 checksum
How to use checksums
87806d15d86e9d901d1a3b95c6bb7190fb76d29acb941c6c646dbecd6e37589c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.3

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

Download URL ina228-0.1.0-py3-none-any.whl
Size 9.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a370a903c9ac63c1b81dcf9d3da28cafb053033c89671b47c00f4411103b8c0a
BLAKE2b-256 checksum
How to use checksums
c511fb0d59ba9a3aaece84dd55c4e97fa567c2b8bf587987fe6622440c0b07d7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.3

Security for ina228 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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