ESP32 RFID
来自Jack's Lab
目录 |
1 Overview
2 Connections
RC522_SDA ---> Noduino_Quantum_D10 RC522_SCK ---> Noduino_Quantum_D13 RC522_MOSI ---> Noduino_Quantum_D11 RC522_MISO --->Noduino_ Quantum_D12 RC522_GND ---> Noduino_Quantum_GND RC522_RST ---> Noduino_Quantum_D9 RC522_3.3V ---> Noduino_Quantum_3V3
3 Quick start
3.1 Install Python
- Install python 2.7 from https://www.python.org/ftp/python/2.7/python-2.7.msi The installation direcory is: C:\Python27
- Run the git for windows, add this line 'export PATH=/c/python27/:$PATH' into /etc/bash.bashrc
- Enter 'Control Panel' ---> All Control Panel Items ---> System ---> Advanced System Settings (System Properties) ---> Advanced ---> Environment Variables, add the python into PATH:
3.2 Install Git
Install Git for windows from: https://git-for-windows.github.io
3.3 Install Arduino
- Install Arduino IDE
- Run the git for windows, go to Arduino IDE installation directory:
$ cd /PATH/TO/Arduino $ cd hardware $ mkdir espressif $ cd espressif $ git clone git://github.com/espressif/arduino-esp32.git esp32 $ cd esp32/tools $ python get.py # waitting for generating the toolchain $ $ cd ../../../../libraries $ git clone git://github.com/miguelbalboa/rfid.git Cloning into 'rfid'... remote: Counting objects: 1105, done. remote: Total 1105 (delta 0), reused 0 (delta 0), pack-reused 1105eceiving objects: K100% Receiving objects: 100% (1105/1105), 1.35 MiB | 459.00 KiB/s, done. Resolving deltas: 100% (582/582), done. Checking connectivity... done.
- Restart Arduino IDE
3.4 Compile and Upload
- Run Arduino IDE, click File --> New, input following code in the new windows in Arduino IDE:
#include <SPI.h>
#include <MFRC522.h>
#define RST_PIN SCL // Configurable, see typical pin layout above
#define NR_OF_READERS 1
byte ssPins[] = {SS};
MFRC522 mfrc522[NR_OF_READERS]; // Create MFRC522 instance.
void setup() {
Serial.begin(115200); // Initialize serial communications with the PC
while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
SPI.begin(); // Init SPI bus
for (uint8_t reader = 0; reader < NR_OF_READERS; reader++) {
mfrc522[reader].PCD_Init(ssPins[reader], RST_PIN); // Init each MFRC522 card
Serial.print(F("Reader "));
Serial.print(reader);
Serial.print(F(": "));
mfrc522[reader].PCD_DumpVersionToSerial();
}
}
void loop() {
for (uint8_t reader = 0; reader < NR_OF_READERS; reader++) {
// Look for new cards
if (mfrc522[reader].PICC_IsNewCardPresent() && mfrc522[reader].PICC_ReadCardSerial()) {
Serial.print(F("Reader "));
Serial.print(reader);
// Show some details of the PICC (that is: the tag/card)
Serial.print(F(": Card UID:"));
dump_byte_array(mfrc522[reader].uid.uidByte, mfrc522[reader].uid.size);
Serial.println();
Serial.print(F("PICC type: "));
MFRC522::PICC_Type piccType = mfrc522[reader].PICC_GetType(mfrc522[reader].uid.sak);
Serial.println(mfrc522[reader].PICC_GetTypeName(piccType));
// Halt PICC
mfrc522[reader].PICC_HaltA();
// Stop encryption on PCD
mfrc522[reader].PCD_StopCrypto1();
} //if (mfrc522[reader].PICC_IsNewC
} //for(uint8_t reader
}
void dump_byte_array(byte *buffer, byte bufferSize) {
for (byte i = 0; i < bufferSize; i++) {
Serial.print(buffer[i] < 0x10 ? " 0" : " ");
Serial.print(buffer[i], HEX);
}
}
Select:
Press Ctrl + U to upload the firmware into Quantum board
Open the serial with 115200 bitrate, reset the board, use a rfid card to touch the rc522:
4 Reference
- For more information please refer to