Enable uart via usb for pi pico using platformio

TL;DR: how can I enable serial via usb on the raspberry pi pico using platformio?

Using CLion + platformio plugin on Arch Linux.

I was working on a project with 240 individually addressable LEDs and a rotary encoder; the arduino nano was not fast enough to handle both, as it misses encoder movements/interrupts when FastLED lib is flushing the LED effects.

In an attempt to get a faster mcu, I bought a raspberry pi pico, thinking I could handle the encoder and leds in each of its individual separate cores, but boy, is this board user UN-friendly!!!

There’s a big chapter about me simply trying to figure out how to upload code via platformio since this mcu does not present a serial interface when plugged in, but skipping to my current issue, after the blink example is working.

I see several tutorials explaining how to enable serial over USB which should be as simple as adding a pico_enable_stdio_usb command to the CMakeLists.txt file, except that with platformio.ini I do not have such file, so I was wondering what other options I have.

Option 1: drop arduino framework and platformio and use the CMakeLists.txt (will need to find an alternative for FastLED and other libs as well as rewrite existing code)

Option 2: drop pi pico and look for another faster (multi-core?) board compatible with arduino and platformio without the pico shenanigans, which should allow me to keep my current development stack.

Option 3: (which is why I am here), find a way to use the arduino framework, FastLED and platformio (since my code is already written using it) and still enable serial over usb without the CMakeLists.txt.

I swear I did try to google a way to do this, but it looks like I am doing something that hasn’t been attempted or at least hasn’t been documented online before. Is it possible to enable the serial interface of the raspberry pi pico in such a way that existing code with Serial.print* will still work as intended?

current platformio.ini:

framework = arduino
;lib_deps =
;	fastled/FastLED
;	contrem/arduino-timer
;	mathertel/OneButton

platform = raspberrypi
board = pico
upload_port = /dev/ttyACM0

Thank you for your time.
Best regards.

You’re working with Arduino. That has the Serial USB capability build in as its default Serial object. Is the most minimal

#inlcude <Arduino.h>
void setup() { Serial.begin(115200); }
void loop() { }

not creating a serial port for you after upload?

Is it really that simple? Then there must be something else wrong with my setup.

There is a /dev/ttyACM0 port which is always there, but when I plug the Arduino UNO, it shows a new /dev/ttyUSB0 port.

After reading through this issue I added the upload_port = /dev/ttyACM0 to platformio.ini and it worked to upload, even though that port is always there even when the pico is not connected. But it does not seem to work for pio device monitor -e pico -b 115200 -p /dev/ttyACM0

If the very first firmware fails to upload, you should manually put the Pi Pico into bootloader mode by plugging it out again, holding to the BOOTSEL button on the board, and then plugging the USB back in (while the button is still being held). A few seconds after it was plugged in, you can let go of the button again. Then a USB drive should show up. Copy paste the .pio/build/pico/firmware.uf2 file on that new USB drive. The Pico should reboot and give you a serial port with hopefully the wanted output when it’s being monitored.

I can’t believe it was really this simple.

echo /dev/tty{ACM,USB}*
/dev/ttyACM0 /dev/ttyACM1

I copied the UF2 file to the mounted drive as you suggested and I can now see a 2nd ttyACM port…

Thank you!!!

Upload should now work seamlessly without you having to reboot to bootloader mode manually. (If it picks the wrong upload port, you might need to help it a tiny bit with upload_port = /dev/ttyACM1 or whatever, but the reset into bootloader mode should happen automatically throug ha special 1200bps serial open).