Metadata-Version: 2.2
Name: ina228
Version: 0.1.0
Summary: Driver for TI INA228 with SMBUS
Author-email: Andrey Zaostrovnykh <megalloid@gmail.com>, Igor Molchanov <akemi_homura@kurisa.ch>
Maintainer-email: Igor Molchanov <akemi_homura@kurisa.ch>
Project-URL: Repository, https://github.com/makise-homura/INA228/
Project-URL: Issues, https://github.com/makise-homura/INA228/issues/
Keywords: electronics,sensing,TI,home automation,smbus,ina2xx
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Topic :: Home Automation
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3.15
Classifier: Operating System :: OS Independent
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: smbus2

# INA228

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

## Installation

Module is [available](https://pypi.org/project/ina228/) on PyPi.
So just `pip install ina228` should be enough, if you're not up to contributing.

## Typical usage

```python
    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](src/ina228/api.py).

## Building from source

Just run:

```console
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](requirements.txt)).

## Testing

See [corresponding README](tests/README.md).

## Known bugs and TODO list

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

## Credits

Original code by [@megalloid](https://t.me/megalloid).
Python module created and maintained by [@makise_homura](https://t.me/makise_homura).
