This library provides a Microsoft Makecode package for the Joy-IT SBC-RFID-RC522 RFID module. See https://joy-it.net/products/SBC-RFID-RC522 for more details.
The RFID module needs to be connected with six pins to the Micro:bit:
| RFID module | Micro:bit |
|---|---|
| VCC | 3V |
| GND | GND |
| MISO | P15 |
| MOSI | P14 |
| SCK | P13 |
| NSS | P16 |
The RFID module needs to be initialized before it is ready to use. All necessary commands will be transfered via SPI here.
// Initialize RIFD module
MFRC522.Init()This function reads the cards unique ID and returns it. This function blocks execution until a card is presented to the reader.
// Read unique ID
MFRC522.getID()This function attempts to read the cards unique ID. In case a card is presented to the reader when the function is called, it returns the cards unique ID, otherwise it returns 0. This function does not block execution and should be called in a loop in order to detect the case when a card is presented to the reader.
// Read unique ID once
MFRC522.getIDOnce()Data stored on the card can be retrieved with this function. This function blocks execution until a card is presented to the reader.
// Read data
MFRC522.read()This function attempts to read the data stored on the card. In case a card is presented to the reader when the function is called, it returns the data stored on the card, otherwise it returns null. This function does not block execution and should be called in a loop in order to detect the case when a card is presented to the reader.
// Read data once
MFRC522.readOnce()Write data, formatted as string, to the card.
// Write data
MFRC522.write("1234")After use, the antenn can be turned off.
// Turn antenna off
MFRC522.AntennaOff()- for PXT/microbit
MIT