In this short article we take a look at using the Flowcode component for the INA226 Current Sense and Bus Voltage Monitor with an ESP32 as the Master micro-controller, which is fully supported in Flowcode.
We will use the combination to construct basically 3 meters.
DC Volt Meter
DC Current Meter(Ammeter)
The ESP32 Wifi capabilities can be utilized by users to build a Web server or publish the data to the cloud services.
We are using the ESP32 Dev-Kit 1 Board with a INA226 Breakout Board for this project as below below.
INA226 Breakout Board
Working voltage: DC 2.7V ~ 5.5V
Measured voltage: DC 0V ~ 36V
Measured current: -20A ~ 20A
Accuracy: +/- 1%
Resolution: 16 bit
I2C Address: pad set
Working temperature: -40 ℃ ~ 125 ℃
This breakout board may well be the last current sensing solution you every need to buy. it can do the work of two multi-meters, it does it with good precision and flexibility. you can measure high or low side DC current, the bus voltage, and have it automatically calculate the power. while delivering the data over I2C to the micro-controller.
Connecting the INA226 board to a ESP32 Wifi capable micro-controller opens up a world of opportunities for the user.
In our project we will configure the INA226 board and Read the DC Current,DC bus Voltage and Power and display the data on an GLCD to represent a desktop meter,We will also send the Data over Serial-USB to a Plotter Program to plot the data as logging function or extension of power Current/Power Meter.
How does it work?
The voltage across the integrated 2 mohm , 0.1% shunt resistor is measured by the internal 16 bit ADC, with good accuracy, this voltage is stored in the internal shunt Voltage Register.
The device also measures the DC bus Voltage and stores the value in the Bus Voltage register,The device contains a Configurations register which the user can select the various modes and Sampling rates of the device.
The Calibration register provides the device with the value of the shunt resistor that was present to create the measured differential voltage. It also sets the resolution of the Current Register. This register is also suitable for use in overall system calibration. See the
Programming the Calibration Register (Datasheet)for additional information on programming the Calibration Register.The use of the Calibration register and reading the current register and power registers is very application specific and therefore not covered in the Standard Flowcode component, for advanced users a specific component can be created that allows the use of these advanced features including the setting of the limits for the Alert pin triggering.
The Power and Current Registers contain the value of the shunt current and the power depending on the modes and sampling settings and the value of the Calibration register.
it is advised the the user read these sections of the device datasheet ,the device have many different settings and calibrations which is beyond the scope of this article. We implement the default settings(the Power on reset state of the device)
Mode: Shunt and Bus Measurement Continuous -> bit value 111
Shunt Voltage Conversion Time : 1.1mSec -> bit Value 111
Bus Voltage Conversion Time : 1.1mSec -> bit value 100
Averaging Mode : 1 sample -> bit value 000
Reset : Off -> bit value 0
Configuration Register Value = 01000001 00100111
In the standard Flowcode component the user can set the mode , sampling times and number of samples for averaging specially handy in a load cause noise on the DC line.
The user can also reset the INA226 to default setting by using the Reset Macro.
When using averaging sampling please note the time needed from the datasheet to complete the sampling and allow this time before reading the Registers of the INA226.
The sensor on the breakout requires between a 2.7V and 5.5V, and can be easily used with most micro-controllers..
Vcc - this is the power pin. To power the board, 2,7 to 5V
GND - common ground for power and logic
I2C Logic Pins
SCL - I2C clock pin, connect to your micro-controllers I2C clock line. The logic level is the same as Vcc and it has a 10K pull-up already on it.
SDA - I2C data pin, connect to your micro-controllers I2C data line. The logic level is the same as Vcc. and it has a 10K pull-up already on it.
Vin+ is the positive input pin. Connect to supply for high side current sensing or to load ground for low side sensing.
Vin- is the negative input pin. Connect to load for high side current sensing or to board ground for low side sensing
Alert is the interrupt output pin. You can configure the interrupt to trigger for various 'reasons' such as going over or under a configured current, voltage, or power setting. Also used to signal a one shot conversion being ready. Voltage level is the same as Vcc.
VBus is the bus voltage. By default it is tied to Vin+ however for low side measurements you should connect VBus to the power bus so it can accurately calculate the bus voltage and total power (VBus * Current) draw.
A0 and A1 solder jumpers - These can be bridged with solder to pull the address pin up to VCC(High) to change the I2C address. As shown in the below Table.
Our Project Connections.
The above project uses the Flowcode Component and serves and an example of using the component .The user needs to implement the code for the Visual Interface he is using.
Download the Base Source code for the experiment and add your display.
For Arduino users below an ARDUINO Source File
Flowcode Component Macros available to the User
The Component supports SCADA Simulation by setting the Component Property "Simulate Comms" to Yes and using the ESP32 API and I2C Injector API you can collect the real time data from an INA226 device and use it in your Flowcode simulation.
NOTE: FlowcodeXchange can implement all the advanced features for a specific hardware configuration. Send a a contact or service request and we will get in touch with you asap