first commit

This commit is contained in:
2025-03-07 19:30:46 +01:00
commit b12dd31f8e
66 changed files with 5930 additions and 0 deletions

View File

@@ -0,0 +1,65 @@
/*
* --------------------------------------------------------------------------------------------------------------------
* Example to test your firmware.
* --------------------------------------------------------------------------------------------------------------------
* This is a MFRC522 library example; for further details and other examples see: https://github.com/OSSLibraries/Arduino_MFRC522v2
*
* This example test the firmware of your MFRC522 reader module, only known version can be checked. If the test passed
* it do not mean that your module is faultless! Some modules have bad or broken antennas or the PICC is broken.
*
* @author Rotzbua
* @license Released into the public domain.
*
* Typical pin layout used:
* -----------------------------------------------------------------------------------------
* MFRC522 Arduino Arduino Arduino Arduino Arduino
* Reader/PCD Uno/101 Mega Nano v3 Leonardo/Micro Pro Micro
* Signal Pin Pin Pin Pin Pin Pin
* -----------------------------------------------------------------------------------------
* SPI SS SDA(SS) 10 53 D10 10 10
* SPI MOSI MOSI 11 / ICSP-4 51 D11 ICSP-4 16
* SPI MISO MISO 12 / ICSP-1 50 D12 ICSP-1 14
* SPI SCK SCK 13 / ICSP-3 52 D13 ICSP-3 15
*
* Not found? For more see: https://github.com/OSSLibraries/Arduino_MFRC522v2#pin-layout
*/
#include <MFRC522v2.h>
#include <MFRC522DriverSPI.h>
//#include <MFRC522DriverI2C.h>
#include <MFRC522DriverPinSimple.h>
#include <MFRC522Debug.h>
MFRC522DriverPinSimple ss_pin(10); // Configurable, see typical pin layout above.
MFRC522DriverSPI driver{ss_pin}; // Create SPI driver.
//MFRC522DriverI2C driver{}; // Create I2C driver.
MFRC522 mfrc522{driver}; // Create MFRC522 instance.
/**
* Check firmware only once at startup.
*/
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.
Serial.println(F("*****************************"));
Serial.println(F("MFRC522 Digital self test"));
Serial.println(F("*****************************"));
MFRC522Debug::PCD_DumpVersionToSerial(mfrc522, Serial); // Show version of PCD - MFRC522 Card Reader.
Serial.println(F("-----------------------------"));
Serial.println(F("Only known versions supported"));
Serial.println(F("-----------------------------"));
Serial.println(F("Performing test..."));
bool result = mfrc522.PCD_PerformSelfTest(); // Perform the test.
Serial.println(F("-----------------------------"));
Serial.print(F("Result: "));
if (result)
Serial.println(F("OK"));
else
Serial.println(F("DEFECT or UNKNOWN"));
Serial.println();
}
void loop() {} // nothing to do

View File

