Getting Pico Serial Number, sharing Pico data in sensor.community

Hi

In order to share data in http://sensor.community I need to register a device with serial number.

To get Pico serial number I had to put together C code, based on https://datasheets.raspberrypi.com/pico/raspberry-pi-pico-c-sdk.pdf. The code is here: enviro/c/pico/pico-test/serialnumber/source.c at main · sikorka/enviro · GitHub.

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?

PS A simple hello world also gives me the said error enviro/c/pico/pico-test/hello/source.c at main · sikorka/enviro · GitHub. Also I tried on 2 Picos, same effect. I am new to this so any advice is welcome 🙏

Your program is missing the never ending loop at the end. It starts, stops and that’s it, so the uart is only open for a very short time.

1 Like

Hi

Thank you for your hints!

I added the loop with infinite printing of the serial number. I hope the code is ok. I unfortunately get the same error on both Picos:

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.

  1. 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
  1. 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.

1 Like

Thank you for your tips. I tried with minicom and screen and I can directly connect.

I also removed uart, it wasn’t needed after all.