Getting Serial output from ESP32 S2

Hello. I'm trying to program ESP32 S2 but I can't see what is going on within it, since Serial.printf is not working. I know that there is a special procedure to upload the sketch on ESP32 S2 by pressing both buttons in the right order. But once the sketch is uploaded I can not get any Serial output in Arduino IDE any more.

Please show your code and connection diagram

It's nothing special. ESP32 S2 Mini connected to PC with USB-C cable:
image

The code is very basic. I'm having no problems with other ESP32 boards. But S2 seems to have some special requirements.

#include <WiFi.h>

void setup () {
    Serial.begin (115200);

    Serial.println ("whatever");
}

void loop () {

}

Is it seen by the PC as COM or USB pheripheral? (I don't own such board BUT ESP32 S.)

Serial over USB. The same as with other ESP32 boards, exept that it works with other ESP32 boards but not with S2.

Is the serial monitor baud rate matching the serial baud rate? Have you properly selected your board in the IDE?

Yes I did. I can compile and upload the sketch.

ESP32 S board (Fig-1) has a USB/UART Converter and this board is seen by PC as a COM pheripheral. Does ESP32 S2 Board contain such a converter? If not, the ESP32 S2 board will be seen by the PC as a USB pheripheral.


Figure-1:

Did you installed required drivers?
Please see this tutorial:
Establish Serial connection to ESP32S2

The ESP32 S2 has native USB, so i think it is not connected to UART0 but you need to do something else.

I also don't own a board so i can't verify anything, but from google i found
This

Hope that helps.

Thank you all. I tried everything. Unfortunately nothing worked for me. I guess I'll go with another ESP32 board.

Hi @bojan_jurca. A fairly unique thing about the boards that use the microcontrollers of the ESP32 family with native USB capability (as is the case with your board) is that they are typically configured to have their USB CDC serial port disabled by default.

That default disabled configuration is appropriate when your sketch doesn't use that port, but in cases where you do need it (such as when your sketch calls Serial.println), then it is necessary to configure the board so that the port will be enabled. Fortunately this is quite easy since the ESP32 boards platform developers configured the board definition to produce a custom board options menu you can use to enable or disable the port as needed via the Arduino IDE user interface.

Please try this:

  1. Select Tools > USB CDC On Boot > Enabled from the Arduino IDE menus.
  2. Upload your sketch to your board again, just as you did before.

Now check the Serial Monitor. Hopefully you will now see the expected output from the board there.

2 Likes

Unfortunately the result is the same.

When I'm having trouble with serial output, I like to do a quick check with the most simple possible sketch. If this works, then I know the problem has something to do with my real sketch. If it doesn't work, then I know the problem is not related to my sketch code. It seems maybe a little silly, but it allows me to be sure I'm focusing my troubleshooting efforts in the right direction.

Try uploading this sketch to your Arduino board:

  1. Copy and paste this code as a new sketch in Arduino IDE:

    void setup() {
      Serial.begin(9600);
    }
    
    void loop() {
      Serial.println("hello");
      delay(1000);
    }
    
  2. Upload the sketch to your Arduino board.

  3. Select Tools > Serial Monitor from the Arduino IDE menus to open the Serial Monitor view if it is not already open.

Do you now see the word "hello" being printed in the Serial Monitor's output field once a second?

I've tested all possible transfer speeds with a simple sketch as yours with no success.

I'm sure it has to do something with CDC, since after installing GitHub - chegewara/EspTinyUSB: ESP32S2 native USB library. Implemented few common classes, like MIDI, CDC, HID or DFU (update). and running CDC example I'm starting to get some kind of serial output, although only from callback functions. Serial.print... still doesn't work.

This thread might be helpful.

Thank you, but my problem is different. I can get ESP32 S2 into "upload" mode by holding the boot key, pressing reset key and then releasing boot key. "Upload" serial connection appears and I can upload the sketch.

The problem occurs afterwards the sketch is run: the serial port disappears.

If I enable CDC by using the EspTinyUSB library at startup, another serial interface appears (not the same as used for "upload"). Some serial communication is possible (through the new serial port) although Serial.print... still doesn't work.

This is as far as I've got.

The following sketch also does not dump any message to the Serial Monitor though it is opened. The onboard LED keeps blinking at 1-sec interval.

//#include <WiFi.h>
#define LED 15

void setup () 
{
  Serial.begin (115200);
  pinMode(LED, OUTPUT);

  Serial.println ("whatever");
}

void loop () 
{
  digitalWrite(LED, HIGH);
  delay(1000);
  digitalWrite(LED, LOW);
  delay(1000);
  Serial.println("Hello");
}

Now, the investigation is to be made if this is the feature of the board that the Virtual COM Port (USB Protocol/Virtual COM Protocol within the MCU) is only designed to receive code/data of the sketch from IDE and NOT to send any message from MCU to the OutputBox of the Serial Monitor of the IDE located on the desktop of PC!!

Schematic of ESP32 S2 Board shows that the USB (D+, D-) signals are arriving to the MCU via GPO-20 and GPIO-19 respectivey. The Serial.print() command targets the hardware UART0 Port which is on GPIO-1(U0_TXD) and GPIO-3(U0_RXD). Therefore, it is natural that the it is not possible for the USB Port of the MCU to forward the message "Hello" of this command Serial.print("Hello") to the Serial Monitor. If UART0 is to be routed towards GPIO-19/20, then there must be a embedded TTL/USB converter within the MCU. In that case, Serial.print("Hello") should work; but, practically, I could not make it work.

My thorough investigation has established that the following hardware (Fig-1) and software arrangement delivers messages from ESP32 S2 Mini Board to the Serial Monitor when Serial1 (UART1) is routed to GPIO-1 (TX1) and GPIO-3 (RX1). (I could not manage to route UART0.)


Figure-1:

Sketch:

//#include <WiFi.h>
#define LED 15

void setup ()
{
  Serial1.begin (115200, SERIAL_8N1, 3, 1);
  pinMode(LED, OUTPUT);

  //Serial1.println ("whatever");
}

void loop ()
{
  digitalWrite(LED, HIGH);
  delay(2000);
  digitalWrite(LED, LOW);
  delay(2000);
  Serial1.println("Hello");
}

Output: (synchronized with LED blinkings)

23:04:54.214 -> Hello
23:04:58.228 -> Hello
23:05:02.214 -> Hello
23:05:06.204 -> Hello
1 Like

Hello,

When I deleted everything else, your sketch started working on the same port as being uploaded from (with CDC on boot enabled. Reset was needed but this is not a problem at all).

I had some class instances declared prior to setup () previously. Although they haven't been used at all, they occupied GPIOs 25, 26 and 27 and this seems to prevent the USB port appearing at runtime.

Thanks a lot to all that helped me.

You mean that you have managed to make this code: Serial.print("Hello") working? Absolutely, I could not make it work; rather, this code works: Serial1.begin(115200, SERIAL_8N1, 3, 1).