Digispark Power Monitor
This instructables show how to build a power monitor with only 3 components: Digispark dev board, INA219 current sensor and SSD1306 OLED breakout board.
Supplies
- Digispark Dev board
- INA219 Current Sensor Breakout board
- SSD1306 128x64 OLED breakout board
- Breadboard and some breadboard wires
What Is Power Monitor?
Power Monitor is useful to visualize the power usage of your circuit. Especially the portable gadgets powered by a battery, the power usage determine the battery life. A power monitor can help you locate the power usage of your circuit or program and then help you decide the battery capacity is required in your project.
Even minor modifications can significantly impact power consumption. For example, as shown in the cover video, adding a resistor can drastically reduce the power consumption of an LED. Without this intermediate resistor, a color-changing LED could consume over 100mA.
You may also want to measure power usage if:
- the dev board enter deep sleep
- the dev board connected to WiFi
- lower the clock speed from 240 MHz to 160 MHz
- use PWM control screen backlight
- power off the screen
- light sleep 5 seconds after every run routine in 0.2 seconds
- removed the on board LED
- replace with a more efficient low-dropout linear regulator
- replace a dev board without serial chip
- and anything you want to try...
A power monitor can help you check all of the above.
Software Preparation
Arduino IDE
Download and install Arduino IDE latest version if not yet:
https://www.arduino.cc/en/software
ATTinyCore
Follow installation step to add ATTinyCore support if not yet:
Wire Connection
Please follow the cover video to connect the wires. And please note the OLED breakout boards have different pin arrangement version. You should double check the VCC/VDD and GND pins connect correctly before turn on the power.
Here are the summary of breadboard connection:
Compile & Upload
Please download the source code at GitHub:
https://github.com/moononournation/ATtinyPowerMeter.git
In Arduino IDE:
- Open ATtinyPowerMeter.ino
- Select Tools menu -> Board -> ATTinyCore -> ATtiny85 (Micronucleus / DigiSpark)
- Press Upload button for compile and upload
- Wait compile finish and show the "Please plug in the device" message
- Plug in the Digispark dev board to upload the program
How to Measure
If you followed the above wire connection, the monitoring power source is come from Digispark 5V (USB). You may replace Vin+ connection by other power source you want to measure but remember also connect the power source GND to this circuit GND. Then connect the load you want to measure to Vin- and GND.
You can see 4 metrics, 2 line charts and 1 area chart on the OLED display. The first line chart represent the voltage, the second line chart represent the current in mA and the area chart represent the power usage in mW. And also the mWh and time metrics help to count the accumulated power usage.
The program read values from the sensor continuously, so you can monitor the live power usage.
Time for Making!
Now you have this "power" tools, you can make your own power efficient portable gadgets now!
Optional: Micronucleus Firmware Fine Tune
You may notice that after turn on the power, it needs wait for few seconds before OLED start to display. It is because micronucleus designed the boot loader check and wait the USB communication for uploading new program a few seconds before running the program. The waiting time can be fine tuned in micronucleus bootloaderconfig.h:
But it requires recompile the firmware and apply to the dev board.
You can find more details for recompile at the GitHub source:
https://github.com/micronucleus/micronucleus
Attached my compiled hex file, you can apply it to your dev board by: