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 1.0.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 1.0.0
File Size Uploaded Provenance Actions
ina228-1.0.0.tar.gz 14.0 kB Without provenance Details for ina228-1.0.0.tar.gz

Built distribution (wheel)

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

Total release size: 24.4 kB

Release files / ina228-1.0.0.tar.gz

Download URL ina228-1.0.0.tar.gz
Size 14.0 kB
Tags Source
SHA-256 checksum
How to use checksums
4a0ca94bb80c7fbdd1eed2edf9c834a003facc175eb425ab394ea18f86bc097d
BLAKE2b-256 checksum
How to use checksums
dc32e4a388baeb70a47efedf41a09d0028d4e926ad220285fb9f91886857f5e9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.3

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

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

Security for ina228 1.0.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