ESP32S3 randomly stopped working

Hi there,

Everything was perfectly working and ESP32S3 stopped working suddenly.
Here is the message,

Begin Websocket client connection and the rest of the message is from the setup() function. After going through these, there is WiFi connection comes but it must be also fine.
I tried pluging out the USB cable and BootLoader mode and then blinking it, it blinks fine. After uploading my code, it fails.
As I told before, I was running perfectly but stopped suddenly.

Anyone, help me please :slight_smile:

Hi there,
Check the Options set for it in the tools menu, PSram , CDC boot, etc.
Check that there’s not something set wrong?
HTH
GL :slight_smile: PJ

Hi PJ,
USB CDC on Boot enabled
USB Firmware MSC on Boot disabled
PSRAM disabled
Upload mode UART0/Hardware CDC
USB Mode Hardware CDC and JTAG

I have no idea what those mean exaclty, I was just googling now.
Thanks a lot.

looks like maybe wifi is not connecting?

Hi cgwaltney,
Thanks for your response.

It is not really about WiFi, I am pretty sure.

WHAT DOES THE BOOT COUNTDOWN REPRESENT?.. sorry for the all caps… im not yelling… just coding

Hey, thanks for now yelling :smiley:
That part of the code is from WebsocketsClient library. So probably it makes the microcontroller ready.

Hi there,
Well for one the PSram should be enabled, CDC on boot probably fine.
Something seems to be forcing boot mode, maybe a pin that’s not initialized correctly or at all.?
Can you post the code I can run a compile and see what it say’s.
HTH
GL :slight_smile: PJ

Hi PJ,
I enabled PSram mode but still same happening. My code works on another XIAO ESP32S3.
Could using RX TX pins and Serial monitor be the problem here? I remove cables on RX TX before uploading the code from the computer.
Also I choose XIAO ESP32S3 and the active port (which is just one), when I check port in Arduino IDE, it says another board there instead of ESP32S3.
I reinstalled Arduino IDE multiple times but still same result. Also I can see nRF52840 has portname in device manager called Seeed XIAO nRF52840 Sense (Interface 0), but when I connect ESP32S3 its name is USB Serial Device in the ports section of the device manager.

// BSP   : esp32 2.0.9
// Board : esp32 / XIAO_ESP32C3
// See https://forum.seeedstudio.com/t/how-to-use-serial1-with-xiao-esp32c3/266306/5
#include <HardwareSerial.h>
#include <Arduino.h>
#include <WiFi.h>
#include <WiFiMulti.h>
#include <WiFiClientSecure.h>
#include <WebSocketsClient.h>
#include <ArduinoJson.h>
#include <ESP32Time.h>

WiFiMulti wiFiClient;
WebSocketsClient webSocket;

#define USE_SERIAL Serial
//WiFi connection
const char * WIFI_SSID ="1111";
const char * WIFI_PASSWORD = "2222222";

void hexdump(const void *mem, uint32_t len, uint8_t cols = 16) {
	const uint8_t* src = (const uint8_t*) mem;
	USE_SERIAL.printf("\n[HEXDUMP] Address: 0x%08X len: 0x%X (%d)", (ptrdiff_t)src, len, len);
	for(uint32_t i = 0; i < len; i++) {
		if(i % cols == 0) {
			USE_SERIAL.printf("\n[0x%08X] 0x%08X: ", (ptrdiff_t)src, i);
		}
		USE_SERIAL.printf("%02X ", *src);
		src++;
	}
	USE_SERIAL.printf("\n");
}

// Initializing the JSON data that we are sending to the WebSocker server
const int capacity = JSON_OBJECT_SIZE(5);
StaticJsonDocument<capacity> doc;


ESP32Time rtc(0); // Created an RTC instance

String message = "{\"status\" : \"connected\"}"; 

HardwareSerial MySerial0(0);

void webSocketEvent(WStype_t type, uint8_t *payload, size_t length)
{
  switch(type)
  {
    case WStype_DISCONNECTED:
    USE_SERIAL.printf("[WSc] Disconnected!\n");
    break;

    case WStype_CONNECTED:
      USE_SERIAL.printf("[WSc] Connected to the url: %s\n", payload);

			// send message to server when Connected
			webSocket.sendTXT(message);      
      break;

    case WStype_TEXT:
    USE_SERIAL.printf("[WSc] get text: %s\n",payload);
    break;

    case WStype_BIN:
    USE_SERIAL.printf("[WSc] get binary length: %u\n",length);
		hexdump(payload, length);
    // send data to server
    // webSocket.sendBIN(payload, length);    
    break;

    case WStype_ERROR:
    case WStype_FRAGMENT_TEXT_START:
    case WStype_FRAGMENT_BIN_START:
    case WStype_FRAGMENT:
    case WStype_FRAGMENT_FIN:
    break;

  }

}


