ESP32 RFID
来自Jack's Lab
(版本间的差异)
(→Quick start) |
(→Quick start) |
||
(未显示1个用户的11个中间版本) | |||
第2行: | 第2行: | ||
[[文件:Quantum-rfid.jpg | 600px]] | [[文件:Quantum-rfid.jpg | 600px]] | ||
+ | |||
+ | <br><br> | ||
+ | |||
+ | == Connections == | ||
+ | |||
+ | [[文件:Quantum-rfid-connect.png | 600px]] | ||
+ | |||
+ | |||
+ | <pre> | ||
+ | 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 | ||
+ | </pre> | ||
+ | |||
<br><br> | <br><br> | ||
第7行: | 第27行: | ||
== Quick start == | == Quick start == | ||
− | + | === 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 | * 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, | + | * 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: | ||
+ | |||
+ | |||
+ | [[文件:Windows-path.jpg | 400px]] | ||
+ | |||
+ | <br><br> | ||
+ | |||
+ | === Install Git === | ||
+ | |||
+ | Install Git for windows from: https://git-for-windows.github.io | ||
+ | |||
+ | <br><br> | ||
+ | |||
+ | === Install Arduino === | ||
* Install Arduino IDE | * Install Arduino IDE | ||
第24行: | 第59行: | ||
$ git clone git://github.com/espressif/arduino-esp32.git esp32 | $ git clone git://github.com/espressif/arduino-esp32.git esp32 | ||
$ cd esp32/tools | $ cd esp32/tools | ||
− | $ python get.py | + | $ 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. | ||
</source> | </source> | ||
第30行: | 第74行: | ||
<br><br> | <br><br> | ||
− | + | ||
− | < | + | === Compile and Upload === |
− | < | + | |
− | < | + | * Run Arduino IDE, click File --> New, input following code in the new windows in Arduino IDE: |
+ | |||
+ | <source lang=cpp> | ||
+ | #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); | ||
+ | } | ||
+ | } | ||
+ | </source> | ||
+ | |||
+ | |||
+ | Select: | ||
+ | |||
+ | [[文件:Quantum-rfid-arduino.jpg | 700px]] | ||
+ | |||
+ | |||
+ | 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: | ||
+ | |||
+ | |||
+ | [[文件:Quantum-rfid-uart.jpg | 600px]] | ||
+ | |||
<br><br> | <br><br> | ||
2016年11月15日 (二) 17:32的最后版本
目录 |
[编辑] 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