2023年8月26日 星期六

實驗1-1RFID RC522 Interfacing with ESP32

實驗1-1RFID RC522 Interfacing with ESP32




/*

 * This ESP32 code is created by esp32io.com

 *

 * This ESP32 code is released in the public domain

 *

 * For more detail (instruction and wiring diagram), visit https://esp32io.com/tutorials/esp32-rfid-nfc

 */


#include <SPI.h>

#include <MFRC522.h>


#define SS_PIN  5  // ESP32 pin GPIO5 

#define RST_PIN 27 // ESP32 pin GPIO27 


MFRC522 rfid(SS_PIN, RST_PIN);


void setup() {

  Serial.begin(9600);

  SPI.begin(); // init SPI bus

  rfid.PCD_Init(); // init MFRC522


  Serial.println("Tap an RFID/NFC tag on the RFID-RC522 reader");

}


void loop() {

  if (rfid.PICC_IsNewCardPresent()) { // new tag is available

    if (rfid.PICC_ReadCardSerial()) { // NUID has been readed

      MFRC522::PICC_Type piccType = rfid.PICC_GetType(rfid.uid.sak);

      Serial.print("RFID/NFC Tag Type: ");

      Serial.println(rfid.PICC_GetTypeName(piccType));


      // print UID in Serial Monitor in the hex format

      Serial.print("UID:");

      for (int i = 0; i < rfid.uid.size; i++) {

        Serial.print(rfid.uid.uidByte[i] < 0x10 ? " 0" : " ");

        Serial.print(rfid.uid.uidByte[i], HEX);

      }

      Serial.println();


      rfid.PICC_HaltA(); // halt PICC

      rfid.PCD_StopCrypto1(); // stop encryption on PCD

    }

  }

}


沒有留言:

張貼留言

Messaging API作為替代方案

  LINE超好用功能要沒了!LINE Notify明年3月底終止服務,有什麼替代方案? LINE Notify將於2025年3月31日結束服務,官方建議改用Messaging API作為替代方案。 //CHANNEL_ACCESS_TOKEN = 'Messaging ...