Serial Monitor Working Very Intermittently -- only on PlatformIO though

Hi All, I’m having some difficulties trying to figure out why I’m having such intermittent issues with the serial monitor inside the VSCode version of Platformio. I am using the Arduino Nano ESP32 board as well.

I have a sketch that works perfectly in the newer Arduino IDE. However, when I have the exact same code in a platformio project with Arduino framework, I get very hit or miss serial monitor behavior. I made sure monitor_speed = 9600 in my ini file and I’ve also checked the baudrate is set to 9600 in my code.

Every time I hard reset my nano esp32, the same exact expected text will read properly in the Arduino IDE, always. But when I try the same thing in platformio, nothing at all prints in the serial monitor. But then it will very randomly. I have no idea what’s happening. I’m always holding down the reset button for a quarter second at least to make sure debouncing isn’t an issue.

I’m a little lost for words right now. Any help is appreciated.

Did you choose the correct COM port (bottom status bar)?

Since the ESP’s boot message is printed at 115200 I suggest to change the baudrate of your sketch and platformio.ini to 115200 as well.

Yes, I made sure to check the same COM port was used throughout. I had the correct COM port chosen in both the Arduino IDE and PlatformIO, double checked as well. I tried baud rate = 115200 and still have the same issue. I tried a putty terminal using both 9600 and 115200 serial baud rates, and was able to see all my serial messages show up on the serial monitors.

I feel like it has something to do with the COM port software in platformio given that I have no problems in Arduino/putty terminals. What would you recommend to check out?

At the moment I have no concrete idea, except that another terminal program may be blocking the COM port (ArduinoIDE / Putty).

What is the complete output when you open the Serial Monitor? Can you post a screenshot?

Hi @sivar2311 Please see screenshots below. I do not believe it is ArduinoIDE or Putty as I am able to switch between the two programs and see it on both programs. Plus closing the application closes the COM port as well.

What’s getting weird now is that I’m getting the correct messages when I flash my board (Arduino nano esp32) and then immediately open the COM port I get the expected messages:

However, when I press the reset button and leave COM port open, it never sees anything. But when I’m on Arduino and hit reset over and over with the COM port open, I get the expected repeated strings. It just repeats “Verified inside setup…” and “Card Mount Failed” as it should.

Do you know why this would be? Is the platform-io COM port always open and sniffing Rx UART line, or does hitting reset on the Arduino while the COM port is open anything?

The monitor stays open until you close the monitor task (right side on your screenshot). Usually it is closed automatically when you upload a new sketch.

You can close the monitor manually by clicking on the trashbin icon:
image

What I noticed:
Your’s is started by the command:
Executing task in folder MicroSD_nanoESP32_Example: C:\Users\zachDev\.platformio\penv\Scripts\platformio.exe device monitor --port COM6

Whereby my terminal is started by the command
Executing task: C:\Users\boris\.platformio\penv\Scripts\platformio.exe device monitor --environment esp32-s3-devkitc1-n16r8 --port COM20

Do you have VS-Code open with multiple project folders?

Hi Sivar, yes I have my project open in VScode. I do have one other project opened. Why do you ask?

Please open only a single project in VS Code and try again.

image

Make sure that the correct environment is selected (bottom status bar).

image

I noticed that PlatformIO quickly gets confused if several project folders are open in VS Code.

Sivar, I’ve already verified this. Not sure where else to look to be honest.

I have to admit, I’m also running out of ideas.

Please check your PlatformIO version:

  • Open a terminal (PlatformIO icon in the left sidebar / Miscellaneous / New Terminal).
  • Enter pio --version

If the version is lower than 6.1.13 perform an update:

  • pio upgrade

Hi Sivar, just ran that command line tool and it looks like I’m all upgraded and on 6.1.13 already. Darn, well thank you for your help. Not sure where to go from here.

have you had any other fishy things with any body using Arduino Nano ESP32’s in relation to COM ports failing?

Have you tried to add this to platformio.ini ?

monitor_rts = 0
monitor_dtr = 0
2 Likes

Thank you! I was having the same problem on Linux even though I had the correct monitor speed and permission/user. It was not at all obvious that the problem was flow control! Turning off rts and dtr solves the problem. Something else for the FAQ, perhaps?

