If you want to run a battery operated instrument of any kind, you will eventually be faced with the desire to figure out how much power your instrument requires.
We developed a power monitor as part of our thermostat project. We wanted the thermostat to have battery backup to maintain the time measured during power outages. Understanding the power requirements of the thermostat allows us to size the battery properly and to develop efficient code.
While we built a custom microcontroller board for this project, you could easily breadboard your own using any commercially available microcontroller board. We built our project using the Raspberry Pi RP2040 chip and the INA228 power monitor chip. This can be replicated using a standard Raspberry Pi Pico and an Adafruit module (found here for $15 USD).
The photo on the left shows the power monitor (purple board) powering a Pico W (green board). The display on the monitor shows that the Pico W is consuming 27.65 mA at 5.075 volts while running the Blink program.
In addition to outputs for +5V and GND, the monitor has a number of GPIO pins available. In this application, a gray wire from GP22 on the monitor connects to the "RUN" pin on the Pico W. This allows us to restart the target microcontroller by pulling the RUN pin LOW and then returning HIGH.
The monitor determines the current by measuring the voltage drop across a sense resistor. The INA228 power monitor can monitor voltages up to 85 volts. Current limitations are determined by the choice of a sense resistor. While the Adafruit hardware uses a 0.015 ohm sense resistor, we used a 0.1 Ohm resistor. This limits us to a maximum current of 1.6 Amps. The current monitor is capable of measuring a voltage drop of 0.3 microVolts across the 0.1 Ohm resistor, giving our hardware a maximum precision of 3 microAmps. The ADC sampling time is software select and can range between 50 microseconds and 4 milliseconds. The chip can also do sample averaging up to 1024 samples.
We wrote firmware for the instrument using the Arduino IDE using an available library (INA228.h) for communicating with the power monitor chip. The code is a modified version of the basic usage example in the INA228 library. The microcontroller electronics of the instrument are nearly identical to those of the Raspberry Pi Pico, so we just choose that as the board in the Arduino IDE. The display is a standard SSD1306 LCD that we control using a library from Adafruit.
The firmware was written to output to the user interface every 200 ms, but this period could be easily changed to read more frequently or less frequently, as needed.
The user interface was written using the Processing interactive development environment. It has a chart that shows the current consumed by the target as a function of time. While running, the display also shows the current bus voltage.
Buttons: The user interface (currently) has seven buttons. They are Connect, Save, Reset, Signal A, Signal B, and Run. The functions are listed below.
Connect: The dark button at the top is the Connect / Disconnect button that signals the interface to connect to the monitor hardware. The bottom button is the Run button that tells the instrument to begin (and end) collecting data to the chart.
Save: The save button allows the user to save the current / time data to the host computer. Clicking on this button opens a JAVA window that allows the user to specify the file name and path. Data is saved in CSV format.
Reset: The third button (upper light blue button) is the Reset button. When this button is pressed, the instrument pulls the reset pin LOW for two seconds before resetting it HIGH. When the reset pin on the power monitor is connected to the RUN pin on the target microcontroller, pressing the reset button on the user interface resets the target. The effect of resetting can be seen in the early part of the screenshot above: In this experiment, the reset pin on the monitor was initially held low, keeping the target in an "off" state. At about 13 second point, the reset button was pressed and the he pin was returned HIGH, initializing the target microcontroller. On starting up, current to the target jumped to about 20 mA.
Signals A and B: The fourth button (lower light blue button) is the Signal button. When this button is pressed, the instrument sends a 3.3 volt pulse to a signal pin. In the experiment shown above, the target microcontroller was programmed with an interrupt on the pin connected to the signal pin of the monitor. At about thirty seconds into the experiment, the signal button was clicked and the target microcontroller was signaled to light its onboard led. As shown in the figure, the current jumped initially to about 35 mA and then settled to about 30.
The custom board we made has a footprint for an SD card socket. We included this feature to allow data logging in the absence of a host computer. Specifically, we targeted this to monitoring automotive batteries. To do this requires a step-down converter from 12V to 3.3V, and a setup to pass the automotive battery current through hardware that will tolerate a high current.