Advertisement
Guest User

Overkill BMS - broken SoC code

a guest
Apr 3rd, 2021
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. #include "bms.h"
  2. #include "U8glib.h"
  3. #include <Wire.h>
  4. #include <Adafruit_SH1106.h>
  5. #define BRIGHTNESS 0x01
  6. #define BRIGHTNESSREG 0x81
  7.  
  8.  
  9. #define OLED_RESET 4
  10. Adafruit_SH1106 display(OLED_RESET);
  11.  
  12. OverkillSolarBms bms = OverkillSolarBms();
  13. uint32_t last_update;
  14.  
  15.  
  16. void setup() {
  17. display.begin(SH1106_SWITCHCAPVCC, 0x3C);
  18.  
  19. display.display();
  20. display.clearDisplay();
  21.  
  22. delay(500);
  23.  
  24. Serial.begin(9600);
  25.  
  26. while (!Serial) { // Wait for the BMS serial port to initialize
  27. }
  28.  
  29. last_update = millis();
  30. bms.begin(&Serial);
  31.  
  32. }
  33.  
  34. void loop() {
  35. bms.main_task();
  36. uint8_t soc = bms.get_state_of_charge();
  37.  
  38.  
  39. // Do something at 1 millisecond
  40. if (millis() - last_update >= 2500) {
  41.  
  42. display.clearDisplay();
  43. display.setTextSize(4);
  44. display.setTextColor(WHITE);
  45. display.setCursor(0,0);
  46.  
  47. display.print("State: ");
  48. display.print(soc, DEC);
  49. display.println("%");
  50.  
  51. display.display();
  52. Wire.beginTransmission(0x3c);
  53. Wire.write(0x00);
  54. Wire.write(BRIGHTNESSREG);
  55. Wire.endTransmission();
  56. Wire.beginTransmission(0x3c);
  57. Wire.write(0x00);
  58. Wire.write(BRIGHTNESS);
  59. Wire.endTransmission();
  60. last_update = millis();
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement