PlatformIO Community

Serial monitor always prints null (macOS)

I did review this post https://community.platformio.org/t/serial-monitor-always-print-nul-in-vs-code/16173/11, and I was going to comment on it but then decided against it. It’s an older post, and it seems to have been answered. I didn’t want to hijack that post. Since the solution did not work, I figured it be better to open a new post.

This is the first time using PlatformIO. I have a ESP32-CAM board that I have attached to my MacBookPro. I have no problems building and uploading to the board. However, when I view the serial monitor, all I receive is a run on of “Nul” (‘NUL’ not ‘Null’). I have verified the baud rate. I have tried several other baud rates just for testing purposes. Again, all I receive is ‘Nul’ in the serial monitor.

The strange thing is, as the other post states, it works fine in Arudino IDE. I have tried uploading the program from Arduino IDE and then viewing the serial monitor in PlatoformIO. I receive the NUL. I have tried uploading the program from PlatformIO and then viewing the serial monitor in Arduino IDE with no problem. The serial monitor works perfectly.

Microsoft now has a new extension called “Serial Monitor” Serial Monitor - Visual Studio Marketplace, and I also receive Nul.

I’m wondering if it has something to do with VSCode?

I also tried, as per the other post, moving the pinMode above the Serial.begin, with no effect on the serial monitor. I still receive ‘Nul’.

Any suggestions and or guidance would be greatly appreciated. Thank you!

MacBookPro
Monterey Version 12.6 (I have not updated to 13 due to the Raspberry Pi Pico “Finder” problem)

VSCode
Version: 1.73.1 (Universal)
Commit: 6261075646f055b99068d3688932416f2346dd3b
Date: 2022-11-09T02:08:38.961Z
Electron: 19.0.17
Chromium: 102.0.5005.167
Node.js: 16.14.2
V8: 10.2.154.15-electron.0
OS: Darwin x64 21.6.0
Sandboxed: No

PlatformIO
Core: 6.1.5
Home 3.4.3

Arduino IDE
**Version: 2.0.1
Date: 2022-10-27T13:25:59.041Z
CLI Version: 0.28.0 [06fb1909]

Hardware
ESP32-CAM

platformio.ini

[env:esp32cam]
platform = espressif32
board = esp32cam
framework = arduino
monitor_speed = 115200

main.cpp

/**
 * OnDemandConfigPortal.ino
 * example of running the configPortal AP manually, independantly from the captiveportal
 * trigger pin will start a configPortal AP for 120 seconds then turn it off.
 * 
 */
#include <WiFiManager.h> // https://github.com/tzapu/WiFiManager

// select which pin will trigger the configuration portal when set to LOW
#define TRIGGER_PIN 4

int timeout = 120; // seconds to run for

void setup() {
  WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP  
  // put your setup code here, to run once:
 // Placed pinMode above Serial.begin per previous post
  pinMode(TRIGGER_PIN, INPUT_PULLUP);
  Serial.begin(115200);
  Serial.println("\n Starting");
}

void loop() {
  // is configuration portal requested?
  if ( digitalRead(TRIGGER_PIN) == LOW) {
    WiFiManager wm;    

    //reset settings - for testing
    //wm.resetSettings();
  
    // set configportal timeout
    wm.setConfigPortalTimeout(timeout);

    if (!wm.startConfigPortal("OnDemandAP")) {
      Serial.println("failed to connect and hit timeout");
      delay(3000);
      //reset and try again, or maybe put it to deep sleep
      ESP.restart();
      delay(5000);
    }

    //if you get here you have connected to the WiFi
    Serial.println("connected...yeey :)");

  }

  // put your main code here, to run repeatedly:
}

Update: I decided to try it on my Raspberry Pi 4. I install PlatformIO CLI on the Rasp 4. I connected the ESP32-CAM to the Rasp 4 and ran the command pio device monitor -b 115200. Same thing happens. I get a run on of ‘Nul’. Seem to be something to do with PlatoformIO. Again, I tried again with Arduino IDE and the Arduino IDE serial monitor works perfectly.

Replace the code with the most simple

#include <Arduino.h>
void setup() {
  Serial.begin(115200);
  Serial.println("Start");
}

void loop() {
  Serial.println("Looping");
  delay(1000);
}

Does the issue still occur?

If notyes, does adding the two monitor_... options in here help?

2 Likes

@maxgerhardt First, thank you for taking the time to read my post and responding. I greatly appreciate that! Your solution worked! :slight_smile:

I uploaded the simple loop to the ESP32-CAM and reviewed the serial monitor. I still obtained the run on of ‘Nul’. I then reviewed the post you suggested and that was the solution.

I added the following to the platformio.ini:

monitor_rts = 0
monitor_dtr = 0

I then checked the serial monitor, and it worked!!! :slight_smile:

I did a little further testing, as the post suggested. I tried different combinations. I found that the solution was indeed the RTS. Adding monitor_rts = 0 to the platformio.ini was the sole solution. I then tried uploading the wifimanager (my original code in my post) and the serial monitor worked!

Again, thank you for taking the time to respond and providing me with the solution. I really appreciate it!