ATtinyPowerMeter

6,588

120

41

Introduction: ATtinyPowerMeter

About: Make it yourself if you cannot buy one!

This instructables show how to make a simple power meter using 3 components: ATtiny85, INA219 and OLED module.

It can continuous measure the voltage(V), current(mA) and accumulated power usage(mWh). And also plot a simple graph to visualise the figures.

Step 1: Why?

While developing IoT device, power consumption does matter, especially if it cannot wired. A simple multi-meter is not enough for continuous monitoring the voltage and current at the same time. And also the accumulated power consumption (mWh) is very important for deciding how big a battery required in the IoT project.

So I use the components in hand to create this ATtinyPowerMeter.

Step 2: Preparation

The power meter should not drain too much power itself, it is the major criteria to choose the components:

MCU

ATtiny85 only draw less than 1 mA while running at 1 MHz and 8 KB program flash can well fit a power meter program.

Power Monitor Module

INA219 module is the only module I can found that can monitor voltage and current at the same time (leave comment to me if you known other modules). It draws around 1 mA power.

Display Module

SSD1306 OLED display module drain few mA for display, it is the major power consumption. It should be better if using mono LCD display, but I only have this I2C display module in hand, so I will use it this time.

Battery

According to the data sheet, the above 3 components can operate at 3 V to 5.5 V, 2 rechargeable AAA battery is not enough, 3 AAA battery is better, 1 Lipo battery also ok. But in this project I am testing a new type battery, Lithium iron phosphate (LiFePO4 or LFP) battery. It is the same as AAA battery in size, but can provide 3.2 V 600 mAh. It should be good enough for most electronic project but I am still testing it.

Others

A 380 hole breadboard, some breadboard wire, a breadboard friendly battery holder, a 3 pins screw terminal block and a switch. And also a ISP for programming the ATtiny85.

Step 3: Download Source Code

Download source from GitHub:

https://github.com/moononournation/ATtinyPowerMete...

If you are not familiar GitHub, simple press "Clone or download" button and then "Download ZIP".

Step 4: Program ATtiny85

Step 5: Circuit Design

Here is the connection summary:

Battery +ve -> switch -> ATtiny85 pin 8, INA219 module Vcc, OLED module Vcc
Battery -ve -> ATtiny85 pin 4, INA219 module GND, OLED module GND, screw terminal block middle pin
ATtiny85 pin 5 -> INA219 module SDA, OLED module SDA
ATtiny85 pin 7 -> INA219 module SCL, OLED module SCL
INA219 module Vin- -> screw terminal block left pin
INA219 module Vin+ -> screw terminal block right pin

Step 6: Testing

  1. Turn on the switch, you should see V and mA figure is 0.
  2. Connect testing power source +ve and -ve to screw terminal right pin and middle pin respectively, you should see V figure become the power source Voltage value and mA still 0
  3. Connect testing loading device +ve and -ve to screw terminal left pin and middle pin respectively, you should see mA figure become the loading device drawing current value

Step 7: Self Test

You want to know how much power draining this power meter itself? In my measurement it draws around 3 - 6 mA, just for your reference.

Step 8: Happing Measuring!

It is the time to design and testing your device power consumption now!

P.S. My source code configured measure maximum 16V and 800 mA, you may change the configuration at "INA219.h".

2 People Made This Project!

Recommendations

  • Fix It! Contest

    Fix It! Contest
  • Metalworking Contest

    Metalworking Contest
  • Water Contest

    Water Contest

41 Discussions

I like very much the nice project.

One point - I need to setup the system with 2 INA219 - how can I ad INA219 I2C addresses to the sketch / h files?

9 more answers

The library I am using is tailor-made for ATtiny85, the compiled size is just fit for 8K flash. I am afraid ATtiny may not capable adding code for controlling 2 INA219. If you are using normal Arduino (ATMEGA), you can try Adafruit INA219 library.

Thank you very much for replying.

I am looking for the very nice solution of ATtiny85 and 2 x INA219 for a monitor for a powersupply 0 -> +/- 12 V dc.

monitor for the current in each line (positive and negative) and voltage monitor.

Monitoring on OLED 1306 display.

