In this example we will connect an RFID-RC522 module and connect to a Wemos Mini
The microcontroller and card reader uses SPI for communication . The card reader and the tags communicate using a 13.56MHz electromagnetic field. (ISO 14443A standart tags)
Features:
- MFRC522 chip based board
- Operating frequency: 13.56MHz
- Supply Voltage: 3.3V
- Current: 13-26mA
- Read Range: Approx 3cm with supplied card and fob
- SPI Interface
- Max Data Transfer Rate: 10Mbit / s
- Dimensions: 60mm × 39mm
Datasheet for the chip that used in modules can be found at:
http://www.nxp.com/documents/data_sheet/MFRC522.pdf
Parts List
Here are the parts I used
Name | Links | |
Wemos Mini | ||
RFID-RC522 | ||
Connecting cables |
Layout
This is how I wired the module to my Wemos Mini as per the documentation
Wemos D1 mini | |
---|---|
Signal | Pin |
RST/Reset | D3 |
SPI SS | D8 |
SPI MOSI | D7 |
SPI MISO | D6 |
SPI SCK | D5 |
Code
Install the RFID522 library – https://github.com/miguelbalboa/rfid
This is the DumpInfo example modified – its the two pins defined at the top of the code
#include <SPI.h> #include <MFRC522.h> #define RST_PIN D3 // Configurable, see typical pin layout above #define SS_PIN D8 // Configurable, see typical pin layout above MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance void setup() { Serial.begin(9600); // Initialize serial communications with the PC SPI.begin(); // Init SPI bus mfrc522.PCD_Init(); // Init MFRC522 mfrc522.PCD_DumpVersionToSerial(); // Show details of PCD - MFRC522 Card Reader details Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks...")); } void loop() { // Look for new cards if ( ! mfrc522.PICC_IsNewCardPresent()) { return; } // Select one of the cards if ( ! mfrc522.PICC_ReadCardSerial()) { return; } // Dump debug info about the card; PICC_HaltA() is automatically called mfrc522.PICC_DumpToSerial(&(mfrc522.uid)); }
Output
This is the output in the serial monitor
There are many other good examples in the library
I did see errors in the serial monitor windows – wdg reset, I will investigate this