Tryingtogetsome
Tryingtogetsome

Reputation: 71

Arduino RP2040 Pico Unique ID

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 ?

Upvotes: 3

Views: 3651

Answers (3)

DSmall
DSmall

Reputation: 26

Adding this for those looking for the same solution in the future. Earl has added a rp2040.getChipID() function to his pico core which will provide the char * (c string) result. A code snippet is:

  // Print out my unique Id
  Serial.print("Unique Id: "); Serial.println(rp2040.getChipID());

And here is the result:

Unique Id: E66138528361BB32

Upvotes: 1

Dacoolinus
Dacoolinus

Reputation: 403

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();                         
    }

Upvotes: 4

Tony
Tony

Reputation: 11

"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

Upvotes: 1

Related Questions