Serial Monitor wont Work (Arduino Uno)

So I am a teacher and not an expert in this. I am programming arduino’s with students and im trying to use VScode over the arduino IDE.

I have been sitting for 2 hours trying to get the dang serial monitor to work.

Board: Arduino R3
Baud Rate: 9600

Serial Monitor Screen:

Ini file:

[env:uno]
platform = atmelavr
board = uno
framework = arduino
monitor_speed = 9600
monitor_rts = 0
monitor_dtr = 0

I would love some help, im so exhausted and I havent even been able to build my project. Also I notice when I open and run the serial monitor seems to be set on something higher than 9600 which I usually use in Arduino IDE.

I have had errors saying the port was denied which resolved as well. I can see my arduino in the device manager. Before this I wasnt seeing anything in the serial field.

You’re using “Serial Monitor”, a VS Code Plugin.

That’s not the serial monitor which comes with PlatformIO!
While you’re having “Serial Monitor” (VS Code Plugin) runing, the COM port is blocked and not available to PlatformIO (eg for uploading your sketch).

Therefore, I suspect that there is another sketch running on the UNO that uses a different baud rate.

Close the “Serial Monitor” (VS Code Plugin)

The monitor settings from platformio.ini only applies to PIO’s builtin serial monitor.
Usually monitor_rts and monitor_dtr are not required and should only be used if necessary. Please remove them for now.

Your platformio.ini should look like this:

[env:uno]
platform = atmelavr
board = uno
framework = arduino
monitor_speed = 9600

You have more than one project open in current VS Code Workspace.

Make sure the correct project is selected in the Project Environment Switcher in PlatformIO’s bottom bar.

Click the Upload & Monitor button to build, upload and monitor your sketch (see screenshot below).

PlatformIO bottom bar:

hmm, it seems I dont have the upload and monitor button. It seems that putting Serial.begin(9600) in my setup instead of loop did the trick. Is this normal behavior? Not sure but doest the arduino sometimes gives junk data on startup, so looping a serial.begin() in a loop was no good?

Interesting! Its now working.

That’s okay. I modified my PlatformIO a while ago. It may not be included by default. Use the upload and monitor buttons one after the other.

Oh, I missed that - it’s probably still too early here (5:15 AM) and my eyes weren’t quite open yet :wink:

No, that’s not good.
This belongs into setup.

Adding a small delay in your setup() should fix this:

void setup() {
  Serial.begin(9600);
  delay(2000); // wait 2 seconds
  Serial.println("Hello World");
}

By the way: You’re not fixed to 9600 baud.
If you want to use higher baud rate simply change it in Serial.begin() and platformio.ini.

main.cpp:

#include <Arduino.h>

void setup() {
  Serial.begin(115200);
  delay(2000); // wait 2 seconds
  Serial.println("Hello World");
}

void loop() {}

platformio.ini:

[env:uno]
platform = atmelavr
board = uno
framework = arduino
monitor_speed = 115200