Your tailor made project supports all but one more INA219.

Therefore I hoped for a changed / updated tailor made INA219 lib for addressing 2 INA219.

Do you have any plans to make this possible in the future?

Yes of course.

The application:

A DC powersupply delivering 0 to 12V positive and negative with a common ground. This is for my daily work developing small modules for my own test equipment.

I woild like to be able to monitor the current in the positive part of the powersupply and the negative part of the power supply.

I also like to monitor the output voltage.

All of this can be done with two INA219. Actually I have the system running now on Arduino UNO. everything is fully working as I intend.

I also have your application running with one INA219 and ATtiny85 - great.

But it would be an elegant solution with two INA219 and ATtiny85. This could be a very nice little monitor module. :)

Ok, yes - I actually allready ordered the INA3221 but I have not received it yet. So the INA3221 only needs one I2C address? and if yes - your drivers for ATtiny85 can be used?

I found this information re. INA3221:

"That module doesn't bring out the 3 pairs of sense pins separately, it cannot be used as a high-side
current sensor, only low-side. Ground is used as the return for all channels."

And the INA3221 is not possible for my project. (sad :( )

Solved !

I have solved the challange.

ATtiny85 - OLED 64x128 (1306 display) - 2xINA219

I have used the Tiny4kOLED and TinyWireM libraries.

ATtiny85 storage use: 6985b / 85% - 145b / 28%

Good to see that! Waiting for your instructables!

Hi!

I'm trying to measure up to 3A following your indications for the CURRENT_REGISTER but still the maximum current I measure is 400mA. These are the values I inserted:

* Calibration Register (address = 05h)
* Data Sheet Page 12 Chapter 8.5.1, Page 25 Figure 27
* Maximum Expected Current 3000 mA
* Current_LSB = 3000 mA / 2^15 ~= 0.0001mA = 100 uA
* R(SHUNT) = 0.1 Ohm
* Cal = 0.04096 / 100 / 0.1 = 4096 (0x1000)
*/

#define CALIBRATION_REGISTER_ADDR 0x05
#define CALIBRATION_UPPER 0x10
#define CALIBRATION_LOWER 0x00
#define CURRENT_LSB 0.1
#define POWER_LSB 20 * CURRENT_LSB

What could be wrong here?

Thank you,

César

3 replies

Hi Chiskas2, CURRENT_LSB should be in mA:

#define CURRENT_LSB 0.0001

Hi again,

Sorry, the code comments were confusing. It is already in mA (100uA=0.1 mA) but even with these right values the maximum measured current was 400mA.

After reading the notes from Adafruit and the INA219 datasheet I found the solution. Apart from these changes to the calibration register, one needs to modify the bits 12-11 in the configuration register. Currently they are set to 00 (: +- 40 mV, Highest current resolution) and I changed them to 10 (: +-160 mV) and it worked. Now I should be able to measure up to 1.6A.

Anyway, thank you for your fantastic project. I use it a lot!

César

good to see that, will you post a I made it here?

0
None
TomJ63

3 months ago

Nice work! I works great with a Trinket.

I see you have modified the .h and .ccp files. I'm not that good at writing libraries, however it looks to me the address of the INA219 is "hardcoded" in the .h file. Yes, it can be altered, but I would like to use more than one INA219, so I would like to call power_mon.begin() several times in my script. What needs to be changed for the INA219 files to accept the address in the begin statement, like power_mon_1.begin(0x41), if possible at all?

1 reply

Hi TomJ63, yes it is possible. but I am tailor-made this library for fitting ATtiny limited resource. If you are using better microcontroller you may seek another complete library, e.g. one from Adafruit.

Hi moononournation,

Is there any documentation to adding/modifying a font to the ssd1306 library? Is this your fork of an earlier DigisparkOLED Library? At this stage I just want o add a period to font_2x.h (so I expect I need a slash as well).

Thanks, Nic

3 replies

good to see that ;>

Thanks, I found that a few hours ago. It looks like the "convert" script in the instructable does not output the array that's in the "font_2x.h" file. Can you confirm the -flip and -rotate switches are still necessary for the output used in "font_2x.h"?