Esp8266 + INA219 + OLED

#include <Wire.h>
#include <Adafruit_INA219.h>
Adafruit_INA219 ina219;
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

float shuntvoltage = 0;
float busvoltage = 0;
float current_mA = 0;
float current_A = 0;
float loadvoltage = 0;
float power_W = 0;

#define CAYENNE_PRINT Serial  
#include "CayenneDefines.h"
#include "BlynkSimpleEsp8266.h"
#include "CayenneWiFiClient.h"

char token[] = "token";
char ssid[] = "ssid";
char password[] = "password";

void setup()
  Cayenne.begin(token, ssid, password);
  Wire.begin(0, 2); // SDA, SDL
  uint32_t currentFrequency;
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);

void loop()
  shuntvoltage = ina219.getShuntVoltage_mV();
  busvoltage = ina219.getBusVoltage_V();
  current_mA = ina219.getCurrent_mA();
  loadvoltage = busvoltage + (shuntvoltage / 1000);
  current_A = current_mA / 1000;
  power_W = current_A * loadvoltage; 
  display.setCursor(0, 0);  
  display.setCursor(45, 0);
  display.setCursor(0, 10);  
  display.setCursor(45, 10);
  display.setCursor(0, 20);  
  display.setCursor(45, 20);

  Cayenne.virtualWrite(V0, loadvoltage);

  Cayenne.virtualWrite(V1, current_A);

  Cayenne.virtualWrite(V2, power_W);


Hi @tad.dvor,

That is the kind of clean simple code I like to see.




This looks just like something I want to incorporate in my solar energy system. check out this mega based PLC that I have, it’s quite a robust little box and fully customizable. A bit expensive but worth it for me. Main site is You’ll see how the resistor packs can be changed out to monitor higher voltage. It’s a good read. I’m kind of a dummy where code is considered, eg. I get the simple stuff but math and float and other codes escape me. Looking for the communities help doing this.I’m going to start a post and see if I get any bites, chime in if your willing.

Nice project, would love to see pics!


Hi @wmontg5988,

$89 isn’t terribly expensive for opto-isolated inputs, a relay bank, good output drivers, an RTC, an LCD, etc, and a box and screw terminals. Frankly, the highest cost of most systems is the box design.

From what I can see, it’s a mega wtih an ESP shield. We can certainly make this work with Cayenne.

Check out this post and merge this code into one of your PLDuino sketches. WifiShield with arduino uno compiling error

@bestes, @rob, @adam, @Ian, check this thing out. Looks cool!




I will do that as soon as my second PLduino arrives, the other one I forget and left in the Philippines. I can get this thing up and running solid before I go back late next year.

Thanks and if you need anything concerning solar, my learning has improved a great deal. Check out there is some great minds on there that can help too. Especially oztules, Rossw and Pete.


Hey @kreggly thought you might like to see the schematics for the PLDuino here:

And the link to libraries, unfortunately you have to dig out the library files add zip library file won’t find them:

Happy Days!