i found a problem when display real time clock DS3231 in LCD 20x4 i2c using ESP32 microcontroller, the code works properly, but every 8 second, it skipped one data, so both the serial monitor and LCD display became like this:
Time: hh:mm:13
Time: hh:mm:14
Time: hh:mm:15
Time: hh:mm:16
Time: hh:mm:17
Time: hh:mm:18
Time: hh:mm:19
Time: hh:mm:20
Time: hh:mm:22
....
and so on (every 8 second), the time hh:mm:21 did not display, it display 22 instead, make the time become offset from the real time.
i used oled SSD1306 to compare it, when it's sharing I2C bus with LCD, the oled SSD1306 also skip one data even in LCD i don't display any RTC data (i display dummy text instead because i just want to check the effect of sharing connection i2c between them), but when oled SSD1306 stands alone, it works normally without skip any data.
is there any solutions for this? i'm still a beginner and in my project i need this 2 module display (oled and lcd), should i use different i2c bus for them to work properly ? (as far as i know esp32 has two i2c bus)
here i drop the program code
#include <Arduino.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <RTClib.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
RTC_DS3231 rtc;
LiquidCrystal_I2C lcd(0x27, 20, 4); // set the LCD address to 0x27 for a 20 chars and 4 line display
Adafruit_SSD1306 display = Adafruit_SSD1306(128, 32, &Wire, -1);
void setup(){
Serial.begin(115200);
rtc.begin();
//rtc.adjust(DateTime(__DATE__, __TIME__));
lcd.init();
lcd.backlight();
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(2);
display.setCursor(0, 0);
display.print("Processing...");
display.display();
delay(3000);
}
void loop(){
DateTime now = rtc.now();
Serial.print("Time: ");Serial.print(now.hour(), DEC);Serial.print(":");Serial.print(now.minute(), DEC);Serial.print(":");Serial.println(now.second(), DEC);
lcd.setCursor(0,0);
lcd.print("Acc-m/s^2");
lcd.setCursor(0,1);lcd.print("X:-AA.AA");
lcd.setCursor(0,2);lcd.print("Y:-AA.AA");
lcd.setCursor(0,3);lcd.print("Y:-AA.AA");
lcd.setCursor(9,0);lcd.print("|");
lcd.setCursor(9,1);lcd.print("|");
lcd.setCursor(9,2);lcd.print("|");
lcd.setCursor(9,3);lcd.print("|");
lcd.setCursor(11,0);lcd.print("hh");
lcd.setCursor(13,0);lcd.print(":");
lcd.setCursor(14,0);lcd.print("mm");
lcd.setCursor(16,0);lcd.print(":");
lcd.setCursor(17,0);lcd.print("ss");
lcd.setCursor(10,1);lcd.print("CO:AAA ppm");
lcd.setCursor(10,2);lcd.print("T :AA.AA C");
lcd.setCursor(10,3);lcd.print("RH:AA.AA %");
display.clearDisplay();
display.setTextSize(2);
display.setCursor(0, 0);
display.print("Time: ");display.print(now.hour(), DEC);display.print(":");display.print(now.minute(), DEC);display.print(":");display.println(now.second(), DEC);
display.display();
delay(1000);
}
