Tutorial: Measuring Current in Raspberry Pi and Arduino Projects

Pi2Grover
Measuring the current of the LEDs and Grove Digital Extender

Tutorial:  Measuring Current in Raspberry Pi and Arduino Projects

When you are building a solar powered system or a battery powered project, it is important to know how much power is being used by your devices.  If you are building a solar powered system by using SunAirPlus, current and voltage measurement is built into the SunAirPlus board.    But what if you want to measure current for individual modules?   That is where the standalone Grove/Pin Header INA3221 comes into play.

What is the INA3221?

The dual Grove/Pin Header INA3221 Breakout Board is a three-channel, high-side current and bus voltage monitor with an I2C interface and a dual Grove Connector / Pin 0050DGHeader interface.   You can use it both with a Grove I2C Connector and standard pin headers.

How To Measure Current in your Projects

INA3221 Breakout Board Application Block Diagram
INA3221 Breakout Board Application Block Diagram

To use the INA3221, you connect the I2C bus up to an Arduino or Raspberry Pi (using the Grove connector or the Pin headers) and then connect the loads that you want to measure as shown in the block diagram.

What does this mean practically?    To measure the current to a device, you need to break the power line (typically labeled VCC or VDD) and run it through one of the channels of the INA3221.   Since the INA3221 has three channels, you can measure the current of three devices at once.   That is why it is so handy in solar power systems (Battery, Solar Cell and Load).

In this tutorial, we are showing you how to measure current in Grove devices (what is a Grove device?   See our Tutorial on Grove devices).

 

[infobox size=”col-6″ last_column=”false” bottom_margin=”true” closable=”false” color=”blue”]

A Common Ground

One of our CTO’s favorite saying is:  “You can always trust your mother, but you can never trust your ground…“.   To measure voltage, you need a common reference point.

If you notice your voltage on the INA3221 seems wrong or flaky, make sure that you have a common ground connection between the INA3221 board and the Device Under Test, even if you have to run another wire to do that.   Current will read correctly (since you are looking at a differential voltage) but the voltage will not.   Just having a USB bus in common is usually not enough.

[/infobox]

 

Step 1: To measure the current easily, we take a Grove cable, cut the VDD (Red) wire and put two female jumper leads on the ends of the VDD wire as seen below.    Now we have a cable that we can measure the current for any Grove device.

IMG_9621 2
Grove Cable with Current Measurement Modification

Step 2:   Connect the I2C Interface on the INA3221 board to your Raspberry Pi or Arduino board (if you have a Pi2Grover board or an Arduino Grove Shield you can do this with a Grove cable, otherwise use the pin header on the INA3221).

Step 3:  Using the female pin jumpers from the cable in Step 1 put them on INA1+ and INA1- on JP2 of the INA3221 board.    This will allow channel 1 on the INA3221 board to measure the current to the device.

Measuring current
INA3221 Hooked Up

Step 4:  Plug the two ends of our modified Grove cable (from Step 1) into your Grove shield (on the Pi2Grover or an Arduino Grove Shield) and into the Grove device you want to measure the current.   This is a Grove Digital Extender connected to a bunch of LEDs in the picture below.

Pi2Grover
Measuring the current of the LEDs and Grove Digital Extender

Step 5:   Power your device up.   Download the INA3221 Driver software for your computer (links to Pi and Arduino software are found on the INA3221 product page)

 

Step 6:   Now run the software on your computer.   Look here for a video of the demo system running.  On the Raspberry Pi, this gives the results below:

pi@RPi3:~/SDL_Pi_INA3221 $ sudo python testSDL_Pi_INA3221.py

Test SDL_Pi_INA3221 Version 1.0 - SwitchDoc Labs

Will work with the INA3221 SwitchDoc Labs Breakout Board
Program Started at:2016-05-25 15:11:15

------------------------------
(Channel 1)  Bus Voltage 1: 4.83 V 
(Channel 1)  Shunt Voltage 1: 2.80 mV 
(Channel 1)  Load Voltage 1:  4.83 V
(Channel 1)  Current 1:  34.80 mA

(Channel 2)  Bus Voltage 2:  0.00 V 
(Channel 2)  Shunt Voltage 2: 0.00 mV 
(Channel 2)  Load Voltage 2:  0.00 V
(Channel 2)  Current 2:  0.00 mA

(Channel 3)  Bus Voltage 3:  0.00 V 
(Channel 3)  Shunt Voltage 3: 0.00 mV 
(Channel 3)  Load Voltage 3:  0.00 V
(Channel 3)  Current 3:  0.00 mA

------------------------------
(Channel 1)  Bus Voltage 1: 4.84 V 
(Channel 1)  Shunt Voltage 1: 2.92 mV 
(Channel 1)  Load Voltage 1:  4.84 V
(Channel 1)  Current 1:  29.20 mA

(Channel 2)  Bus Voltage 2:  0.00 V 
(Channel 2)  Shunt Voltage 2: 0.00 mV 
(Channel 2)  Load Voltage 2:  0.00 V
(Channel 2)  Current 2:  0.00 mA

(Channel 3)  Bus Voltage 3:  0.00 V 
(Channel 3)  Shunt Voltage 3: 0.00 mV 
(Channel 3)  Load Voltage 3:  0.00 V
(Channel 3)  Current 3:  0.00 mA

------------------------------
(Channel 1)  Bus Voltage 1: 4.84 V 
(Channel 1)  Shunt Voltage 1: 2.84 mV 
(Channel 1)  Load Voltage 1:  4.84 V
(Channel 1)  Current 1:  28.40 mA

(Channel 2)  Bus Voltage 2:  0.00 V 
(Channel 2)  Shunt Voltage 2: 0.00 mV 
(Channel 2)  Load Voltage 2:  0.00 V
(Channel 2)  Current 2:  0.00 mA

(Channel 3)  Bus Voltage 3:  0.00 V 
(Channel 3)  Shunt Voltage 3: 0.00 mV 
(Channel 3)  Load Voltage 3:  0.00 V
(Channel 3)  Current 3:  0.00 mA

 

Note how the current varies from one sample to another.   That is because we are running a python program (in another terminal window) that is randomly flashing LEDs connected to the Grove Digital Extender Board, randomly changing the current.

 

 

1 Trackback / Pingback

  1. Air Quality Sensor Test Results with Raspberry Pi - SwitchDoc Labs

Comments are closed.