Serial monitor not working correctly

I am a SW newbie. I’ve recently made the jump from Arduinio IDE to Vs and PlatformIO. I can’t seem to get the serial monitor to work. In the .ini, “monitor=115200”. I also have in setup "serial.begin(115200). The compile and upload execute and display correctly, and for some reason upload switches to a baud rate over 400K. After, the serial monitor prints out a few things, and then garbage that looks like the wrong baud rate. The serial monitor works fine in Arduino. Any hints?

— Terminal on COM5 | 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 Redirecting...
— Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H
e�v�%�␘���D(��Q���׌Qj␕Qr�,␕���␃��y�␝B����C�)S�D�bTf�4�,Q�PiPNӠ�␌/h�␘␗␓�U{5�C␔��G�P�ʢ␋�PT���ֱ�pEӨ␎��k��␄�␘�O6E(j����
x�!����␘���

This must be

monitor_speed = 115200

Let us know more details like the platform used, the board used etc. by showing your complete platformio.ini

Yes, I am sorry, that is what I meant.

This is what you need?

[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
lib_extra_dirs = ~/Documents/Arduino/libraries
monitor_speed = 115200

FYI, this was working code on Arduino…These are just debug serial messages.

The platdormio.ino looks correct, except for the lib_deps. But that’s a different topic.

COM5 is the correct port?
Your sketch does have Serial.begin(115200); ?(please doublecheck!)

Yes, Absolutely. I had it running at 500kbaud on the Arduino IDE. This was all working fine on Arduino, so I am moving a working project to PlatformIO. It compiles, it uploads, and shows everything on the serial monitor, except for the serial output. It did work once, but not for long. It has me stumped.

Can you post a screenshot of your ArduinoIDE setting where this project works?

You should remove this!

In PlatformIO, libraries are installed per project for a good reason: reproducibility.

You can specify the exact version number of the library to be used per project.

Imagine you have two projects that use ArduinoJson. Project A requires ArduinoJson 5.1 and Project B requires ArduinoJson 7.2!

If you use a “global installed” version of ArduinoJson you can either build Project A or Project B, but not both!

This can be easily solved with PlatformIO in the platformio.ini

Project A:

lib_deps = blanchon/ArduinoJson @ ^5.1.0

Project B:

lib_deps = bblanchon/ArduinoJson @ ^7.2.0

Sorry for the reply delay. I see your point on the libraries. A blanket Arduino/Libraries also seems to really, really, slow down compilation. I did another open sourced project (Onstep) which required specific library versions. The concept is now gelled in my head!

As for serial, the monitor seems to still have problems, now it just doesn’t show up at all. I think there is some sort of conflict. When I shut down PlatformIO, and bring up Arduino, the serial monitor works fine. I need to do more work in that area.
Thanks for the library tip!
Bob

I want to update my reply:
I just added a few libraries via the “lib dependency” route. The program compiles, and those dependencies are in the .pio\libdeps folder, but they are not in the platformio.ini file. In the picture below, I added the dependencies in the .ini file, and no change, it still compiles fine. I also tried to add a lib_extra_dirs to point to a “modified” NTPClient.h (contains a “date” function), but I just can’t that to work. It can’t find the file. Any pointers?

If you have a modified version of the NTPClient in library, don’t include it in the lib_deps expression in the platformio.ini. Remove it from there. When building, PlatformIO will look into the lib/ folder and find your modified library.

(Also delete the .pio folder of the project after removing it from lib_deps so that the old library is definitely gone).

That was part of the problem. You can see my modified NTPClient in my library, but when compiling, it could not find the file. I made sure the “extra” function was not called, and just installed the regular NTPClient.