top of page
Klaus Strohmayer

Power Measurement with the INA260 via I2C

Overview

In this article, we are going to explore how to use SmartWave to interface with the INA260 Current and Power monitor from Texas Instruments. The INA260 is a digital-output, current, power and DC voltage monitor with an I2C and SMBus compatible interface. The device monitors both the shunt current and bus supply voltage using an internal current sense resistor. With an internal multiplier, it provides direct readouts of voltage, current and power from its respective registers.


INA260 Functional Block Diagram courtesy of Texas Instruments

In our test setup, we will be using a breakout board from Adafruit that allows us to easily connect the INA260 to SmartWave.



INA260 breakout board courtesy of Adafruit

I2C Protocol

I2C is one of the most widely used communication protocols for interfacing with sensors. It features an SCL line for the clock signal, ensuring synchronisation between the host and peripheral, and an SDA line, which serves as a bidirectional serial data line.  In I2C communication, data is transferred in messages, which are divided into frames. Each message consists of an address frame containing the binary address of the peripheral, along with one or more data frames transmitting the data. Additionally, the message includes START and STOP conditions, READ/WRITE bits, and ACK/NACK bits separating each data frame. A typical timing diagram for the INA260 sensor is depicted below.



I2C Timing Diagram of the INA260 Power Sensor

The timing diagram illustrates the process of reading the content of the Power Register. Initially, the host transmits the device address with the write bit, followed by the register address of the Power Register. This action updates the register pointer to the desired location. To retrieve the register content, the host sends the address byte again in read mode. Subsequently, the peripheral transmits the data from the specified register pointer location.


In a previous article, we addressed common I2C setup issues and provided solutions. Be sure to check it out for more insights. Those who are interested in a detailed explanation of how the I2C protocol works, we recommend reading the following guide from Texas Instruments.


Configure the sensor

The default I2C address of the device is 0x40. However, if multiple sensors are used in an application, the A0 and A1 solder jumpers can be connected to VCC to change the I2C address according to the following table:

A0

A1

I2C Address in HEX

GND

GND

0x40 (Default)

GND

VCC

0x41

VCC

GND

0x44

VCC

VCC

0x45

Table 1. I2C address configuration


In our setup, we'll measure the power consumption of a small brushed DC motor. To do this, we connect a VDD output of the SmartWave to Vin+ on the breakout board and the motor to the Vin- pin. Additionally, we connect the power, SCL, and SDA lines to the device as illustrated in the block diagram below.


Block diagram

We set up the device in normal operational mode, that is, continuously measuring the internal shunt voltage and calculating the current and power. These values are stored and averaged until reaching the configured number of samples. After completion, the average values for current and power are available for reading from the dedicated output registers. The data read from the registers is in binary format. The LSB size for the Bus Voltage Register, Current Register, and Power Register is fixed and shown in Table 2. To calculate any of the values for current, voltage, or power, multiply the decimal value returned by the device by the corresponding LSB size. As the INA260 supports current measurements in either direction, the returned value for negative currents is represented in two's complement format.


Register Name

Address

Content

Decimal

LSB

Value

Current

0x01

00000000 01000000

64

1.25 mA

0.08 A

Bus Voltage

0x02

00001110 10001011

3720

1.25 mV

4.65 V

Power

0x03

00000000 00100101

37

10 mW

0.37 W

Table 2. Calculating register readouts


Interfacing with SmartWave

Interfacing with SmartWave is facilitated through our Python API, which enables the retrieval and conversion of register values into decimal format. To replicate this functionality, you can download our example ina260 script from our GitHub repository. This script serves as a practical guide on interacting with the INA260 sensor, reading its registers, and calculating values in decimal format. It also serves as a foundation for exploring additional features of the device and can be expanded to include data visualization using libraries like Matplotlib or SciPy.


The script begins by establishing a connection with SmartWave and configuring it in I2C mode. Subsequently, it conducts an initial check to ensure a successful connection to the target device. Upon successful verification, the script proceeds to retrieve and calculate the content of the bus voltage, current, and power registers, presenting the results to the user.


Through this API, users can enhance their ability to integrate SmartWave into various projects and workflows. The python package of the API can be installed via pip install SmartWave.


Conclusion

In this article, we delved into the potential of using SmartWave for interfacing with the INA260 power measurement sensor via I2C. We explored its basic configuration and capabilities, providing users with insights into its functionality. Additionally, we offered an example Python script as a foundation for further exploration.


If this article has captured your interest, stay tuned for our next instalment, where we will integrate the INA260 into the stepper motor demo, leveraging our new Python API to interface with the SmartWave.


For those keen on exploring SmartWave's capabilities in their projects, we encourage reaching out to semify via email (office@semify-eda.com) for more information, product demonstrations, or to discuss specific requirements. You can also explore other intriguing articles and demos showcasing SmartWave through the provided links.







Comments


bottom of page