Skip to content

Instantly share code, notes, and snippets.

@maxistar
Created November 16, 2019 14:14
Show Gist options
  • Save maxistar/e461288a361cb1e4d74528fabe73bb2f to your computer and use it in GitHub Desktop.
Save maxistar/e461288a361cb1e4d74528fabe73bb2f to your computer and use it in GitHub Desktop.
ESP-32 and INA219
#include <Wire.h>
#include <Adafruit_INA219.h> // You will need to download this library
Adafruit_INA219 sensor219; // Declare and instance of INA219
void setup(void)
{
Wire.begin(13, 15); //define which pins used for i2c
Serial.begin(9600);
sensor219.begin();
}
void loop(void)
{
float busVoltage = 0;
float current = 0; // Measure in milli amps
float power = 0;
busVoltage = sensor219.getBusVoltage_V();
current = sensor219.getCurrent_mA();
power = busVoltage * (current/1000); // Calculate the Power
Serial.print("Bus Voltage: ");
Serial.print(busVoltage);
Serial.println(" V");
Serial.print("Current: ");
Serial.print(current);
Serial.println(" mA");
Serial.print("Power: ");
Serial.print(power);
Serial.println(" W");
Serial.println("");
delay(2000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment