当前位置:网站首页>ESP8266 RC522
ESP8266 RC522
2022-07-01 01:16:00 【Mrli0530】
One 、 Read the card information
#include <SPI.h>
#include <MFRC522.h>
#define RST_PIN 5 // Configure pins
#define SS_PIN 4
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create a new RFID example
MFRC522::MIFARE_Key key;
void setup() {
Serial.begin(9600); // Set the serial port baud rate to 9600
SPI.begin(); // SPI Start
mfrc522.PCD_Init(); // Init MFRC522 card
Serial.println("test-demo-start");
}
void loop() {
// Looking for a new card
if ( ! mfrc522.PICC_IsNewCardPresent()) {
//Serial.println(" No card found ");
return;
}
// Select a card
if ( ! mfrc522.PICC_ReadCardSerial()) {
Serial.println(" There are no cards to choose from ");
return;
}
// Show card details
Serial.print(F(" card UID:"));
dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);
Serial.println();
Serial.print(F(" Card type : "));
MFRC522::PICC_Type piccType = mfrc522.PICC_GetType(mfrc522.uid.sak);
Serial.println(mfrc522.PICC_GetTypeName(piccType));
// Check compatibility
if ( piccType != MFRC522::PICC_TYPE_MIFARE_MINI
&& piccType != MFRC522::PICC_TYPE_MIFARE_1K
&& piccType != MFRC522::PICC_TYPE_MIFARE_4K) {
Serial.println(F(" Just for Mifare Classic Card reading and writing "));
return;
}
MFRC522::StatusCode status;
if (status != MFRC522::STATUS_OK) {
Serial.print(F(" Authentication failed ? Or the card link failed "));
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}
// stop it PICC
mfrc522.PICC_HaltA();
// Stop encryption PCD
mfrc522.PCD_StopCrypto1();
return;
}
/** Dump byte arrays into serial hexadecimal values */
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);
}
}
Two 、 The whole program
//RC522
#define BLINKER_WIFI
#include <Blinker.h>
#include <SPI.h>
#include <String.h>
#include <MFRC522.h>
#define SS_PIN 4
#define RST_PIN 5
MFRC522 rfid(SS_PIN, RST_PIN);
byte nuidPICC[4];
int a_1=1;
// initialization
char auth[] = "eb6b127b98b2";
char ssid[] = "ESP8266";
char pswd[] = "12345678";
// New component object
BlinkerButton Button1("btn-abc");
// Press the key to execute the function
void button1_callback(const String & state) {
BLINKER_LOG("get button state: ", state);
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
Serial.print("S");
}
void setup()
{
Serial.begin(115200);
//SPI
SPI.begin();
rfid.PCD_Init();
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH);
// initialization blinker
Blinker.begin(auth, ssid, pswd);
Button1.attach(button1_callback);
// Set pin
}
//hex
void printHex(byte *buffer, byte bufferSize)
{
for (byte i = 0; i < bufferSize; i++)
{
//Serial.print(buffer[i] < 0x10 ? " 0" : "");
//Serial.print(buffer[i], HEX);
}
}
//================== For opening the door ================//
void printDec(byte *buffer, byte bufferSize)
{
for (byte i = 0; i < bufferSize; i++) {
//Serial.print(buffer[i] < 0x10 ? " 0" : "");
//Serial.print(buffer[i], DEC);
}
// personnel 1
if(nuidPICC[0]==0xAA&& nuidPICC[1]==0xFD && nuidPICC[2]==0xA9 && nuidPICC[3]==0x26)// Card number ID
{
Serial.print("1");
a_1=1;
// It's open here
}
// personnel 2
else if (nuidPICC[0]==0xAA&& nuidPICC[1]==0xF9 && nuidPICC[2]==0xD9 && nuidPICC[3]==0x26)
{
Serial.print("2");
a_1=1;
// It's open here
}
// personnel 3
else if (nuidPICC[0]==0xAA&& nuidPICC[1]==0xE1 && nuidPICC[2]==0x11 && nuidPICC[3]==0x26)
{
Serial.print("3");
a_1=1;
// It's open here
}
// personnel 4
else if (nuidPICC[0]==0xAA&& nuidPICC[1]==0x99 && nuidPICC[2]==0x3F && nuidPICC[3]==0xAD)
{
Serial.print("4");
a_1=1;
// It's open here
}
// personnel 5
else if (nuidPICC[0]==0x25&& nuidPICC[1]==0x5C && nuidPICC[2]==0x42 && nuidPICC[3]==0x25)
{
Serial.print("5");
a_1=1;
// It's open here
}
// personnel 6
else if (nuidPICC[0]==0x25&& nuidPICC[1]==0x5C && nuidPICC[2]==0x42 && nuidPICC[3]==0x25)
{
Serial.print("6");
a_1=1;
// It's open here
}
// personnel 7
else if (nuidPICC[0]==0x35&& nuidPICC[1]==0xB3 && nuidPICC[2]==0x70 && nuidPICC[3]==0x50)
{
Serial.print("7");
a_1=1;
// It's open here
}
// personnel 8
else if (nuidPICC[0]==0x39&& nuidPICC[1]==0x8E && nuidPICC[2]==0x3B && nuidPICC[3]==0x10)
{
Serial.print("8");
a_1=1;
// It's open here
}
// personnel 9
else if (nuidPICC[0]==0x25&& nuidPICC[1]==0xBA && nuidPICC[2]==0x3C && nuidPICC[3]==0x50)
{
Serial.print("9");
a_1=1;
// It's open here
}
// personnel 10
else if (nuidPICC[0]==0x35&& nuidPICC[1]==0x65 && nuidPICC[2]==0x95 && nuidPICC[3]==0x50)
{
Serial.print("0");
a_1=1;
// It's open here
}
}
// register + distinguish
void zhuce(){
if ( ! rfid.PICC_IsNewCardPresent())
return;
if ( ! rfid.PICC_ReadCardSerial())
return;
MFRC522::PICC_Type piccType = rfid.PICC_GetType(rfid.uid.sak); // take NUID Save to nuidPICC Array
for (byte i = 0; i < 4; i++)
{
nuidPICC[i] = rfid.uid.uidByte[i];
}
//Serial.print(" Hexadecimal UID:");
printHex(rfid.uid.uidByte, rfid.uid.size); //Hex:16 Base number
//Serial.println();
//
//Serial.print(" Decimal system UID:");
printDec(rfid.uid.uidByte, rfid.uid.size); //Dec:10 Base number
//Serial.println();
// Put in the card reading area IC The card goes to sleep , No more repeat card reading ,Halt( stop it )
rfid.PICC_HaltA();
// Stop reading card module encoding
rfid.PCD_StopCrypto1();
}
void loop(){
zhuce();
Blinker.run();
}
3、 ... and 、 connection 
边栏推荐
- 问题解决:如何管理线程私有(thread_local)的指针变量
- Detailed analysis of operators i++ and ++i in JS, i++ and ++i
- 【2023联发科提前批笔试题】~ 题目及参考答案
- Chapter 53 overall understanding of procedures from the perspective of business logic implementation
- pytorch编程知识(2)
- 技术人进阶画业务大图,手把手教学来了
- 孔乙己第一问之服务通信知多少?
- fluttertoast
- 解决IDEA:Class ‘XXX‘ not found in module ‘XXX‘
- Pytorch installs and uses GPU acceleration
猜你喜欢