void setup() {
  // USE_SERIAL.begin(921600);
	USE_SERIAL.begin(115200);

	//Serial.setDebugOutput(true);
	USE_SERIAL.setDebugOutput(true);

  Serial.setTxTimeoutMs(0); // maybe needed for Serial.print()
  delay(500);
  Serial.printf("Begin WebSocket client connection...");

  for(uint8_t t = 4; t>0; t--){
    Serial.printf("[SETUP] BOOT WAIT %d...\n",t);
    Serial.flush();

  }
  wiFiClient.addAP(WIFI_SSID, WIFI_PASSWORD);

  // WiFi.disconnect();
  while(wiFiClient.run() != WL_CONNECTED) 
  {
    Serial.printf(".");
    delay(100);
  }

  Serial.printf("Connected to the WiFi!");

  // Server address, port and url
  webSocket.begin("192.168.60.30", 8080, "/sendSensorData");

  // Event handler
  webSocket.onEvent(webSocketEvent);

	// use HTTP Basic Authorization this is optional remove if not needed
	// webSocket.setAuthorization("user", "Password");
  // Try every 2 seconds if WebSocket connection failed
  webSocket.setReconnectInterval(2000);
  delay(1000);
  MySerial0.begin(115200, SERIAL_8N1, -1, -1);  // default TX~D6 RX=D7
  delay(500);
}



int prevRPM = 0;
int currRPM = 0;


int numOfStartups = 0;

int* readRXTXData(){
  
  if(MySerial0.available() > 0) {
      int temp_char = MySerial0.parseInt();
      Serial.print("TEMP CHAR ");
      Serial.println(temp_char);
      if(temp_char == 0){
      }
      else if(temp_char<=6) {
        currRPM = 0;
      }
      else{
            currRPM = temp_char;
 
      if(currRPM > 20) { 
        if(prevRPM <= 20) {
          rtc.setTime(0, 0, 0, 1, 1, 2024); 
          numOfStartups++;
        }
      }

   if(currRPM > 20) {

    }


    if(currRPM < 20){
      if(prevRPM >= 20) {

  
      }
    }
        prevRPM = currRPM;
      }
      
    arr[0] = currRPM;
    // Serial.println("Total runtime: "+String(h)+ ":"+ String(minute)+":"+String(sec));
    
    
    // Sending JSON message in the format: { "value" : 100}
    doc["sensorData"] = currRPM;
 
   
    // Declaring buffer to hold the result
    char output[50];

    serializeJson(doc,output);

    // Sending the message to the server when connected
    webSocket.sendTXT(output);

  // }
  }
 


  delay(100);
  return arr;
  

}


void loop() {

  // int* ptr; // Pointer to hold address
  // ptr = 
  readRXTXData();
  // for(int i =0; i<4;i++) { //Printing out the values returned from readRXTXData()
  //   // Serial.println(ptr[i]);
  // }


  webSocket.loop();


}

Thanks in advance.

@celine Hi, I need a favour can you test bottom of board pins as gpio
I want to know will they able to perform gpio functionalities.

Hi there,
Yes, it’s a well known bug in the Arduino IDE,
" You must select the correct board every time"
HTH
GL :slight_smile: PJ

Hi faizannar,

Thanks for the response.
I couldn’t do it really. I am not good at how to program the microcontrollers yet.

Have a great day.

Hi PJ,

Of course I keep choosing my board and open port. So it’s not about that.
The problem is, ESP32S3 keeps connecting and disconnecting into the port.
Could you help me out with this.

Thanks.

Hi there,
Disconnect it,
USB…
Hold the Boot button down and Plug it back in…
Does it stay enumerated or not?
HTH
GL :slight_smile: PJ
also try same with reset button, if not.

Hi PJ,

I tried that too, of course.
Where is enumerated supposed to show up?
When I want to upload code into the ESP32S3, it doesn’t let me to do it. That’s why I hold the boot button on it and after that give power into it, which means connecting it into the USB cable.
After uploading when I go to the serial monitor, it keeps connecting and disconnecting again.
Doesn’t make sense at all. Something must be corrupted.

Hi there,
I understand that… What I’m telling you is , it’s NOT in Boot loader mode when are trying to upload, the PC is still running on the chip with the offending code. The LOOP portion if it has too short of delay or no code at all, and the Serial port baud rate is at 115200 then it’s a hard to catch at the right time.
If that happens hit upload and try to release the rest button when it hits the port upload code.
if you catch it you can send it a blink or something to fix it.

earlier I was describing what you can try to force it to boot mode by holding the button down while plugging in the usb connection. takes some coordination but that too will stop the loop.
HTH
GL :slight_smile: PJ

Hi PJ,

Thanks for the response.
Of course the microcontroller is not in BOOT mode when I try to upload the code.
But what I am telling is, since it doesn’t let me to upload the code I put the microcontroller into Bootloader mode which means plugging it out from the USB data cable and hold the BOOT button on the microcontroller and then plug the USB cable again and release the BOOT button. And then I upload the code.
If that’s not the case for uploading code, well it lets me upload it after doing this :smile:.
I can upload any kind of example if I go into bootloader mode. Blink code works too.
I will try the one with reset button, thanks.

Have a great day.

It looks like the problem is with the WiFi part. When I remove WiFi related codes from the main code, it works.

Hi there,
Ok , I see that now, LOL… Same thing I was saying.
OK so try that code again but insert a long delay in the “Loop” function.
See if you can upload after a reset after that.
HTH
GL :slight_smile: PJ

Hi PJ,

It did not help sadly. My WiFi module starts in setup function I put 15 seconds delay there and also into the loop but the microcontroller does not even complete the setup function because of the WiFi part, let alone loop function.

Thanks for your help.