Esp8266 + INA219 + OLED


#1
#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()
{
  Serial.begin(9600);
  Cayenne.begin(token, ssid, password);
  
  Wire.begin(0, 2); // SDA, SDL
  uint32_t currentFrequency;
  ina219.begin();
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
}

void loop()
{
  Cayenne.run();
  
  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.clearDisplay();
  display.setTextColor(WHITE);
  display.setTextSize(1);
  display.setCursor(0, 0);  
  display.println(loadvoltage);
  display.setCursor(45, 0);
  display.println("V");
  display.setCursor(0, 10);  
  display.println(current_A);    
  display.setCursor(45, 10);
  display.println("A");
  display.setCursor(0, 20);  
  display.println(power_W);    
  display.setCursor(45, 20);
  display.println("W");
  display.display();
}


CAYENNE_OUT(V0)
{
  Cayenne.virtualWrite(V0, loadvoltage);
}

CAYENNE_OUT(V1)
{
  Cayenne.virtualWrite(V1, current_A);
}

CAYENNE_OUT(V2)
{
  Cayenne.virtualWrite(V2, power_W);
}

#2

Hi @tad.dvor,

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

Cheers,

Craig


#3

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. www.digital-loggers.com/plchw.html Main site is www.plc.us 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!


#4

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!

Cheers,

Craig


#5

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 www.anotherpower.com there is some great minds on there that can help too. Especially oztules, Rossw and Pete.


#6

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!


#7

#8