【网络丢包,网络延迟?这款神器帮你搞定所有!】

For the first time in more than 20 years! CVPR best student thesis awarded to Chinese college students!
![[learning notes] double + two points](/img/d4/1ef449e3ef326a91966da11b3c8210.png)
[learning notes] double + two points

K210工地安全帽
![[original] PLSQL index sorting optimization](/img/91/dcd0262705a19645f1a87d4cf03bc8.jpg)
[original] PLSQL index sorting optimization

TCP三次握手为什么不是两次或四次

Two-stage RO: part 1

Principes de formation de la programmation robotique

Sword finger offer 19 Regular Expression Matching

Golang treasure house recommendation
随机推荐
[original] PLSQL index sorting optimization
PyTorch安装并使用gpu加速
PHP online confusion encryption tutorial sharing + basically no solution
The real topic of the 11th provincial competition of Bluebridge cup 2020 - crop hybridization
Service
Implementation of date class
Pytorch installs and uses GPU acceleration
NE555 waveform generator handle tutorial NE555 internal structure (I)
What if the disk of datanode is full?
关于Unity一般的输入操作方式
The longest selling mobile phone in China has been selling well since its launch, crushing iphone12
Metauniverse and virtual reality (II)
探索互联网时代STEAM教育创新之路
(learning power + thinking power) x action power, summary of flywheel effect on the growth of technicians
文件服务设计
Error msb8031: building an MFC project for a non Unicode character set is deprecated
Join table query select generation
双链表:初始化 插入 删除 遍历
Chapter 53 overall understanding of procedures from the perspective of business logic implementation
The communication mechanism and extension of Supervisor