ESP32 C3 I2C not working after using deep sleep

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.

I don't see any deep_sleep, just comented out light sleep.
If you think the esp32 has a non-working I2C, load a I2C sample sketch to test the board.
If the test fails, replace the board.
I can't imagine how a light sleep command would break a board. Make sure you power cycle and reset the board before testing it.
Good luck.
One other thing, make sure this is NOT a boards 3 issue. Check the migration document at HERE

I did remove the deep sleep form the code and the light sleep command is commented out.
I have load the I2C search sketch on the ESP32 and it doesn't find any devices.
I'm jet to replace the ESP32-C3 for another ESP board, but just like you I can't imagine how deep sleep can damage a board.

Either try a few more scans (other sketches, there are lots around), and if you do have a second board, try the scan on it. Just do a standard problem resolution procedure and see which branch the error happens.
Have you RESET the board using the RST button?
BTW, do you know that when you return from deep sleep, the board reboots? Is that the behaviour you want?

on the ESP32-C3 (and all ESP32 chips), deep sleep always causes a full reset. This is by design—it doesn’t preserve RAM or code state during deep sleep.

If you want to resume the loop after the sleep, you have to use light sleep. There are other boards that allow reumption after a deep sleep, check out RP2040 and the new RP2350???

I actually started this project with an RP2040 board and as it was my first time using a RP2040, but It started acting wired on me, it began need to enter boot mode to load an sketch so I changed for the ESP32 which I'm familiar with.

Yes, many of the new boards have unusual reset/upload scenarios, BUT they also are inherently lower in power.
Check out the following.
https://www.pjrc.com/store/teensy41.html

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.