@@ -0,0 +1,63 @@
/*
* --------------------------------------------------------------------------------------------------------------------
* Example showing how to read data from a PICC to serial.
* --------------------------------------------------------------------------------------------------------------------
* This is a MFRC522 library example; for further details and other examples see: https://github.com/OSSLibraries/Arduino_MFRC522v2
*
* Example sketch/program showing how to read data from a PICC (that is: a RFID Tag or Card) using a MFRC522 based RFID
* Reader on the Arduino SPI interface.
*
* When the Arduino and the MFRC522 module are connected (see the pin layout below), load this sketch into Arduino IDE
* then verify/compile and upload it. To see the output: use Tools, Serial Monitor of the IDE (hit Ctrl+Shift+M). When
* you present a PICC (that is: a RFID Tag or Card) at reading distance of the MFRC522 Reader/PCD, the serial output
* will show the ID/UID, type and any data blocks it can read. Note: you may see "Timeout in communication" messages
* when removing the PICC from reading distance too early.
*
* If your reader supports it, this sketch/program will read all the PICCs presented (that is: multiple tag reading).
* So if you stack two or more PICCs on top of each other and present them to the reader, it will first output all
* details of the first and then the next PICC. Note that this may take some time as all data blocks are dumped, so
* keep the PICCs at reading distance until complete.
*
* @license Released into the public domain.
*
* Typical pin layout used:
* -----------------------------------------------------------------------------------------
* MFRC522 Arduino Arduino Arduino Arduino Arduino
* Reader/PCD Uno/101 Mega Nano v3 Leonardo/Micro Pro Micro
* Signal Pin Pin Pin Pin Pin Pin
* -----------------------------------------------------------------------------------------
* SPI SS SDA(SS) 10 53 D10 10 10
* SPI MOSI MOSI 11 / ICSP-4 51 D11 ICSP-4 16
* SPI MISO MISO 12 / ICSP-1 50 D12 ICSP-1 14
* SPI SCK SCK 13 / ICSP-3 52 D13 ICSP-3 15
*
* Not found? For more see: https://github.com/OSSLibraries/Arduino_MFRC522v2#pin-layout
*/
#include <MFRC522v2.h>
#include <MFRC522DriverI2C.h>
#include <MFRC522Debug.h>
const uint8_t customAddress = 0x28;
TwoWire &customI2C = Wire;
MFRC522DriverI2C driver{customAddress, customI2C}; // Create I2C driver.
MFRC522 mfrc522{driver}; // Create MFRC522 instance.
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() {
if ( !mfrc522.PICC_IsNewCardPresent() || !mfrc522.PICC_ReadCardSerial()) {
return;
}
MFRC522Debug::PICC_DumpToSerial(mfrc522, Serial, &(mfrc522.uid));
}

View File

@@ -0,0 +1,66 @@
/*
* --------------------------------------------------------------------------------------------------------------------
* Example showing how to read data from a PICC to serial.
* --------------------------------------------------------------------------------------------------------------------
* This is a MFRC522 library example; for further details and other examples see: https://github.com/OSSLibraries/Arduino_MFRC522v2
*
* Example sketch/program showing how to read data from a PICC (that is: a RFID Tag or Card) using a MFRC522 based RFID
* Reader on the Arduino SPI interface.
*
* When the Arduino and the MFRC522 module are connected (see the pin layout below), load this sketch into Arduino IDE
* then verify/compile and upload it. To see the output: use Tools, Serial Monitor of the IDE (hit Ctrl+Shift+M). When
* you present a PICC (that is: a RFID Tag or Card) at reading distance of the MFRC522 Reader/PCD, the serial output
* will show the ID/UID, type and any data blocks it can read. Note: you may see "Timeout in communication" messages
* when removing the PICC from reading distance too early.
*
* If your reader supports it, this sketch/program will read all the PICCs presented (that is: multiple tag reading).
* So if you stack two or more PICCs on top of each other and present them to the reader, it will first output all
* details of the first and then the next PICC. Note that this may take some time as all data blocks are dumped, so
* keep the PICCs at reading distance until complete.
*
* @license Released into the public domain.
*
* Typical pin layout used:
* -----------------------------------------------------------------------------------------
* MFRC522 Arduino Arduino Arduino Arduino Arduino
* Reader/PCD Uno/101 Mega Nano v3 Leonardo/Micro Pro Micro
* Signal Pin Pin Pin Pin Pin Pin
* -----------------------------------------------------------------------------------------
* SPI SS SDA(SS) 10 53 D10 10 10
* SPI MOSI MOSI 11 / ICSP-4 51 D11 ICSP-4 16
* SPI MISO MISO 12 / ICSP-1 50 D12 ICSP-1 14
* SPI SCK SCK 13 / ICSP-3 52 D13 ICSP-3 15
*
* Not found? For more see: https://github.com/OSSLibraries/Arduino_MFRC522v2#pin-layout
*/
#include <MFRC522v2.h>
#include <MFRC522DriverSPI.h>
#include <MFRC522DriverPinSimple.h>
#include <MFRC522Debug.h>
MFRC522DriverPinSimple ss_pin(10); // Create pin driver. See typical pin layout above.
SPIClass &spiClass = SPI; // Alternative SPI e.g. SPI2 or from library e.g. softwarespi.
const SPISettings spiSettings = SPISettings(SPI_CLOCK_DIV4, MSBFIRST, SPI_MODE0); // May have to be set if hardware is not fully compatible to Arduino specifications.
MFRC522DriverSPI driver{ss_pin, spiClass, spiSettings}; // Create SPI driver.
MFRC522 mfrc522{driver}; // Create MFRC522 instance.
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() {
if ( !mfrc522.PICC_IsNewCardPresent() || !mfrc522.PICC_ReadCardSerial()) {
return;
}
MFRC522Debug::PICC_DumpToSerial(mfrc522, Serial, &(mfrc522.uid));
}

View File

@@ -0,0 +1,70 @@
/*
* --------------------------------------------------------------------------------------------------------------------
* Example showing how to read data from a PICC to serial.
* --------------------------------------------------------------------------------------------------------------------
* This is a MFRC522 library example; for further details and other examples see: https://github.com/OSSLibraries/Arduino_MFRC522v2
*
* Example sketch/program showing how to read data from a PICC (that is: a RFID Tag or Card) using a MFRC522 based RFID
* Reader on the Arduino SPI interface.
*
* When the Arduino and the MFRC522 module are connected (see the pin layout below), load this sketch into Arduino IDE
* then verify/compile and upload it. To see the output: use Tools, Serial Monitor of the IDE (hit Ctrl+Shift+M). When
* you present a PICC (that is: a RFID Tag or Card) at reading distance of the MFRC522 Reader/PCD, the serial output
* will show the ID/UID, type and any data blocks it can read. Note: you may see "Timeout in communication" messages
* when removing the PICC from reading distance too early.
*
* If your reader supports it, this sketch/program will read all the PICCs presented (that is: multiple tag reading).
* So if you stack two or more PICCs on top of each other and present them to the reader, it will first output all
* details of the first and then the next PICC. Note that this may take some time as all data blocks are dumped, so
* keep the PICCs at reading distance until complete.
*
* @license Released into the public domain.
*
* Typical pin layout used:
* -----------------------------------------------------------------------------------------
* MFRC522 Arduino Arduino Arduino Arduino Arduino
* Reader/PCD Uno/101 Mega Nano v3 Leonardo/Micro Pro Micro
* Signal Pin Pin Pin Pin Pin Pin
* -----------------------------------------------------------------------------------------
* SPI SS SDA(SS) 10 53 D10 10 10
* SPI MOSI MOSI 11 / ICSP-4 51 D11 ICSP-4 16
* SPI MISO MISO 12 / ICSP-1 50 D12 ICSP-1 14
* SPI SCK SCK 13 / ICSP-3 52 D13 ICSP-3 15
*
* Not found? For more see: https://github.com/OSSLibraries/Arduino_MFRC522v2#pin-layout
*/
#include <MFRC522v2.h>
#include <MFRC522DriverSPI.h>
//#include <MFRC522DriverI2C.h>
#include <MFRC522DriverPinSimple.h>
#include <MFRC522Debug.h>
MFRC522DriverPinSimple ss_pin(10); // Configurable, see typical pin layout above.
MFRC522DriverSPI driver{ss_pin}; // Create SPI driver.
//MFRC522DriverI2C driver{}; // Create I2C driver.
MFRC522 mfrc522{driver}; // Create MFRC522 instance.
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));
}

View File

