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

  • configure(): Performs INA228 reset and initial configuration.
  • 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.

Credits

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

Metadata

Release files for ina228 0.1.1

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.1
File Size Uploaded Provenance Actions
ina228-0.1.1.tar.gz 12.7 kB Without provenance Details for ina228-0.1.1.tar.gz

Built distribution (wheel)

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

Total release size: 22.8 kB

Release files / ina228-0.1.1.tar.gz

Download URL ina228-0.1.1.tar.gz
Size 12.7 kB
Tags Source
SHA-256 checksum
How to use checksums
3c1e33642668b4e885724beeb4b8b3d229014297bf32f90e3b92d91a1b295de5
BLAKE2b-256 checksum
How to use checksums
6600519077b9307297d126ac9d35b7240d5ddeeed27ae0958bd1992c3cd3d91d
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.1-py3-none-any.whl

Download URL ina228-0.1.1-py3-none-any.whl
Size 10.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8973d46327fcb331b7aa8e160705306bf29681d184fd159c50e4a8aea92944e5
BLAKE2b-256 checksum
How to use checksums
8165715991451a5cbf66aecaa58f877bc0bbab9e5e8c442a50f4ecd36dd78262
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.1

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