Serial Monitor always print 'NUL' in VS Code

Hey everyone!

I migrated from Arduino IDE to VS Code with PlatformIO, and have problem with Serial Monitor. Serial Monitor always prints ‘NUL’. Can someone help me ?

I’m using ESP01 with 1mb memory

platformio.ini
Screenshot 2020-09-24 at 20.53.14

code:

#include "Arduino.h"

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

void loop()
{
  digitalWrite(LED_BUILTIN, HIGH);
  delay(500);
  digitalWrite(LED_BUILTIN, LOW);
  delay(500);
  Serial.print("Hello !");
}
1 Like

It always print ‘NUL’ even if in code no ‘Serial.print’

1 Like
  1. On reset, the ESP8266 will print bootloader messages at 74880 baud. Since you have set the monitor to 115200 baud, the USB-UART adapter cannot correctly the UART TX signal and prints the wrong data. What is being output at minotor_speed = 74880? I suspect your ESP just can’t boot.
  2. I see that you’re using a Mac by that /dev/cu.usbserial* device name. Serial drivers for like CH340 chips are known to be very buggy / needing the exact right kernel driver. See Troubleshooting CH340G issues on macOS. If no sensible output is shown on any baud rate, a driver issue may be fault.
  1. minotor_speed = 74880 - Nothing change
  2. upload_speed = 460800 - didn’t help. Also, I didn’t found chip CH340 on my adapter
  3. if I upload code via Arduino IDE everything works fine. I use ESP Link v1.0 adapter
  4. I thing when I upload code via VS Code, it’s also working because led on my esp01 blinking
    correctly I mean every 500milisec (I tried other value for milisec). Something wron with Serial

Yeah that one has a good CP2104 usb-serial chip on it with which I haven’t seen any problems reports with MacOS so far. With the CH340 though… a lot.

You can try and follow the above links to make sure you have the correct drivers installed for your Mac. The solution also depends on what Mac os you are running, as I remember that the vendor-drivers needed to be used for older Mac OS versions, but the built-in ones for higher Mac OS versions.

I looked into all my drivers and everything looks good. I have the latest version of MacOS Catalina 10.15.6

Well if usbserial.kext is really not loaded and the MacOS AppleUSBCHCOM.kext is, your problem is unknown to us. Apple support forums might help you?

Did the module work when using the Arduino IDE? Do you still have the Arduino IDE installed? If so try:

  • Build and upload the firmware from the Arduino IDE and then try the serial monitor in PlatformIO
  • Build and upload the firmware in PlatformIO and then try the serial monitor in the Arduino IDE

Which combinations work?

Yes, the module works when I’m using Arduino IDE.

The first combination works. (firmware from the Arduino IDE and then try the serial monitor in PlatformIO)

The cause of the problem is quite unexpected: it’s a conflict between the LED and the Serial output. The LED is on pin 2, so is the serial’s TX.

In PlatformIO, the LED_BUILTIN is correctly defined as 2. So your code outputs 1 Hz square wave instead of a TX signal. The LED will have worked.

In the Arduino IDE, you probably have something else selected as the LED pin or the selected board has a different selection. So the serial output was working, but probably the LED wasn’t.

Just put pinMode before Serial.begin and should be work!

{
  pinMode(LED_BUILTIN, OUTPUT);
  Serial.begin(115200);
}
1 Like

Tnx
Its work !!!.
same problem solved with this Answer.