Metadata-Version: 2.2
Name: ina228
Version: 1.0.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>
License: MIT License
        
        Copyright (c) 2021 Andrey Zaostrovnykh
        Copyright (c) 2026 Igor Molchanov
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
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

* `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](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).

## Credits

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