Hi all, I'm working on a project that uses an ESP32 feather as a devboard. In the process of just getting everything setup I was trying to run a simple blink sketch with some Serial prints just to check everything was working. It does not work.
The behavior is this:
I plug my esp32 into my Windows laptop (running W11). It gets recognized as COM8. I am able to upload my sketch to the board and it runs correctly. When I open the serial monitor, it seems to connect but nothing is printed.
Using a Mac laptop running IDE v1.8.16, I uploaded THE EXACT SAME sketch. It runs it correctly and on the Mac if I open the serial monitor, the output can be seen. Now where it gets strange is that if I take the board after it's been flashed by the Mac and plug it into my laptop I'm able to see the Serial monitor output under COM5 (this is plugged into the same port that was previously COM8 with the same cable). If I try to flash the board from this COM5 port, I get this error:
A fatal error occurred: Could not open COM5, the port doesn't exist
Failed uploading: uploading error: exit status 2
Hitting the reset button restarts the code and the COM port remains 5. Putting the board into bootloader mode manually by hitting Boot and Reset buttons puts the board onto COM port 8 and I'm no longer able to see the Serial monitor output, but can now upload code.
// the setup function runs once when you press reset or power the board
void setup() {
// initialize built in LED pin as an output.
pinMode(LED_BUILTIN, OUTPUT);
// initialize USB serial converter so we have a port created
Serial.begin();
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
Serial.write("LED ON");
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
Serial.write("LED OFF");
delay(1000); // wait for a second
}
yes, I know there is no Baud rate. It defaults to 9600.
Thank you in advance for your help
@ptillisch , I've seen you solve a lot of issues like this. Please save me I can generate logs for you if you'd like.
Several of Adafruit's bootloaders switch COM port numbers between loading and program execution. Usually the serial monitor is informed of the switch, but can get out of sync with the IDE and the board. See this thread: https://forums.adafruit.com/viewtopic.php?t=211026
Is there a way to manually select the new COM port? I upload to COM8 and after the upload I hit the reset button twice to try and get the IDE to see the new COM port where the Serial output is being sent but it remains at COM8 and that is the only available port. Looking in device manager the only visible COM port is port 8. I'm not really sure how to get to this new COM port that it switches to for Serial output.
I don't know how the COM ports are assigned. Once automatically assigned (evidently upon first connection), they seem to be permanently associated with the Feather module in question.
I suspect that a unique serial number is involved. The Adafruit people would know.
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 disable the use of their USB CDC serial port in the sketch by default.
That default disabled configuration is appropriate when your sketch doesn't use the serial port, but in cases where you do need it (such as when your sketch calls Serial.println, etc.), 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:
Select Tools > USB CDC On Boot > Enabled from the Arduino IDE menus.
Upload the 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.
You probably already had the "USB CDC On Boot" menu set to "Enabled" on the other computer. This configuration is made to the board itself when you upload a sketch, rather than being a configuration of the Arduino IDE application, so it is expected that the behavior transfers from one computer to another.