Serial Printing at startup?

This is my first XIAO device, I have used many psuedo arduino’s. I am trying to sort out how to Serial print during startup.

In all other boards I have used I would simply do this in startup, doesn’t seem to work here.

void setup() {
Serial.begin(9600);
while (!Serial) {}
Serial.println(“Foo”);
}

If loop does no printing?

Maybe XIAO_ESP32C3 needs this.

  Serial.begin(115200);
  Serial.setTxTimeoutMs(0); //for Serial.print();

Doesn’t print anything now:
void setup() {
Serial.begin(115200);
Serial.setTxTimeoutMs(0); //for Serial.print(); //while (!Serial) {;}
Serial.println(“Foo”);
}

void loop() {
// put your main code here, to run repeatedly:
Serial.println(“Bar”);
}

and after three attempts I get:
esptool.py v4.2.1
Serial port COM13
Connecting…
Chip is ESP32-C3 (revision 4)
Features: Wi-Fi
Crystal is 40MHz
XX…
Uploading stub…
Running stub…
Stub running…
Changing baud rate to 921600

A fatal error occurred: No serial data received.
A fatal error occurred: No serial data received.

I think it’s time to return this item.

I was in exactly the same situation as you. The following is the result of my trial and error.

  1. If can’t flash, press “boot”, then connect to USB, and then flash.
  2. After flashing, be sure to press “reset” and then open the serial monitor.

I have written several sketches for XIAO_ESP32C3, and in the past I have encountered this situation with simple sketches like blink. However, in most other sketches, I never have to press “reset” or “boot” and have not experienced any inconvenience. I am not sure why.

I assume you mean hold down the boot button until after the usb is inserted?

I have to do this every time?

Is there a minimum script, set of things to do that will make this go away? I can’t be doing this while I am trying to sort out how to get a new concept to work?

And it doesn’t seem to want to print from startup?

I assume you mean hold down the boot button until after the usb is inserted?

Yes

I have to do this every time?

If you’re unlucky

I don’t encounter this situation most of the time, so I don’t find it too inconvenient. It has been discussed in other forums as a problem specific to ESP32C3, but I have not followed it in detail.

I found that the following works every time I tried it at least.

void setup() {
Serial.begin(115200);
Serial.setTxTimeoutMs(0); //for Serial.print(); //while (!Serial) {;}
while (!Serial) {;}
delay(1000); // lower to 100 and doesn’t work
Serial.println(“Foo”);
}

void loop() {
Serial.println(“Bar”); // With nothing here it doesn’t work;
//At this point, not sure what the minimum is here but I assume everyone has something in the loop anyway.
}