@@ -0,0 +1,88 @@
/*
* --------------------------------------------------------------------------------------------------------------------
* Example to change UID of changeable MIFARE card.
* --------------------------------------------------------------------------------------------------------------------
* This is a MFRC522 library example; for further details and other examples see: https://github.com/OSSLibraries/Arduino_MFRC522v2
*
* This sample shows how to set the UID on a UID changeable MIFARE card.
*
* @author Tom Clement
* @license Released into the public domain.
*
* Typical pin layout used:
* -----------------------------------------------------------------------------------------
* MFRC522 Arduino Arduino Arduino Arduino Arduino
* Reader/PCD Uno/101 Mega Nano v3 Leonardo/Micro Pro Micro
* Signal Pin Pin Pin Pin Pin Pin
* -----------------------------------------------------------------------------------------
* SPI SS SDA(SS) 10 53 D10 10 10
* SPI MOSI MOSI 11 / ICSP-4 51 D11 ICSP-4 16
* SPI MISO MISO 12 / ICSP-1 50 D12 ICSP-1 14
* SPI SCK SCK 13 / ICSP-3 52 D13 ICSP-3 15
*
* Not found? For more see: https://github.com/OSSLibraries/Arduino_MFRC522v2#pin-layout
*/
#include <MFRC522v2.h>
#include <MFRC522DriverSPI.h>
//#include <MFRC522DriverI2C.h>
#include <MFRC522DriverPinSimple.h>
#include <MFRC522Debug.h>
#include <MFRC522Hack.h>
MFRC522DriverPinSimple ss_pin(10); // Configurable, see typical pin layout above.
MFRC522DriverSPI driver(ss_pin);
//MFRC522DriverI2C driver();
MFRC522 mfrc522(driver); // Create MFRC522 instance.
MFRC522Hack mfrc522Hack(mfrc522, true); // Create MFRC522Hack instance.
/* Set your new UID here! */
constexpr uint8_t newUid[] = {0xDE, 0xAD, 0xBE, 0xEF};
MFRC522::MIFARE_Key key;
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.
Serial.println(F("Warning: this example overwrites the UID of your UID changeable card, use with care!"));
Serial.println(F("This example only works with MIFARE Classic cards."));
// Prepare key - all keys are set to FFFFFFFFFFFFh at chip delivery from the factory.
for (byte i = 0; i < 6; i++) {
key.keyByte[i] = 0xFF;
}
}
void loop() {
// Reset the loop if no new card present on the sensor/reader. This saves the entire process when idle. And if present, select one.
if ( !mfrc522.PICC_IsNewCardPresent() || !mfrc522.PICC_ReadCardSerial() ) {
delay(50);
return;
}
// Now a card is selected. The UID and SAK is in mfrc522.uid.
// Dump UID.
Serial.print(F("Card UID:"));
MFRC522Debug::PrintSelectedUID(mfrc522, Serial);
Serial.println();
// Set new UID.
if ( mfrc522Hack.MIFARE_SetUid(newUid, (byte)4, key, true) ) {
Serial.println(F("Wrote new UID to card."));
}
// Halt PICC and re-select it so DumpToSerial doesn't get confused.
mfrc522.PICC_HaltA();
if ( !mfrc522.PICC_IsNewCardPresent() || !mfrc522.PICC_ReadCardSerial() ) {
return;
}
// Dump the new memory contents.
Serial.println(F("New UID and contents:"));
MFRC522Debug::PICC_DumpToSerial(mfrc522, Serial, &(mfrc522.uid));
delay(2000);
}

View File

@@ -0,0 +1,59 @@
/*
* --------------------------------------------------------------------------------------------------------------------
* Example to fix a broken UID changeable MIFARE cards.
* --------------------------------------------------------------------------------------------------------------------
* This is a MFRC522 library example; for further details and other examples see: https://github.com/OSSLibraries/Arduino_MFRC522v2
*
* This sample shows how to fix a broken UID changeable MIFARE cards that have a corrupted sector 0.
*
* @author Tom Clement
* @license Released into the public domain.
*
* Typical pin layout used:
* -----------------------------------------------------------------------------------------
* MFRC522 Arduino Arduino Arduino Arduino Arduino
* Reader/PCD Uno/101 Mega Nano v3 Leonardo/Micro Pro Micro
* Signal Pin Pin Pin Pin Pin Pin
* -----------------------------------------------------------------------------------------
* SPI SS SDA(SS) 10 53 D10 10 10
* SPI MOSI MOSI 11 / ICSP-4 51 D11 ICSP-4 16
* SPI MISO MISO 12 / ICSP-1 50 D12 ICSP-1 14
* SPI SCK SCK 13 / ICSP-3 52 D13 ICSP-3 15
*
* Not found? For more see: https://github.com/OSSLibraries/Arduino_MFRC522v2#pin-layout
*/
#include <MFRC522v2.h>
#include <MFRC522DriverSPI.h>
//#include <MFRC522DriverI2C.h>
#include <MFRC522DriverPinSimple.h>
#include <MFRC522Hack.h>
MFRC522DriverPinSimple ss_pin(10); // Configurable, see typical pin layout above.
MFRC522DriverSPI driver(ss_pin);
//MFRC522DriverI2C driver();
MFRC522 mfrc522(driver); // Create MFRC522 instance.
MFRC522Hack mfrc522Hack(mfrc522, true); // Create MFRC522Hack instance.
MFRC522::MIFARE_Key key;
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.
Serial.println(F("Warning: this example overwrites the UID of your UID changeable card, use with care!"));
Serial.println(F("This example only works with MIFARE Classic cards."));
// Prepare key - all keys are set to FFFFFFFFFFFFh at chip delivery from the factory.
for (byte i = 0; i < 6; i++) {
key.keyByte[i] = 0xFF;
}
}
void loop() {
if ( mfrc522Hack.MIFARE_UnbrickUidSector() ) {
Serial.println(F("Cleared sector 0, set UID to 1234. Card should be responsive again now."));
}
delay(1000);
}

