Mini OLED Panel Meter
INTRO
This is an arduino programmable OLED panel meter that uses the INA226 power monitor chip to sense the voltage, and current which is then shown on the SSD1306 OLED display. Usually other small panel meters which are the ones on amazon/ebay that are dirt cheap are very inaccurate, and some of them come with this potentiometer that can vary the voltage and current, but this is only accurate within a small range of values, and usually messes up the volt/current reading. To avoid this frustration I built my own panel meter that can display both voltage, and current accurately, be very tiny, be easy to use, measure watts, and change units of any measurement..
Working Principle
Background On Current and voltage measurement
Measuring Voltage is quite easy where all you have to do is connect the voltage you want to measure to an ADC (analog to digital converter) for a microcontroller to then read, and display the values for you. An ADC pretty much samples the analog voltage at certain points in time, and stores those values as bits. The higher the bit resolution, which is the amount of samples the ADC takes of the analog voltage, the better the accuracy. Measuring current can be done in many different ways, but I'll only focus on the one this project uses which is using a current shunt. A current shunt is just a resistor connected in series with the load you are measuring, and according to Ohms Law, the current running through this resistor will create a voltage drop across the resistor equal to I times R. The current through the shunt will be the same as the the current running through the load as it is connected in series with the load. If the value of the shunt is known then the current through the load will be equal to voltage drop across the shunt/resistance of shunt. Shunts can be connected in the high or low side where high side is when the current shunt is connected to the positive side of the load, while low side is connected to the ground side of the load. I chose high side sensing for this project.
About The Components
This project uses the INA226 power monitoring IC to measure the voltage, and current. It achieves this by measuring the voltage across the shunt resistor, and calculates the current running through the load as the voltage is simply measured by the ADC of the INA226. The heart of this project is the ATMEGA328p, since it reads the values from the INA226 through I2C, and displays these values to the OLED display through again, I2C. The current shunt is a 5mΩ resistor with 1% tolerance rated to be 2W which creates a voltage drop that the INA226 measures. The SSD1306 is a typical display that is available everywhere that is commonly used in arduino project where you simply power it up, and feed it information through the I2C line.
SCHEMATIC
The ATMEGA328p is pretty much the same as an Arduino mini, and to program an Arduino mini you would need a FTDI programmer in order to convert the USB to serial communication. In order to program the ATMEGA328p, the FTDI programmer needs to connect to the ATMEGA by using pins DTR, RX, TX, CTS, POWER, and GROUND. Not only do you have to program the ATMEGA, but since the chip is blank it needs to be bootloaded, and to bootload the chip you need to connect an Arduino uno to the chip with pins 15, 16, 17, and 29. Programming, and bootloading the chip will be explained in the steps below. The two 10k resistors are on pins 28, and 27 of the ATMEGA as those are the I2C pins (SDA and SCL). These two pins need a pull-up resistor to function correctly where the display, and INA226 use I2C communication which is why they have pins labelled SDA, and SCL (serial data and serial clock). VBUS of the INA226 is the point (with respect to ground) that you measure the voltage with, IN+ goes to the positive side of the shunt, and IN- goes to the load side of the shunt, the alert pin is used to alert the user of fault conditions.
Bootloading and Programming PCB
Bootloading
D11 → 15
D12 → 16
D13 → 17
+3.3v → +3.3v
GND → GND
Then open the Arduino IDE, and open an example sketch called "ArduinoISP", and upload the code. After this, go to tools, and select "Programmer" then "Arduino as ISP". Lastly, go to tools and select "Burn Bootloader" where if it's bootloaded, the board will quickly blink 3 times while bootloading, and you will get a message in the command window telling you it has been bootloaded.
Programming
After bootloading, the board is now ready to be programmed. First, get the FTDI programmer, and connect to the female header shown in the picture above, or you can follow the pinout of the female header, and connect an FTDI board to it through jumper wires. Make sure to set the FTDI programmer to 3.3v. When everything is connected, simply upload the code in step 4.
Calibration
Keep in mind that you may have to tinker with the resistance value for the "setResistorRange" function since resistors aren't perfect. In order to calibrate the sensor you must run the code, and turn on the serial monitor where it would first read 0 or near 0, then you must connect a load, and pass a known current through it. Passing this known current will give you a reading on the serial monitor. Divide this number by 1000 (since it's in mV), then divide it by the known current (in amps), and this should give you the real resistance value. Plug the real resistance value into the "setResistorRange" function to calibrate the board. In step 4 I set the value to 5mΩ, but this of course needs changing if you use a 1% tolerance resistor as you most likely wouldn't need to calibrate it if you use a 0.1% tolerance resistor.
Using It
Wiring the board is very easy, simply follow the diagram above, and keep in in mind you must connect grounds together if you are using two separate supplies. This board can only handle around 5A of current measurement before it starts to get warm, but it can theoretically measure up to 16A as the max sense voltage can only be 80mV. However, the resistor heating up will raise its resistance, and cause inaccuracies. Voltage reading may be inaccurate due to the voltage drop of the measurement wires, to avoid this make sure to use thick wires. The meter can only measure a max of 36v, though, I believe it's possible to redesign the board, add a voltage divider to limit the output voltage, and change the code to get a higher voltage mesurment value. Keep in mind you dont have to use it as a panel meter where you can use it to display anything you want.
Library I used : link
More info on library : link
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <math.h>
#include <INA226_WE.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET 4
#define I2C_ADDRESS 0x40
Adafruit_SSD1306 display(OLED_RESET);
//INA226 INA(0x40);
float shuntVoltage_mV = 0.000;
float busVoltage_V = 0.000;
float current_A = 0.000;
float loadVoltage_V = 0.000;
float x;
float z;
float y;
INA226_WE ina226 = INA226_WE(0x40);
void setup() {
Wire.begin();
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
Serial.begin(9600);
ina226.init();
ina226.setResistorRange(0.00515,10.0);
ina226.waitUntilConversionCompleted();
ina226.setConversionTime(CONV_TIME_140);
ina226.setAverage(AVERAGE_256);
pinMode(2,OUTPUT);
}
void loop() {
// ina226.setCorrectionFactor(1);
//ina226.readAndClearFlags();
shuntVoltage_mV = ina226.getShuntVoltage_mV();
busVoltage_V = (ina226.getBusVoltage_V());
current_A = ina226.getCurrent_mA()/1000;
if (current_A <=0) {
x = 0.000;
}
else{
x = current_A;
}
if (busVoltage_V >= 10){
z = 18;
}
else {
z = 30;
}
if ( current_A >= 10){
y = 18;
}
else {
y = 30;
}
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(2);
display.setCursor(z,0);
display.print(busVoltage_V,3);
display.setCursor(110,0);
display.print("V ");
display.setTextColor(WHITE);
display.setTextSize(2);
display.setCursor(y,18);
display.print(x,3);
display.setCursor(110,18);
display.print("A ");
display.display();
Serial.println(shuntVoltage_mV,5);
}
Mini OLED Panel Meter
*PCBWay community is a sharing platform. We are not responsible for any design issues and parameter issues (board thickness, surface finish, etc.) you choose.
- Comments(0)
- Likes(4)
- Marios Daskalakis Sep 28,2024
- Engineer Apr 07,2024
- Manuel Mota Feb 06,2024
- Commodore Bench Dec 12,2023
- 0 USER VOTES
- YOUR VOTE 0.00 0.00
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
More by Arrwin TecKnacks
-
-
-
-
-
-
3D printed Enclosure Backplate for Riden RD60xx power supplies
154 1 1 -
-