Hi everybody,
I have a strange behavior on a 1.54" OLED Display which on other ones does not appear:
same code, just plugging in a 1.3" OLED
The code loaded on an ESP32C supermini is this one:
// Digital Clock Galactico
// Test for ESP32C3 Supermini
// November 2023
// Bernardo Gullasch
// including Wifi, OLED, Setbuttons
#include <DS3231.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SH110X.h>
#include <Adafruit_SSD1306.h>
#include <SPI.h>
#include <WiFi.h>
// Create the OLED display
Adafruit_SH1106G oled = Adafruit_SH1106G(128, 64, &Wire, -1);
// WiFi setup data
const char* ssid = "Galactico_Salon"; // Name of the Wi-Fi box
const char* password = "saturno002"; // MDP of the Wi-Fi box
const char* ntpServer = "cl.pool.ntp.org";
const long gmtOffset_sec = 3600 * -3;
const int daylightOffset_sec = 3600 * 1;
int AdjustPin = 1; // black button
int SetPin = 0; // yellow button
bool Century = false;
bool h12; // RTC read Hour Parameter
bool PM; // RTC read Hour Parameter
DS3231 Clock;
int DoW;
const char *WeekDay[] = {"Domingo ", "Lunes ", "Martes ", "Miercoles", "Jueves ", "Viernes ", "Sabado "};
bool END;
int Block[7];
int setVal=0;
int dispPos=0;
int showHour;
int showMinute;
int count;
// --------- SETUP ---------
void setup()
{
oled.begin();
oled.setTextSize(1);
oled.setTextColor(SH110X_WHITE, SH110X_BLACK);
oled.clearDisplay();
oled.display();
Wire.begin();
delay(100);
pinMode(AdjustPin, INPUT); // right button
pinMode(SetPin, INPUT); // left button
// Serial.println(" ***** Start Setup *****");
WiFi.mode(WIFI_STA); // Optional
WiFi.begin(ssid, password);
oled.setCursor(0,0);
oled.println(" Time init");
oled.println(" Connecting");
while (WiFi.status() != WL_CONNECTED)
{
oled.print("."); oled.display();
count++;
if(count>100) {oled.clearDisplay(); oled.setCursor(0,0); oled.println("connection failed"); oled.display(); delay(2000); break;}
delay(100);
}
if(WiFi.status() == WL_CONNECTED)
{
oled.clearDisplay();
oled.setCursor(0,0);
oled.println("Connected to ");
oled.println();
oled.println(ssid);
oled.println();
oled.println("Local ESP32 IP: ");
oled.println();
oled.println(WiFi.localIP());
oled.display();
delay(3000);
oled.clearDisplay();
oled.setCursor(0,0);
oled.println("get Time from NTP...");
oled.display();
// We configure the NTP server
configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
struct tm timeinfo;
if (!getLocalTime(&timeinfo))
{
oled.clearDisplay();
oled.setCursor(0,0);
oled.println("Failed to obtain time");
oled.println("adjust time manually");
oled.display();
delay(2000);
InputTime();
}
else
{
Block[0] = timeinfo.tm_year -100;
Block[1] = timeinfo.tm_mon + 1;
Block[2] = timeinfo.tm_mday;
Block[3] = timeinfo.tm_wday;
Block[4] = timeinfo.tm_hour;
Block[5] = timeinfo.tm_min;
Block[6] = timeinfo.tm_sec;
SetClock();
oled.clearDisplay();
oled.setCursor(0,0);
oled.println("Time set OK");
oled.display();
}
}
else
{
InputTime();
}
//delay(3000);
// while (!digitalRead(SetPin)) {;}
Clock.setClockMode(false); // Clock 24 Hour Mode
Serial.println("ready for Setup ...");
Block[0] = Clock.getYear(), DEC;
Block[1] = Clock.getMonth(Century), DEC;
Block[2] = Clock.getDate(), DEC;
Block[3] = Clock.getDoW(), DEC;
Block[4] = Clock.getHour(h12,PM), DEC;
Block[5] = Clock.getMinute(),DEC;
Block[6] = Clock.getSecond(),DEC;
oled.clearDisplay();
//oled.drawRect(1,1,126,30,WHITE);
oled.setCursor(4,5);
oled.print("RTC actual time is");
oled.setCursor(4,12);
oled.print("-------------------");
oled.setCursor(4,19);
if (Block[2]<10) {oled.print("0");}
oled.print(Block[2]);
oled.print(".");
if (Block[1]<10) {oled.print("0");}
oled.print(Block[1]);
oled.print(". ");
oled.print("20"); oled.print(Block[0]);
oled.print(" ");
if(Block[4]<10) {oled.print("0");} oled.print(Block[4]);
oled.print(":");
if(Block[5]<10) {oled.print("0");} oled.print(Block[5]);
oled.print(":");
if(Block[6]<10) {oled.print("0");} oled.println(Block[6]);
oled.drawRect(0,0,128,32,WHITE);
oled.display();
/* while (!digitalRead(SetPin) && !digitalRead(AdjustPin)) {;}
// **************** NOW INPUT DATA *******************
if (digitalRead(SetPin))
{
oled.clearDisplay();
delay(200);
InputTime();
}
*/
delay(5000);
oled.clearDisplay();
oled.setCursor(0,20);
oled.print("* Time Set ready *");
oled.display();
delay(1000);
// LET´S GO
} // --------------------- finish Setup ------------------------
void loop()
{
showTime();
}
// ------------------------------------- End Loop ------------------------------
void InputTime()
{
Block[0]=23;
Block[1]=11;
Block[2]=18;
Block[3]=6;
setVal=3;
while (setVal<7) // input date/time values
{
if (digitalRead(AdjustPin)) // ajust actual value
{
Block[setVal]++ ;
if (Block[0] > 32) {Block[0] = 22;}
if (Block[1] > 12) {Block[1] = 1;}
if (Block[2] > 31) {Block[2] = 1;}
if (Block[3] > 7 ) {Block[3] = 1;}
if (Block[4] > 23) {Block[4] = 0;}
if (Block[5] > 59) {Block[5] = 0;}
if (Block[6] > 59) {Block[6] = 0;}
delay(100);
}
if (digitalRead(SetPin)) // set value and goto next
{
setVal++;
delay(100);
}
showInput();
delay(200);
} // ready input date/time values 0 to 5
oled.clearDisplay();
oled.setCursor(0,0);
oled.print("Ready for adjust time");
oled.display();
while(!digitalRead(SetPin)) {;}
SetClock();
}
void showInput()
{
oled.clearDisplay();
oled.setCursor(0,0);
oled.println("Hora Minuto Segundo");
oled.println("---------------------");
for (dispPos=4; dispPos<7; dispPos++)
{
oled.setCursor(((dispPos-4)*36),19);
if (dispPos==setVal) {oled.setTextColor(SH110X_BLACK, SH110X_WHITE);} else {oled.setTextColor(SH110X_WHITE, SH110X_BLACK);}
if (Block[dispPos] < 10) {oled.print("0"); oled.print(Block[dispPos]);} else {oled.print(Block[dispPos]);}
}
oled.display();
oled.setTextColor(SH110X_WHITE, SH110X_BLACK);
}
void SetClock()
{
Clock.setClockMode(false); // set to 24h
Clock.setSecond(Block[6]);
Clock.setMinute(Block[5]);
Clock.setHour(Block[4]);
Clock.setDoW(Block[3]);
Clock.setDate(Block[2]);
Clock.setMonth(Block[1]);
Clock.setYear(Block[0]);
oled.setCursor(30,24);
oled.print("* READY *");
oled.display();
delay(1000);
}
void showTime()
{
oled.clearDisplay();
oled.setTextSize(1);
oled.setCursor(0,8);
if(Clock.getDate() < 10) {oled.print("0");}
oled.print(Clock.getDate(), DEC);
oled.print(".");
oled.print(Clock.getMonth(Century), DEC);
if(Clock.getMonth(Century) < 10) {oled.print("0");}
oled.print(". ");
oled.print("20"); oled.print(Clock.getYear(), DEC);
oled.print(" ");
oled.print(WeekDay[Clock.getDoW()]);
oled.drawRoundRect(0,25,128,32,10,WHITE);
oled.drawRoundRect(1,26,126,30,10,WHITE);
oled.setTextSize(2);
oled.setCursor(15,33);
if ((Clock.getHour(h12, PM)) < 10){oled.print("0");}
oled.print(Clock.getHour(h12, PM));
oled.print(":");
if ((Clock.getMinute()) < 10){oled.print("0");}
oled.print(Clock.getMinute());
oled.print(":");
if ((Clock.getSecond()) < 10){oled.print("0");}
oled.print(Clock.getSecond());
oled.display();
}
the display is not broke, I can reproduce the issue on another one of the same type.
the effect appears only using the Adafruit library, with other libraries the respecting examples work fine.
Any idea what this is about ?