#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(2, 0); // 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);
}
Comments