What was confusing was that idf.py monitor worked just fine, but the monitor button in platformio just displayed:

 *  Executing task: platformio device monitor 

--- Terminal on /dev/ttyUSB1 | 115200 8-N-1
--- Available filters and text transformations: colorize, debug, default, direct, esp32_exception_decoder, hexlify, log2file, nocontrol, printable, send_on_enter, time
--- More details at https://bit.ly/pio-monitor-filters
--- Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H
 *  Terminal will be reused by tasks, press any key to close it.

After adding monitor_rts = 0 and monitor_dtr = 0 to platformio, the expected output appears in the monitor:

 *  Executing task: platformio device monitor 

--- forcing DTR inactive
--- forcing RTS inactive
--- Terminal on /dev/ttyUSB1 | 115200 8-N-1
--- Available filters and text transformations: colorize, debug, default, direct, esp32_exception_decoder, hexlify, log2file, nocontrol, printable, send_on_enter, time
--- More details at https://bit.ly/pio-monitor-filters
--- Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H
ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0x1 (POWERON),boot:0x8 (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fce3818,len:0x1750
load:0x403c9700,len:0x4
load:0x403c9704,len:0xc00
load:0x403cc700,len:0x2e04
entry 0x403c9908
␛[0;32mI (27) boot: ESP-IDF 5.1.2 2nd stage bootloader␛[0m
␛[0;32mI (27) boot: compile time Feb 25 2024 14:33:15␛[0m
␛[0;32mI (27) boot: Multicore bootloader␛[0m
␛[0;32mI (30) boot: chip revision: v0.1␛[0m
␛[0;32mI (34) boot.esp32s3: Boot SPI Speed : 80MHz␛[0m
␛[0;32mI (38) boot.esp32s3: SPI Mode       : DIO␛[0m
␛[0;32mI (43) boot.esp32s3: SPI Flash Size : 8MB␛[0m
␛[0;32mI (48) boot: Enabling RNG early entropy source...␛[0m
␛[0;32mI (53) boot: Partition Table:␛[0m
␛[0;32mI (57) boot: ## Label            Usage          Type ST Offset   Length␛[0m
␛[0;32mI (64) boot:  0 nvs              WiFi data        01 02 00009000 00006000␛[0m
␛[0;32mI (72) boot:  1 phy_init         RF data          01 01 0000f000 00001000␛[0m
␛[0;32mI (79) boot:  2 factory          factory app      00 00 00010000 00100000␛[0m
␛[0;32mI (87) boot: End of partition table␛[0m
␛[0;32mI (91) esp_image: segment 0: paddr=00010020 vaddr=3c080020 size=1fa90h (129680) map␛[0m
␛[0;32mI (122) esp_image: segment 1: paddr=0002fab8 vaddr=3fc96e00 size=00560h (  1376) load␛[0m
␛[0;32mI (123) esp_image: segment 2: paddr=00030020 vaddr=42000020 size=7e18ch (516492) map␛[0m
␛[0;32mI (221) esp_image: segment 3: paddr=000ae1b4 vaddr=3fc97360 size=03fb4h ( 16308) load␛[0m
␛[0;32mI (225) esp_image: segment 4: paddr=000b2170 vaddr=40374000 size=12dc8h ( 77256) load␛[0m
␛[0;32mI (252) boot: Loaded app from partition at offset 0x10000␛[0m
␛[0;32mI (252) boot: Disabling RNG early entropy source...␛[0m
␛[0;32mI (263) cpu_start: Multicore app␛[0m
␛[0;32mI (263) cpu_start: Pro cpu up.␛[0m
␛[0;32mI (264) cpu_start: Starting app cpu, entry point is 0x40375438␛[0m
␛[0;32mI (0) cpu_start: App cpu up.␛[0m
␛[0;32mI (282) cpu_start: Pro cpu start user code␛[0m
␛[0;32mI (282) cpu_start: cpu freq: 160000000 Hz␛[0m
␛[0;32mI (282) cpu_start: Application information:␛[0m
␛[0;32mI (285) cpu_start: Project name:     espidf-get-started␛[0m
␛[0;32mI (291) cpu_start: App version:      1␛[0m
␛[0;32mI (295) cpu_start: Compile time:     Feb 25 2024 14:33:03␛[0m
␛[0;32mI (301) cpu_start: ELF file SHA256:  1accd5d8ae0d8869...␛[0m
␛[0;32mI (307) cpu_start: ESP-IDF:          5.1.2␛[0m
␛[0;32mI (312) cpu_start: Min chip rev:     v0.0␛[0m
␛[0;32mI (317) cpu_start: Max chip rev:     v0.99 ␛[0m
␛[0;32mI (321) cpu_start: Chip rev:         v0.1␛[0m
␛[0;32mI (326) heap_init: Initializing. RAM available for dynamic allocation:␛[0m
␛[0;32mI (334) heap_init: At 3FC9EC68 len 0004AAA8 (298 KiB): DRAM␛[0m
␛[0;32mI (340) heap_init: At 3FCE9710 len 00005724 (21 KiB): STACK/DRAM␛[0m
␛[0;32mI (346) heap_init: At 3FCF0000 len 00008000 (32 KiB): DRAM␛[0m
␛[0;32mI (352) heap_init: At 600FE010 len 00001FD8 (7 KiB): RTCRAM␛[0m
␛[0;32mI (360) spi_flash: detected chip: gd␛[0m
␛[0;32mI (363) spi_flash: flash io: dio␛[0m
␛[0;33mW (367) spi_flash: Detected size(16384k) larger than the size in the binary image header(8192k). Using the size in the binary image header.␛[0m
␛[0;32mI (380) sleep: Configure to isolate all GPIO pins in sleep state␛[0m
␛[0;32mI (387) sleep: Enable automatic switching of GPIO sleep configuration␛[0m
␛[0;32mI (394) app_start: Starting scheduler on CPU0␛[0m
␛[0;32mI (399) app_start: Starting scheduler on CPU1␛[0m
␛[0;32mI (399) main_task: Started on CPU0␛[0m
␛[0;32mI (409) main_task: Calling app_main()␛[0m
␛[0;32mI (429) wifi softAP: ESP_WIFI_MODE_AP␛[0m
␛[0;32mI (429) pp: pp rom version: e7ae62f␛[0m
␛[0;32mI (429) net80211: net80211 rom version: e7ae62f␛[0m
I (439) wifi:wifi driver task: 3fca8da0, prio:23, stack:6656, core=0
I (449) wifi:wifi firmware version: 91b9630
I (449) wifi:wifi certification version: v7.0
I (449) wifi:config NVS flash: enabled
I (449) wifi:config nano formating: disabled
I (459) wifi:Init data frame dynamic rx buffer num: 32
I (459) wifi:Init static rx mgmt buffer num: 5
I (459) wifi:Init management short buffer num: 32
I (469) wifi:Init dynamic tx buffer num: 32
I (469) wifi:Init static tx FG buffer num: 2
I (479) wifi:Init static rx buffer size: 1600
I (479) wifi:Init static rx buffer num: 10
I (479) wifi:Init dynamic rx buffer num: 32
␛[0;32mI (489) wifi_init: rx ba win: 6␛[0m
␛[0;32mI (489) wifi_init: tcpip mbox: 32␛[0m
␛[0;32mI (499) wifi_init: udp mbox: 6␛[0m
␛[0;32mI (499) wifi_init: tcp mbox: 6␛[0m
␛[0;32mI (499) wifi_init: tcp tx win: 5744␛[0m
␛[0;32mI (509) wifi_init: tcp rx win: 5744␛[0m
␛[0;32mI (509) wifi_init: tcp mss: 1440␛[0m
␛[0;32mI (519) wifi_init: WiFi IRAM OP enabled␛[0m
␛[0;32mI (519) wifi_init: WiFi RX IRAM OP enabled␛[0m
␛[0;32mI (529) phy_init: phy_version 620,ec7ec30,Sep  5 2023,13:49:13␛[0m
I (569) wifi:mode : softAP (f4:12:fa:e2:4f:11)
I (569) wifi:Total power save buffer number: 16
I (569) wifi:Init max length of beacon: 752/752
I (569) wifi:Init max length of beacon: 752/752
␛[0;32mI (569) wifi softAP: wifi_init_softap finished. SSID:mywifissid password:mywifipass channel:1␛[0m
␛[0;32mI (579) esp_netif_lwip: DHCP server started on interface WIFI_AP_DEF with IP: 192.168.4.1␛[0m
␛[0;32mI (589) main_task: Returned from app_main()␛[0m
1 Like