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 contribute.
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.
You probably don't need anything else.
Create the instance of INA228 class, specifying the device location on SMBus.
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.
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(): Test if specific alert is active.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 src/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.
-
constashould be removed from methods using it. -
Special methods not intended to be used by user should be made private.
-
All trash should be put out to constants file.
-
Alert register read should be redone in a more correct way.
-
Manufacturer ID should be returned in string, not separate bytes.
Credits
Original code by @megalloid. Python module created and maintained by @makise_homura.
Metadata
Release files for ina228 0.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ina228-0.0.4.tar.gz | 10.8 kB | Without provenance | Details for ina228-0.0.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ina228-0.0.4-py3-none-any.whl | Python 3 | none | any | Details for ina228-0.0.4-py3-none-any.whl |
Total release size: 19.9 kB
Release files / ina228-0.0.4.tar.gz
| Download URL | ina228-0.0.4.tar.gz |
|---|---|
| Size | 10.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
091be05bc173fc5ac541f3cbed57e2ef571ef9f2707706d199a64a92c41f574f
|
|
BLAKE2b-256 checksum How to use checksums |
1e707b5db59bd0c711f266a6b35ec32c568500d51e3f724fd5c51dcce4385cc0
|
| 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.0.4-py3-none-any.whl
| Download URL | ina228-0.0.4-py3-none-any.whl |
|---|---|
| Size | 9.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2fe7b3d800084475d43f9226033d46a2b2d3e896aef423f9fd238f451231c91e
|
|
BLAKE2b-256 checksum How to use checksums |
3c747f8648d32d71921a510d5f20e292a540eb2b2829439a0c6046f2c6a57361
|
| 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.0.4
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.