Teensy3.5 Serial not working in PlatformIO (on Raspi 4) - same example works from Arduino/Teensyduino

I can compile the Arduino Example “ASCIITable” in PlatformIO on the Raspi 4 with no errors. However, when the program runs there is no output in the Serial monitor (which is opening ttyACM0). I can see the Teensy as ttyACM0 when it is plugged into the USB port when I do a “ls /dev/tty*”.
If I plug the Teensy into my Win10 computer, it shows up as COM25 but there is no serial output here either.
Compiling the same example program in Arduino 1.8.13/Teensyduino 1.54 Beta 7, on the Raspi 4, it works fine.
Compiling the same example program in PlatformIO (or Arduino) on my PC, it also works fine.
In PlatformIO,on the Raspi 4, if I add a few lines to blink the LED as it is looping &sending out ASCII characters, the LED is flashing indicating that the program is executing the loop properly- it’s just not sending any serial output.
I am new to using PlatformIO. I was thinking it would be good to use on Raspi 4 for both the Teensy and ESP32 MCUs that I commonly use.
Any one have any ideas?
Many thanks

On both my PC, and the Raspi 4, the PlatformIO core is 5.1.1

I’ve recently observed that multiple Arudino cores have changed their USB serial code to only send data when the DTR line is asserted.

Does it serial output appear in PlatformIO’s monitor program when you add

monitor_dtr = 1

to the platformio.ini?

Thanks for the rapid response, Max. Unfortunately, adding this line to the platformIO.ini did not change anything. Actually, I have never run across any instances where DTR handshake was needed to send data via a USB CDC serial port- using any of the Teensy devices.

I had added “build_flags= -D USB_SERIAL” to the ini file- just to be sure, although they say that the Teensy 3.x USB SERIAL firmware is loaded by default.
The fact that it works when I compile it under PIO on my PC is strange. However, if I try to program it on my PC, after having programmed it on the Raspi using PIO, it won’t download the code unless I push the Teensy Boot button, which, in itself, indicates something is wrong with the code that Raspi 4 PIO has loaded.
Thanks

Okay sorry, do I understand you correctly that you have a single PlatformIO project that, when compiled and uploaded on your PC, works fine (sends serial output when connected to both PC and Raspberry Pi), but when compiled on the Pi itself, it won’t work?

What’s the exact platformio.ini and code?

Hi Max: Yes, that was it exactly.
However, I figured out what was going wrong- nothing to do with the Serial port itself. I am totally new to PIO- I am happy/well experienced using Visual Studio/Visual Micro add in for Arduino on the PC but hadn’t tried PIO on PC.I was curious to try it on the RasPi.
My first test was the simple LED blink program that worked fine. Then I used the Arduino Import function to load in the ASCIItext example, which tests the Serial function. Both of these programs are in the same (only) workspace that I have.
My problem is that when I open up the folder containing the ASCIItext example and choose the ino file in the src folder, when I do a build, it just compiles the earlier blink program. The build messages scroll by pretty quickly in the terminal window, so I did not notice that I was really compiling the earlier example that I had tried out.
I don’t understand the Workspace idea in PIO. I haven’t been able to figure out how to make the INO file that I have currently open in the active tab, be the one that gets built. On the forum, there is a thread where some one else asks this question. The answer is that whatever code is open in the active tab is the one that gets built.
It doesn’t work that way for me. I have the ASCIItext.ino open (and has a blue icon to the left of it). However, PIO is still building the earlier Blink program.
I completely re-installed PIO and tried again- this time starting with the ASCIItext. program. Now this program is what gets built and Serial port works fine. Adding the blink program next, and selecting its ino file in the active tab, I see a blue icon next to it in both the code edit tab and in the Explorer window.(I am not sure what the blue icon signifies) But it is still building the earlier-loaded ASCIItext program.
On my PC,PIO does the same thing- it only builds the first project that I loaded ( I was not using PIO on the PC- I just loaded it for comparisions sake when I had this problem on the RasPi.)
I am at a loss. I could upload a screen dump of this, if it would help, or at least make my claim credible.
I have run into the same problem when I tried STM32cubeIDE. I could never figure out what was actually being built when I had a specific program loaded in the edit window. I must be missing something basically different from what I am used to with the many other compilers I’ve used.
Thanks

At the time of writing that was correct. It has been changed since the last major extension version due to a multitude of people reporting that that wasn’t working for them. The documentation reflects that, too, but sadly there’s still that older info around. There’s still discussion in Having to separately select a default to compile and upload since v2.3.0 · Issue #2410 · platformio/platformio-vscode-ide · GitHub and Automatically switch to newly created project's environment · Issue #2414 · platformio/platformio-vscode-ide · GitHub to improve that behavior.

Thanks so much, Max. Looking at your documentation link, I see the environment switching menu item on the bottom. I had noticed it before, but 1) both projects had almost identical assigned names based upon time /date so I didn’t notice the discrepancy and 2) I never would have expected that the environment would remain on the old one when a new project was loaded. You also expressed a similar opinion in one of the threads that you gave me.
I see no way to rename these project folders after they have been created with the “date-time-MCU type” name. It is not usable if that is the only way it can be done. Probably I was given a choice to define my own name while importing it, but I don’t recall being asked for a project name. I need to look into this as well as examine the threads you gave me.
Again, thanks so much for your time/expertise. I expect that there will be lots of differences in PIO than what I am used to on the other IDEs that I routinely use.

When doing an “Import from Arduino code” there is indeed no name option, only when creating a new project. That is tracked in https://github.com/platformio/platformio-vscode-ide/issues/2306.

However, one can remove the folder from the workspace (no file deletion), then rename the project folder in C:\Users\<user>\Documents\PlatformIO\Projects, and then open the project from the new path again.

However I’d advise in this case to simply always create a new project with the desired board and framework, and copy-paste the code file in a main.ino, and then start working on the .cpp conversion from there, if any is needed.

Indeed, this feature was already requested by me but currently has a bug in the implementation. This is tracked in Automatically switch to newly created project's environment · Issue #2414 · platformio/platformio-vscode-ide · GitHub.

Hi Max:
Thanks for the tips. Looks like the Import Arduino function is not very well implemented if it won’t allow you to name the project directly.
I started my PIO checkout with Arduino examples since they are simple and should work- plus they don’t have many dependencies or functions that have to be declared at the start of program. I will be interested to see if I can get some of my complex Teensy/ESP32 programs with many external libraries working under PIO on the Raspi. I’ve tried a few using the arduino IDE, and they compiled fine once I migrated the custom libraries over to the Raspi’s Arduino folder.
You have been very helpful. I’m new to this forum, but the Teensy forum is very active as well.