Skip to content

Commit

Permalink
- Added battery percentage, watts in and watts out on display
Browse files Browse the repository at this point in the history
- Added screen address and OLED reset parameter
- Fallback log for SSD1306 initialisation correctly
- Working with more display
- Updated Readme with new display image
- Removing display glitches
  • Loading branch information
Stefano Russello committed Feb 15, 2024
1 parent 27409af commit 55d911d
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 6 deletions.
7 changes: 7 additions & 0 deletions Bluetti_ESP32/MQTT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,13 @@ void publishTopic(enum field_names field_name, String value){
}
}

if (map_field_name(field_name) == "total_battery_percent") {
disp_setBattery(value);
} else if (map_field_name(field_name) == "dc_input_power") {
disp_setWattIn(value);
} else if (map_field_name(field_name) == "ac_output_power") {
disp_setWattOut(value);
}

}

Expand Down
70 changes: 64 additions & 6 deletions Bluetti_ESP32/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,20 @@ byte days = 0;
bool enableProgressbar=false;
String strdispIP = "NoConf";
String strdispStatus="boot..";
String strBattery = "";
String strWattIn = "";
String strWattOut = "";
byte prevStateIcons = 0;
byte prevBTStateIcons = 0;
byte prevMQStateIcon = 0;


#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3C for 128x64, 0x3D for 128x32
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

void initDisplay()
{
Expand All @@ -53,19 +59,20 @@ void initDisplay()
digitalWrite(DISPLAY_RST_PORT, HIGH);
delay(20);
#endif
Wire.begin(DISPLAY_SDA_PORT, DISPLAY_SCL_PORT);
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C, false, false))
// Wire.begin(DISPLAY_SDA_PORT, DISPLAY_SCL_PORT); // Cause issue on a few display
if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS))
{
Serial.println(F("display: SSD1306 allocation failed"));
for (;;)
;
for (;;);
} else {
Serial.println(F("display: SSD1306 initialised correctly!"));
}
display.clearDisplay();
display.setTextSize(1); // Draw 2X-scale text
display.setTextColor(BLACK,WHITE);
display.setCursor(1, 1);
display.drawRect(0,0,73,10,WHITE);
display.println("BlueTTI Wifi");
display.println("BLUETTI Wifi");
wrDisp_IP();
wrDisp_Running();
wrDisp_Status("Init....");
Expand Down Expand Up @@ -237,6 +244,33 @@ void wrDisp_Status(String strStatus)
display.println("Status:" + strStatus);
display.display();
}
void wrDisp_Battery(String percent)
{
display.fillRect(0,45,50,20,0);
display.setTextColor(WHITE,BLACK);
display.setCursor(0, 45);
display.setTextSize(2);
display.println(percent + "%");
display.display();
display.setTextSize(1);
}
void wrDisp_WattIn(String watt)
{
display.fillRect(50,45,60,8,0);
display.setTextColor(WHITE,BLACK);
display.setCursor(50, 45);
display.println("IN: " + watt + "W");
display.display();
}
void wrDisp_WattOut(String watt)
{
display.fillRect(50,53,60,8,0);
display.fillRect(110, 48, 18, 8, 0); // Remove glitch under MQ
display.setTextColor(WHITE,BLACK);
display.setCursor(50, 53);
display.println("OUT: " + watt + "W");
display.display();
}
void wrDisp_mqttConnected(bool blMqttConnected)
{
display.fillRect(115, 136, 13, 13, 0);
Expand Down Expand Up @@ -494,6 +528,30 @@ void disp_setIP(String strIP)
strdispIP = strIP;
}
}
void disp_setBattery(String battery)
{
if (battery != strBattery)
{
wrDisp_Battery(battery);
strBattery = battery;
}
}
void disp_setWattIn(String watt)
{
if (watt != strWattIn)
{
wrDisp_WattIn(watt);
strWattIn = watt;
}
}
void disp_setWattOut(String watt)
{
if (watt != strWattOut)
{
wrDisp_WattOut(watt);
strWattOut = watt;
}
}
void disp_setStatus(String strStatus)
{
if (strStatus != strdispStatus)
Expand Down
3 changes: 3 additions & 0 deletions Bluetti_ESP32/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ void disp_setBlueTooth(bool boolBtConn=false);
void disp_setWifiSignal(int extWifMode=0, int extSignal=-100);
void disp_setStatus(String strStatus);
void disp_setIP(String strIP);
void disp_setBattery(String battery);
void disp_setWattIn(String watt);
void disp_setWattOut(String watt);
void disp_setMqttStatus(bool blMqttconnected=false);
#endif
#include <Arduino.h>
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ Display functionality:
* a progressbar is available but currently not used anywhere. (to see where it can be used)
* Show bluetooth icon status. Connected is static, blinking is trying to connect, together with message in case of scanning.
* Show MQTT icon status. Connected is static, blinking is trying to connect.
* Show battery percentage, watts In and Out

Example display screen:
![DisplayImage](doc/images/display.jpg)
Expand Down
Binary file modified doc/images/display.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 55d911d

Please sign in to comment.