Advertisement
learnelectronics

Arduino Power Monitor

Jul 20th, 2017
4,509
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.35 KB | None | 0 0
  1. /*
  2.  * Arduino Power Monitor
  3.  *
  4.  * learnelectronics
  5.  * 18 JUL 2017
  6.  *
  7.  * www.youtube.com/c/learnelectronics
  8.  */
  9.  
  10. #include <Wire.h>                                             //wire library for I2C comms
  11. #include <Adafruit_SSD1306.h>                                 //driver for the oled
  12. #include <INA219.h>                                           //driver for the ina219
  13.  
  14. #define OLED_RESET 4                                          //oled reset on pin 4
  15.  
  16.  
  17.  
  18. INA219 monitor;                                               //create instance of the INA219 called monitor
  19. Adafruit_SSD1306 display(OLED_RESET);                         //create instance of the SSD1306 called display
  20.  
  21.  
  22.  
  23. void setup()   {                
  24.  
  25.   monitor.begin();                                            //start the ina219
  26.   display.begin(SSD1306_SWITCHCAPVCC, 0x3C);                  //start the oled
  27.   display.display();                                          //show adafruit splash screen
  28.   delay(2000);                                                //wait 2 seconds
  29.   display.clearDisplay();                                     //clear buffer & display
  30.  
  31. }
  32.  
  33.  
  34. void loop() {
  35.  
  36.   display.clearDisplay();                                     //begin each loop by clearing old data
  37.   display.setTextSize(1);                                     //set to smallest text size
  38.   display.setTextColor(WHITE);                                //set color to white
  39.   display.setCursor(0,0);                                     //cursor to upper left
  40.  
  41.   display.print("shunt V: ");                                 //send title to buffer
  42.   display.print(monitor.shuntVoltage() * 1000, 2);            //send shunt voltage to buffer in mV with 2 dec places
  43.   display.println(" mV");                                     //send units to buffer
  44.  
  45.   display.print("shunt I: ");
  46.   display.print(monitor.shuntCurrent() * 1000, 2);
  47.   display.println(" mA");
  48.  
  49.   display.print("bus V:   ");
  50.   display.print(monitor.busVoltage(), 2);
  51.   display.println(" V");
  52.  
  53.   display.print("bus P:   ");
  54.   display.print(monitor.busPower() * 1000, 2);
  55.   display.println(" mW");
  56.  
  57.   display.display();                                          //show whats in the buffer
  58.   delay(1000);                                                //wait one second before restarting the loop
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement