Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Arduino Power Monitor
- *
- * learnelectronics
- * 18 JUL 2017
- *
- * www.youtube.com/c/learnelectronics
- */
- #include <Wire.h> //wire library for I2C comms
- #include <Adafruit_SSD1306.h> //driver for the oled
- #include <INA219.h> //driver for the ina219
- #define OLED_RESET 4 //oled reset on pin 4
- INA219 monitor; //create instance of the INA219 called monitor
- Adafruit_SSD1306 display(OLED_RESET); //create instance of the SSD1306 called display
- void setup() {
- monitor.begin(); //start the ina219
- display.begin(SSD1306_SWITCHCAPVCC, 0x3C); //start the oled
- display.display(); //show adafruit splash screen
- delay(2000); //wait 2 seconds
- display.clearDisplay(); //clear buffer & display
- }
- void loop() {
- display.clearDisplay(); //begin each loop by clearing old data
- display.setTextSize(1); //set to smallest text size
- display.setTextColor(WHITE); //set color to white
- display.setCursor(0,0); //cursor to upper left
- display.print("shunt V: "); //send title to buffer
- display.print(monitor.shuntVoltage() * 1000, 2); //send shunt voltage to buffer in mV with 2 dec places
- display.println(" mV"); //send units to buffer
- display.print("shunt I: ");
- display.print(monitor.shuntCurrent() * 1000, 2);
- display.println(" mA");
- display.print("bus V: ");
- display.print(monitor.busVoltage(), 2);
- display.println(" V");
- display.print("bus P: ");
- display.print(monitor.busPower() * 1000, 2);
- display.println(" mW");
- display.display(); //show whats in the buffer
- delay(1000); //wait one second before restarting the loop
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement