### Basic INA228 Usage Example Source: https://github.com/adafruit/adafruit_circuitpython_ina228/blob/main/README.rst Continuously read and print power consumption metrics from the INA228 sensor every second. Ensure the INA228 library and necessary board support are installed. ```python import time import board import adafruit_ina228 i2c = board.I2C() ina228 = adafruit_ina228.INA228(i2c) while True: print(f"Current: {ina228.current:.2f} mA") print(f"Bus Voltage: {ina228.bus_voltage:.2f} V") print(f"Shunt Voltage: {ina228.shunt_voltage*1000:.2f} mV") print(f"Power: {ina228.power:.2f} mW") print(f"Energy: {ina228.energy:.2f} J") print(f"Temperature: {ina228.die_temperature:.2f} °C") time.sleep(1) ``` -------------------------------- ### Install adafruit-circuitpython-ina228 system-wide Source: https://github.com/adafruit/adafruit_circuitpython_ina228/blob/main/README.rst Install the library system-wide, which may be required in some cases. ```shell sudo pip3 install adafruit-circuitpython-ina228 ``` -------------------------------- ### Install adafruit-circuitpython-ina228 in a virtual environment Source: https://github.com/adafruit/adafruit_circuitpython_ina228/blob/main/README.rst Set up a virtual environment for a project and install the library within it. ```shell mkdir project-name && cd project-name python3 -m venv .venv source .env/bin/activate pip3 install adafruit-circuitpython-ina228 ``` -------------------------------- ### Install circup Source: https://github.com/adafruit/adafruit_circuitpython_ina228/blob/main/docs/index.md Install the circup utility to manage CircuitPython libraries. This is a prerequisite for installing the INA228 library. ```shell pip3 install circup ``` -------------------------------- ### Install adafruit-circuitpython-ina228 using pip Source: https://github.com/adafruit/adafruit_circuitpython_ina228/blob/main/README.rst Install the library for the current user on supported GNU/Linux systems. ```shell pip3 install adafruit-circuitpython-ina228 ``` -------------------------------- ### Install adafruit_ina228 using circup Source: https://github.com/adafruit/adafruit_circuitpython_ina228/blob/main/README.rst Install the library onto a connected CircuitPython device using the circup tool. ```shell circup install adafruit_ina228 ``` -------------------------------- ### mode Source: https://github.com/adafruit/adafruit_circuitpython_ina228/blob/main/docs/api.md Gets or sets the operating mode of the sensor. ```APIDOC ## mode ### Description Operating mode of the sensor. ### Property Type int ``` -------------------------------- ### shunt_resistance Source: https://github.com/adafruit/adafruit_circuitpython_ina228/blob/main/docs/api.md Gets or sets the shunt resistance in ohms. ```APIDOC ## shunt_resistance ### Description The shunt resistance in ohms. ### Property Type float ``` -------------------------------- ### Basic INA228 Sensor Test Source: https://github.com/adafruit/adafruit_circuitpython_ina228/blob/main/docs/examples.md This script initializes the INA228 sensor over I2C and continuously prints various measurements including current, bus voltage, shunt voltage, power, energy, and die temperature. Ensure the adafruit_ina228 library is installed and the I2C bus is correctly configured. ```Python # SPDX-FileCopyrightText: Copyright (c) 2025 Liz Clark for Adafruit Industries # # SPDX-License-Identifier: MIT import time import board import adafruit_ina228 i2c = board.I2C() ina228 = adafruit_ina228.INA228(i2c) print("Adafruit INA228 Test") print(f"Bus conversion time: {ina228.bus_voltage_conv_time} microseconds") print(f"Shunt conversion time: {ina228.shunt_voltage_conv_time} microseconds") print(f"Samples averaged: {ina228.averaging_count}") while True: print("\nCurrent Measurements:") print(f"Current: {ina228.current * 1000:.2f} mA") print(f"Bus Voltage: {ina228.bus_voltage:.2f} V") print(f"Shunt Voltage: {ina228.shunt_voltage * 1000:.2f} mV") print(f"Power: {ina228.power * 1000:.2f} mW") print(f"Energy: {ina228.energy:.2f} J") print(f"Temperature: {ina228.die_temperature:.2f} °C") time.sleep(1) ``` -------------------------------- ### temp_conv_time Source: https://github.com/adafruit/adafruit_circuitpython_ina228/blob/main/docs/api.md Gets or sets the conversion time for temperature measurements. ```APIDOC ## temp_conv_time ### Description Temperature conversion time setting. ### Property Type int ``` -------------------------------- ### alert_latch Source: https://github.com/adafruit/adafruit_circuitpython_ina228/blob/main/docs/api.md Gets or sets the alert latch enable setting. A value of 0 means the alert is transparent, and 1 means the alert is latched. ```APIDOC ## alert_latch ### Description Alert latch enable. 0 = transparent, 1 = latched. ### Property Type int ``` -------------------------------- ### Update adafruit_ina228 using circup Source: https://github.com/adafruit/adafruit_circuitpython_ina228/blob/main/README.rst Update an existing installation of the library on a CircuitPython device. ```shell circup update ``` -------------------------------- ### bus_voltage_conv_time Source: https://github.com/adafruit/adafruit_circuitpython_ina228/blob/main/docs/api.md Gets or sets the conversion time for bus voltage measurements. ```APIDOC ## bus_voltage_conv_time ### Description Bus voltage conversion time setting. ### Property Type int ``` -------------------------------- ### averaging_count Source: https://github.com/adafruit/adafruit_circuitpython_ina228/blob/main/docs/api.md Gets or sets the number of samples to average for readings. ```APIDOC ## averaging_count ### Description Number of samples to average. ### Property Type int ``` -------------------------------- ### shunt_voltage_conv_time Source: https://github.com/adafruit/adafruit_circuitpython_ina228/blob/main/docs/api.md Gets or sets the conversion time for shunt voltage measurements. ```APIDOC ## shunt_voltage_conv_time ### Description Shunt voltage conversion time setting. ### Property Type int ``` -------------------------------- ### adc_range Source: https://github.com/adafruit/adafruit_circuitpython_ina228/blob/main/docs/api.md Gets or sets the ADC range setting for the sensor. The available settings are 0 for ±163.84mV and 1 for ±40.96mV. ```APIDOC ## adc_range ### Description ADC range setting. 0 = ±163.84mV, 1 = ±40.96mV ### Property Type int ``` -------------------------------- ### alert_polarity Source: https://github.com/adafruit/adafruit_circuitpython_ina228/blob/main/docs/api.md Gets or sets the alert pin polarity. A value of 0 indicates active high, and 1 indicates active low. ```APIDOC ## alert_polarity ### Description Alert pin polarity. 0 = active high, 1 = active low. ### Property Type int ``` -------------------------------- ### INA2XX Class Methods and Properties Source: https://github.com/adafruit/adafruit_circuitpython_ina228/blob/main/docs/index.md This section details the various methods and properties available for the INA2XX base class, which provides common functionality for INA2XX series sensors. ```APIDOC ## INA2XX Class ### Description Provides common methods and properties for INA2XX series power monitors. ### Methods and Properties: * **`adc_range`** (property): Get or set the ADC range. * **`alert_latch`** (property): Get or set the alert latch behavior. * **`alert_polarity`** (property): Get or set the alert polarity. * **`averaging_count`** (property): Get or set the averaging count. * **`bus_voltage_conv_time`** (property): Get or set the bus voltage conversion time. * **`device_id`** (property): Get the device ID. * **`mode`** (property): Get or set the operating mode. * **`reset()`** (method): Resets the device to its default configuration. * **`shunt_resistance`** (property): Get or set the shunt resistance value. * **`shunt_voltage_conv_time`** (property): Get or set the shunt voltage conversion time. * **`temp_conv_time`** (property): Get or set the temperature conversion time. ``` -------------------------------- ### INA228 Class Methods and Properties Source: https://github.com/adafruit/adafruit_circuitpython_ina228/blob/main/docs/index.md This section details the various methods and properties available for the INA228 class, allowing users to interact with the sensor for readings and configuration. ```APIDOC ## INA228 Class ### Description Provides access to the INA228 sensor's features, including voltage, current, power, and temperature measurements, as well as configuration options. ### Methods and Properties: * **`alert_flags`** (property): Get the alert status flags. * **`alert_type`** (property): Get or set the alert type. * **`bus_voltage`** (property): Get the bus voltage. * **`bus_voltage_overlimit`** (property): Get the bus voltage over limit status. * **`bus_voltage_underlimit`** (property): Get the bus voltage under limit status. * **`charge`** (property): Get the accumulated charge. * **`clear_overflow_flags()`** (method): Clears the overflow flags. * **`conversion_ready`** (property): Check if a conversion is ready. * **`current`** (property): Get the current measurement. * **`die_temperature`** (property): Get the die temperature. * **`energy`** (property): Get the accumulated energy. * **`power`** (property): Get the power measurement. * **`power_limit`** (property): Get or set the power limit. * **`reset_accumulators()`** (method): Resets the accumulators for charge and energy. * **`set_calibration()`** (method): Sets the calibration values for the sensor. * **`set_calibration_16V_400mA()`** (method): Sets calibration for 16V and 400mA range. * **`set_calibration_32V_1A()`** (method): Sets calibration for 32V and 1A range. * **`set_calibration_32V_2A()`** (method): Sets calibration for 32V and 2A range. * **`shunt_tempco`** (property): Get or set the shunt temperature coefficient. * **`shunt_voltage`** (property): Get the shunt voltage. * **`shunt_voltage_overlimit`** (property): Get the shunt voltage over limit status. * **`shunt_voltage_underlimit`** (property): Get the shunt voltage under limit status. * **`temperature_limit`** (property): Get or set the temperature limit. * **`trigger_measurement()`** (method): Triggers a new measurement cycle. ``` -------------------------------- ### INA2XX Class Initialization Source: https://github.com/adafruit/adafruit_circuitpython_ina228/blob/main/docs/api.md Initializes the INA2XX sensor driver. This class serves as the base for INA2XX series power and current sensors. ```APIDOC ## INA2XX(i2c_bus: busio.I2C, address: int = _INA2XX_DEFAULT_ADDR, skip_reset: bool = False) ### Description Base driver for INA2XX series power and current sensors. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Constructor Parameters * **i2c_bus** (*I2C*) – The I2C bus the INA2XX is connected to. * **address** (*int*) – The I2C device address. Defaults to `0x40` * **skip_reset** (*bool*) – Skip resetting the device on init. Defaults to False. ``` -------------------------------- ### reset Source: https://github.com/adafruit/adafruit_circuitpython_ina228/blob/main/docs/api.md Resets the sensor to its default configuration. ```APIDOC ## reset() ### Description Reset the sensor to default configuration. ### Returns None ``` -------------------------------- ### INA228 Class Source: https://github.com/adafruit/adafruit_circuitpython_ina228/blob/main/docs/api.md The main class for interacting with the INA228 sensor. ```APIDOC ## class adafruit_ina228.INA228(i2c_bus: busio.I2C, address: int = 0x40, skip_reset: bool = False) Driver for the INA228 power and current sensor ### Properties * **alert_flags**: dict All diagnostic and alert flags. Returns a dictionary with the status of each flag: - ‘ENERGYOF’: bool - Energy overflow - ‘CHARGEOF’: bool - Charge overflow - ‘MATHOF’: bool - Math overflow - ‘TMPOL’: bool - Temperature overlimit - ‘SHNTOL’: bool - Shunt voltage overlimit - ‘SHNTUL’: bool - Shunt voltage underlimit - ‘BUSOL’: bool - Bus voltage overlimit - ‘BUSUL’: bool - Bus voltage underlimit - ‘POL’: bool - Power overlimit - ‘CNVRF’: bool - Conversion ready - ‘MEMSTAT’: bool - ADC conversion status * **alert_type**: int Alert type configuration. * **bus_voltage**: float Bus voltage in volts. * **bus_voltage_overlimit**: float Bus voltage overlimit threshold in volts * **bus_voltage_underlimit**: float Bus voltage underlimit threshold in volts * **charge**: float Accumulated charge in coulombs * **conversion_ready**: bool Check if conversion is complete. * **current**: float Current in amperes. * **die_temperature**: float Die temperature in degrees Celsius. * **energy**: float Energy measurement in Joules * **power**: float Power in watts. * **power_limit**: float Power overlimit threshold in watts * **shunt_tempco**: int Shunt temperature coefficient in ppm/°C * **shunt_voltage**: float Shunt voltage in volts. * **shunt_voltage_overlimit**: float Shunt voltage overlimit threshold in volts * **shunt_voltage_underlimit**: float Shunt voltage underlimit threshold in volts * **temperature_limit**: float Temperature overlimit threshold in degrees Celsius ### Methods * **clear_overflow_flags() -> None** Clear energy, charge, and math overflow flags * **reset_accumulators() -> None** Reset the energy and charge accumulators * **set_calibration(shunt_res: float = 0.015, max_current: float = 10.0) -> None** Set the calibration based on shunt resistance and maximum expected current. * Parameters: * **shunt_res** (*float*) – Shunt resistance in ohms * **max_current** (*float*) – Maximum expected current in amperes * **set_calibration_16V_400mA() -> None** Configure for 16V and up to 400mA measurements * **set_calibration_32V_1A() -> None** Configure for 32V and up to 1A measurements * **set_calibration_32V_2A() -> None** Configure for 32V and up to 2A measurements * **trigger_measurement() -> None** Trigger a one-shot measurement when in triggered mode ``` -------------------------------- ### device_id Source: https://github.com/adafruit/adafruit_circuitpython_ina228/blob/main/docs/api.md Reads the device ID of the sensor. ```APIDOC ## device_id ### Description Device ID ### Property Type int ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.