Tutorial: DataLogger #2 – Measure/Graph/Log Current with the Raspberry Pi

USB Cable Cut for Current Measurement

Tutorial: DataLogger #2 –  Measure/Graph/Log Current with the Raspberry Pi

The Hardware

IMG_7818

Since current is so important in many of our designs at SwitchDoc Labs, we decided to build a Raspberry Pi based DataLogger to read how much current was going into the Arduino based transmitter and use this information to modify the system to reduce the current.  This tutorial shows how to build the DataLogger.

Part 1: DataLogger Introduction

Part 2:  DataLogger Hardware

Part 3: DataLogger Software

The DataLogger consists of a Raspberry Pi 3 running the DataLogging Python Software,  MySQL, MatPlotLib and an Apache Webserver.   Installing all this software will be described in Part 3 of this tutorial.  Since we are currently measuring current, we are using a Grove INA3221  3 Channel current/voltage measurement device.

What is Grove?

Grove is a system for prototyping systems quickly by the use of standardized plugs. Check our full Grove tutorial here.

The Hardware

The five pieces of hardware used in this project tutorial are:

Raspberry Pi 3
Raspberry Pi 3

Raspberry Pi 3

The Raspberry reads the INA3221 via the I2C bus. We are using a Raspberry Pi 3 for convenience.   The CPU loading for the DataLogging function is low enough to use any Raspberry Pi model with no problem.   We are also providing the 5V power for the entire system from the Raspberry Pi.    The Raspberry Pi 3 uses about 720mA peak current, so make sure you add what you are consuming in your DUT (Device Under Test) to the 720mA when you are sizing your power supply.

Pi2Grover - Raspberry Pi to Grover Prototyping System Interface
Pi2Grover – Raspberry Pi to Grover Prototyping System Interface

Pi2Grover Raspberry Pi to Grove Prototyping System Interface

The Pi2Grover board provides 15 Grove connectors  for your prototyping needs.  10 Grove Digital, 4 Grove I2C, and one Grove UART.    Fast prototyping with many, many Grove devices available.  No software drivers required.  You are right next to the hardware.

It plugs right into your Raspberry Pi GPIO pins with a special connector that allows you to plug boards or hats on top of the Grove board.

 

 

 

DataLogger
Pi2Grover Installed on Raspberry Pi

To the left you can see the Pi2Grover board plugged into a Raspberry Pi.

DataLogger
Grove INA3221 3 Channel Current/Voltage

Grove INA3221 3 Channel Current/Voltage Measuring  Device

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 Header interface.   You can use it both with a Grove I2C Connector and standard pin headers.

Note that the SunAirPlus board also contains an INA3221.  Since we are planning to make the wireless link system Solar Powered, we used the INA3221 in SunAirPlus for one project, and an INA3221 for the other project.

 

 

 

DataLogger INA3221
INA3221 Breakout Board Application Block Diagram

 

The block diagram to the left shows the basic structure.   The Raspberry reads the INA3221 via the I2C bus.   The power line for the DUT (Device Under Test) is split and the end wire directly from the power supply is fed into the INA1+ line and then a wire goes from the INA1- line into the power supply of the DUT.

Grove Cable Modified for Current Measurement
Grove Cable Modified for Current Measurement

Modified Grove Cable

For doing current measurements of Grove devices, we built a special Grove cable, cutting the power line and adding two female jumpers so we can plug them into the INA3221.

 

DataLogger Cable
USB Cable Cut for Current Measurement

Modified USB Cable

When we are doing whole system measurements (that are powered by an USB Cable), we cut the +5V Power line on a short USB Cable extender and added female jumpers that can plug into the INA3221.

 

 

 

 

 

We have used this DataLogger in two projects so far.   The first was a system test of our new product, the Grove Digital Extender board, an I2C board that gives 8 more Grove Digital ports.

How it Hooks Up

[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]

In the picture below, we show an Arduino based system being powered by a USB cable hooked up to the Raspberry Pi DataLogger

DataLogger

In the picture below we show a similar system being measured by the INA3221 contained in SunAirPlus.

WeatherLink Prototype with DataLogger
WeatherLink Prototype with DataLogger

 

Coming Up Next?

In our final part of this tutorial, we will be showing how to install the software on the Raspberry Pi and how it all works together.