Hi, I'm new around here and I have come into a problem with my ESP32-C3, has I always start any project I begin writing and testing code to see if it works and if it dose I'll just keep adding more complex parts until it has all the functions added and in full working mode. Having said that I'm building a digital clock for my old land cruiser and started with the oled display and the RTC functions of the ESP32, the problem that I'm having started when I tried to add deep sleep into my sketch and the I2C port stop working, I say stop working because I remove the deep sleep code from my sketch and I still I get the following error on the serial monitor:
E (362790) i2c.master: s_i2c_synchronous_transaction(924): I2C transaction failed
E (362797) i2c.master: i2c_master_multi_buffer_transmit(1186): I2C transaction failed
E (362805) i2c.master: I2C transaction unexpected nack detected
I think that my ESP32 board I2C port got fried or something because if I load the I2C search sketch it dose not find any devices, but if I connect the oled to an Arduino Nano my code works just fine and the display turns on as it should.
I'll add my code, but I don't think that the problem is in my code, I think that by calling the deep sleep start function something got broken in my ESP32.
#include <ESP32Time.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SH110X.h>
#include <Fonts/FreeSansBold24pt7b.h>
#include <Fonts/FreeSansBold9pt7b.h>
#include <Fonts/FreeSans24pt7b.h>
#include <Fonts/FreeSans9pt7b.h>
#define i2c_Address 0x3c
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
#define but_Ho 0
#define but_Mi 3
#define but_sleep 1
#define SDA 8
#define SCK 9
Adafruit_SH1106G display = Adafruit_SH1106G(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
ESP32Time rtc;
int Ho, Mi, Se, Ho_new, Mi_new, Se_new;
void setup(){
Wire.begin();
Serial.begin(9600);
pinMode(but_Ho, INPUT_PULLDOWN);
pinMode(but_Mi, INPUT_PULLDOWN);
pinMode(but_sleep, INPUT_PULLDOWN);
delay(250);
display.begin(i2c_Address, true);
display.display();
display.setFont(&FreeSansBold24pt7b);
display.setTextColor(SH110X_WHITE);
display.display();
delay(2000);
display.clearDisplay();
display.setContrast(255);
display.display();
display.setCursor(4, 36);
display.print("12:00");
display.setContrast(1);
display.display();
}
void loop(){
Ho = rtc.getHour();
Mi = rtc.getMinute();
Se = rtc.getSecond();
display.clearDisplay();
display.setCursor(4, 46);
if(digitalRead(but_sleep) == LOW){
display.oled_command(SH110X_DISPLAYOFF);
// esp_light_sleep_start();
while(digitalRead(but_sleep) == LOW){}
display.oled_command(SH110X_DISPLAYON);
}
if((Se % 2) == 0){
if(Ho < 10){
display.print(" ");
display.print(Ho);
display.print(" ");
}
else{
display.print(Ho);
display.print(" ");
}
if(Mi < 10){
display.print("0");
display.print(Mi);
}
else{
display.print(Mi);
}
display.drawRect(60, 36, 6, 6, 1);
display.fillRect(60, 36, 6, 6, 1);
display.drawRect(60, 18, 6, 6, 1);
display.fillRect(60, 18, 6, 6, 1);
display.display();
}
else{
if(Ho < 10){
display.print(" ");
display.print(Ho);
display.print(" ");
}
else{
display.print(Ho);
display.print(" ");
}
if(Mi < 10){
display.print("0");
display.print(Mi);
}
else{
display.print(Mi);
}
display.display();
}
if(digitalRead(but_Ho)){
Ho++;
if(Ho > 12){
Ho = 1;
}
rtc.setTime(0, Mi, Ho, 1, 1, 2025);
delay(250);
}
if(digitalRead(but_Mi)){
Mi++;
if(Mi > 59){
Mi = 0;
}
rtc.setTime(0, Mi, Ho, 1, 1, 2025);
delay(250);
}
}
Any help or ideas are appreciated.