The micro:bit has a register mapped into it's memory called the FICR (factory information configuration register) that stores information programmed in at manufacturing time. One of the items programmed in is a unique* serial number. The serial is actually a 64-bit factory generated pseudo-random number etched into each processor. Only 32 bits are used here though (as that makes it consistent for all the micro:bit higher level languages to deal with), and still enables it to be unique for most practical applications. To put this into context, you'd need about 100,000 to 250,000 micro:bits in one place to expect a duplication.
Voici un exemple d'un tel code récupéré sur une carte : 0x761b118b (en python)
A savoir : en python le numéro de série et retourné en base 16 : ex 0x761b118b
Pour récupérer le numéro de série de votre carte il suffit de rajouter la fonction get_serial_number ci-dessous dans votre programme
et de l'appeler quand vous avez besoin de le récupérer : get_serial_number()
from microbit import *
display.show('S')
def get_serial_number(type=hex):
NRF_FICR_BASE = 0x10000000
DEVICEID_INDEX = 25 # deviceid[1]
@micropython.asm_thumb
def reg_read(r0):
ldr(r0, [r0, 0])
return type(reg_read(NRF_FICR_BASE + (DEVICEID_INDEX*4)) & 0xFFFFFFFF)
while True:
if button_a.was_pressed():
display.scroll(get_serial_number())
sleep(1000)
display.show('S')
sleep(100)
Le code nécéssaire pour récupérer le numéro de série de la carte est un code assembleur. N'hésitez pas à demander à votre enseignant ce qu'il signifie.
Documentation correspondante : how-to-read-the-device-serial-number