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

Built distribution (wheel)

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

Total release size: 24.5 kB

Release files / ina228-1.0.1.tar.gz

Download URL ina228-1.0.1.tar.gz
Size 14.0 kB
Tags Source
SHA-256 checksum
How to use checksums
3f2073750d6c01a2ea47acbbbcf0f9d9546933487d847bffd47b2a0c78aeb04c
BLAKE2b-256 checksum
How to use checksums
d8fe66eefeea469f8ae225a8713963fc8a81b22d3fd4510b1336b1e04b6aca18
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.1-py3-none-any.whl

Download URL ina228-1.0.1-py3-none-any.whl
Size 10.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dcf61c5d101a2763002b83b01d3dd731053cc80d1128ca907a8676b9694167e5
BLAKE2b-256 checksum
How to use checksums
31b502a3cc6864adc199748738928eca976d994e577817840fb58ebdab9e5600
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.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