3

I am using Raspberry pi pico on Arduino IDE. I am using this library githublink for it. There is 3 examples in this link, ArduinoUniqueID and ArduinoUniqueID8 doesn't print anything. Ide says

WARNING: library ArduinoUniqueID claims to run on avr, esp8266, esp32, sam, samd, stm32 architecture(s) and may be incompatible with your current board which runs on mbed_rp2040 architecture(s).

(but GitHub says we add RP2040)

When I try to use last example ArduinoUniqueIDSerialUSB , It prints something but they are not correct values. It prints these :

UniqueID: 30 00 33 00 39 00 31 00 36 00 30 00 45 00 36 00 32 00 41 00 38 00 32 00 34 00 38 00 43 00 33 00 
UniqueID: 34 00 38 00 43 00 33 00 

The correct unique ID values here : (I printed these with micropython)

hex value of s = e660a4931754432c
type s = <class 'bytes'>
s =  b'\xe6`\xa4\x93\x17TC,'

I don't even know what type 34 00 38 00 43 00 33 00 are, I try to convert hex but it prints same thing.

How can I find pico's Unique ID with Arduino Code ?

2 Answers2

4

A unique ID for the Pico (and most RP2040 boards) is determined by the serial number of the flash. The Pico SDK has functions to get that ID. Either you can retrieve it directly from the flash by using flash_get_unique_id(uint8_t* id_out) which is what the library linked above did. The documentation for that is here.

Alternatively, you can get the unique ID from the MCU. The two functions for retrieving the ID are pico_get_unique_board_id(pico_unique_board_id_t* id_out) which returns the ID as a hex array or pico_get_unique_board_id_string(char* id_out, uint len) which returns it as a string. The documentation for that is here.

Those values are hex and are coming from their Unique_ID buffer which it looks like is being improperly filled with the Unique id. The code below should instead do what you need.

   uint8_t UniqueID[8];
   void UniqueIDdump(stream)                      
    {
        flash_get_unique_id(UniqueID);                                             
        stream.print("UniqueID: ");       
        for (size_t i = 0; i < 8; i++) 
        {                                         
            if (UniqueID[i] < 0x10)               
                stream.print("0");                
            stream.print(UniqueID[i], HEX);      
            stream.print(" ");                          }                                         
        stream.println();                         
    }
hcheung
  • 3,377
  • 3
  • 11
  • 23
Dacoolinus
  • 388
  • 1
  • 10
  • Thank you, for now I am using Earle's pico core so I can't try this. Because this library not work over there. I will try to implement this to Earle pico core. – Tryingtogetsome Nov 22 '22 at 13:47
1

"UniqueID: 30 00 33 " etc is a unicode string "039160E62A8248C348C3" not hex.

also for Earls pico core just add extern "C" void flash_get_unique_id(uint8_t *p); to your sketch and you can access the function required by the above UniqueIDdump example

starball
  • 20,030
  • 7
  • 43
  • 238
Tony
  • 11
  • 1