It compiles. and flashes onto Pico successfully. However when running, it displays error (I see it in Thonny, when I press Stop in Thonny I get same error):
Unable to connect to /dev/cu.usbmodem1412201: [Errno 2] could not open port /dev/cu.usbmodem1412201: [Errno 2] No such file or directory: '/dev/cu.usbmodem1412201'
Process ended with exit code 1.
This command gives me:
$ sudo ls -la /dev/cu.*
crw-rw-rw- 1 root wheel 0x16000001 2 Aug 15:45 /dev/cu.BLTH
Can someone help why this is happening?
And most importantly how can I get serial number of my Pico?
Unable to connect to /dev/cu.usbmodem1412201: [Errno 2] could not open port /dev/cu.usbmodem1412201: [Errno 2] No such file or directory: '/dev/cu.usbmodem1412201'
Process ended with exit code 1.
I also tried a simple hello world, here. Same effect.
I managed to get the serial number through VS Code and through this C code.
When I changed the USB hub to another USB cable I started getting the serial number in VS Code when flashing it onto Pico (1st screenshot). It must have been bad connection previously through the hub.
Now when I run this command, I get the desired dev/cu.usbmodem thingy:
$ sudo ls -la /dev/cu.*
Password:
crw-rw-rw- 1 root wheel 0x16000001 10 Aug 12:42 /dev/cu.BLTH
crw-rw-rw- 1 root wheel 0x16000003 10 Aug 12:54 /dev/cu.usbmodem14301
When I changed in Thonny > bottom right corner > the WebREPL setting from “try to detect port automatically” to “n/a /dev/cu.BLTH” (2nd screenshot) then I could not get the flashed onto Pico code to run and show results in Thonny (3rd screenshot). But when I changed it to manually choose /dev/cu.usbmodem14301, the code started running (4th screenshot)! It does it in a weird way, displaying error that the device is busy, but hey - it works!
Conclusion: you don’t need to write the code to get serial number from Pico. You need a simple, runnable, hello world C program and serial number will print in VS Code when you try to run it on Pico.
I think your program is running. Have you tried to connect with a simple terminal emulator directly to /dev/cu.usbmodem14301 (that is the port that shows up in the first screenshot)? Note that Thonny needs a MicroPython/CircuitPython firmware, as it clearly states in the third screenshot.
I would also change the CMakeLists.txt file (near the end): only activate usb, not usb and uart. I am not fully sure, but I think if you activate both you have to explicitly select in your code which target the printf will use.