Linux VSCode Platformio NodeMCU12e Serial doesnt seem to work

The below code works when compiled under the Arduino IDE but spits gibberish (once) when compiled under Platformio. It uploads fine. What did I do wrong, or what did I miss? I should mention the board is a clone (LoLin) with the CH340 Usb to serial IC

#include <Arduino.h>
void setup() {
void loop() {
  Serial.println("Hello World!\n");

…My Platformio.ini contains…


platform = espressif8266
board = nodemcuv2
framework = arduino

monitor_port = /dev/ttyUSB0
monitor_speed = 9600
monitor_rts = 0
monitor_dtr = 0

Why add this explicitly?

Yes, absolutely expected. The ESP8266 runs a bootloader at a different baud rate (74880) that outputs some messages before booting into your main firmware (Strange output on serial port when reset ESP · Issue #3047 · esp8266/Arduino · GitHub). When the serial monitor is set to receive characters at 9600 symbols per second (baud) but the board sends at 74880 baud, the intepreted received content will be wrong (garbage).

You can easily see the proper messages by chainging Serial.begin() to 74880 and also monitor_speed. Then execute the “Upload and Monitor” project task in VSCode as normal.

When you’re using 9600 baud, just print like two newlines after Serial.begin().

And actually, in the Arduino IDE, you should see that too, if you press the reset button on the board after the firmware has started up. Maybe it supresses it on the first boot so that users don’t think something is broken. But there is nothing broken.

It was added explicitly because I was seeing if it made any difference. Anyway, the problem was the dumbest ever rookie mistake. I didnt realize there was a main.cpp in the src directory of the project folder. I created one in the root of the project folder. So i spent about 4 times uploading a blank sketch :smiley: Anyway it works now.

Ohhh okay then you only see the garbled monitor output and none of your output. I just assumed you were wondering about the garbled output before your output. Went overboard there :smiley: