פיתוח RFID ESP32
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
#include <MFRC522v2.h> #include <MFRC522DriverSPI.h> //#include <MFRC522DriverI2C.h> #include <MFRC522DriverPinSimple.h> #include <MFRC522Debug.h> MFRC522DriverPinSimple ss_pin(5); // Configurable, see typical pin layout above. MFRC522DriverSPI driver{ss_pin}; // Create SPI driver. // MFRC522DriverI2C driver{}; // Create I2C driver. MFRC522 mfrc522{driver}; // Create MFRC522 instance. String tagContent = ""; void setup() { Serial.begin(115200); // Initialize serial communications with the PC for debugging. while (!Serial) ; // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4). mfrc522.PCD_Init(); // Init MFRC522 board. MFRC522Debug::PCD_DumpVersionToSerial(mfrc522, Serial); // Show details of PCD - MFRC522 Card Reader details. Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks...")); } void loop() { // Reset the loop if no new card present on the sensor/reader. This saves the entire process when idle. 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. MFRC522Debug::PICC_DumpToSerial(mfrc522, Serial, &(mfrc522.uid)); Serial.println("Printing only the Card ID:"); Serial.println("--------------------------"); for (byte i = 0; i < mfrc522.uid.size; i++) { tagContent.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ")); tagContent.concat(String(mfrc522.uid.uidByte[i], HEX)); } tagContent.toUpperCase(); Serial.println(tagContent); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
#include <MFRC522v2.h> #include <MFRC522DriverSPI.h> //#include <MFRC522DriverI2C.h> #include <MFRC522DriverPinSimple.h> #include <MFRC522Debug.h> MFRC522DriverPinSimple ss_pin(5); // Configurable, see typical pin layout above. MFRC522DriverSPI driver{ss_pin}; // Create SPI driver. // MFRC522DriverI2C driver{}; // Create I2C driver. MFRC522 mfrc522{driver}; // Create MFRC522 instance. String tagContent = ""; char IdCards[10][20]; void setup() { Serial.begin(115200); // Initialize serial communications with the PC for debugging. while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4). mfrc522.PCD_Init(); // Init MFRC522 board. MFRC522Debug::PCD_DumpVersionToSerial(mfrc522, Serial); // Show details of PCD - MFRC522 Card Reader details. Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks...")); strcpy(IdCards[0]," 84 41 26 64"); } void loop() { // Reset the loop if no new card present on the sensor/reader. This saves the entire process when idle. 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. // MFRC522Debug::PICC_DumpToSerial(mfrc522, Serial, &(mfrc522.uid)); tagContent = ""; Serial.println("Printing only the Card ID:"); Serial.println("--------------------------"); for (byte i = 0; i < mfrc522.uid.size; i++) { tagContent.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ")); tagContent.concat(String(mfrc522.uid.uidByte[i], HEX)); } tagContent.toUpperCase(); Serial.println(">>>>>>>>>>>>>>>>>"); Serial.println(tagContent); if(tagContent==" 84 41 26 64") { Serial.println("Door open"); } char *p; p=IdCards[0]; if(p = IdCards[0]) { Serial.println("Door open 1"); } } |