View File

@@ -0,0 +1,92 @@
/*
* --------------------------------------------------------------------------------------------------------------------
* Example showing how to read data from more than one PICC to serial.
* --------------------------------------------------------------------------------------------------------------------
* This is a MFRC522 library example; for further details and other examples see: https://github.com/OSSLibraries/Arduino_MFRC522v2
*
* Example sketch/program showing how to read data from more than one PICC (that is: a RFID Tag or Card) using a
* MFRC522 based RFID Reader on the Arduino SPI interface.
*
* Warning: This may not work! Multiple devices at one SPI are difficult and cause many trouble!! Engineering skill
* and knowledge are required!
*
* @license Released into the public domain.
*
* Typical pin layout used:
* -----------------------------------------------------------------------------------------
* MFRC522 Arduino Arduino Arduino Arduino Arduino
* Reader/PCD Uno/101 Mega Nano v3 Leonardo/Micro Pro Micro
* Signal Pin Pin Pin Pin Pin Pin
* -----------------------------------------------------------------------------------------
* SPI SS 1 SDA(SS) ** custom, take a unused pin, only HIGH/LOW required **
* SPI SS 2 SDA(SS) ** custom, take a unused pin, only HIGH/LOW required **
* SPI MOSI MOSI 11 / ICSP-4 51 D11 ICSP-4 16
* SPI MISO MISO 12 / ICSP-1 50 D12 ICSP-1 14
* SPI SCK SCK 13 / ICSP-3 52 D13 ICSP-3 15
*
* Not found? For more see: https://github.com/OSSLibraries/Arduino_MFRC522v2#pin-layout
*/
// Note for i2c:
// With i2c possible if every device has a own unique address.
// Otherwise a i2c multiplexer is required, which requires a own implementation of MFRC522Driver.h.
#include <MFRC522v2.h>
#include <MFRC522DriverSPI.h>
#include <MFRC522DriverPinSimple.h>
#include <MFRC522Debug.h>
MFRC522DriverPinSimple ss_1_pin(10); // Configurable, take an unused pin, only HIGH/LOW required, must be different to SS 2.
MFRC522DriverPinSimple ss_2_pin(8); // Configurable, take an unused pin, only HIGH/LOW required, must be different to SS 1.
MFRC522DriverSPI driver_1{ss_1_pin};
MFRC522DriverSPI driver_2{ss_2_pin};
MFRC522 readers[]{driver_1, driver_2}; // Create MFRC522 instance.
/**
* Initialize.
*/
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).
for (MFRC522 reader : readers) {
reader.PCD_Init(); // Init each MFRC522 card.
Serial.print(F("Reader "));
static uint8_t i = 0;
i++;
Serial.print(i);
Serial.print(F(": "));
MFRC522Debug::PCD_DumpVersionToSerial(reader, Serial);
}
}
/**
* Main loop.
*/
void loop() {
// Look for new cards.
for (MFRC522 reader : readers) {
if (reader.PICC_IsNewCardPresent() && reader.PICC_ReadCardSerial()) {
Serial.print(F("Reader "));
static uint8_t i = 0;
i++;
Serial.print(i);
// Show some details of the PICC (that is: the tag/card).
Serial.print(F(": Card UID:"));
MFRC522Debug::PrintUID(Serial, reader.uid);
Serial.println();
Serial.print(F("PICC type: "));
MFRC522::PICC_Type piccType = reader.PICC_GetType(reader.uid.sak);
Serial.println(MFRC522Debug::PICC_GetTypeName(piccType));
// Halt PICC.
reader.PICC_HaltA();
// Stop encryption on PCD.
reader.PCD_StopCrypto1();
}
}
}