Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: miguelbalboa/rfid
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: dirkx/rfid
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 12 commits
  • 14 files changed
  • 2 contributors

Commits on Nov 7, 2018

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    8fcd538 View commit details

Commits on Nov 11, 2018

  1. cleanups.

    dirkx committed Nov 11, 2018
    Copy the full SHA
    9199263 View commit details

Commits on Nov 15, 2018

  1. Copy the full SHA
    62713e9 View commit details

Commits on Mar 9, 2019

  1. Fix i2c register names.

    dirkx committed Mar 9, 2019
    Copy the full SHA
    874de6f View commit details

Commits on Mar 28, 2020

  1. Copy the full SHA
    20ddd7b View commit details
  2. Copy the full SHA
    09fc9d6 View commit details
  3. Move URL over to the makerspace

    dirkx committed Mar 28, 2020
    Copy the full SHA
    0dc6dc0 View commit details
  4. Copy the full SHA
    75a79fa View commit details

Commits on Feb 15, 2021

  1. Copy the full SHA
    2bad1c5 View commit details
  2. Copy the full SHA
    06054fc View commit details

Commits on Oct 22, 2021

  1. Merge pull request #1 from lucas-inacio/uart

    Uart
    dirkx authored Oct 22, 2021
    Copy the full SHA
    a416633 View commit details
  2. Merge pull request #1 from MakerSpaceLeiden/master

    Arduino DUE board
    dirkx authored Oct 22, 2021
    Copy the full SHA
    8035802 View commit details
Showing with 821 additions and 343 deletions.
  1. +2 −2 README.rst
  2. +5 −0 changes.txt
  3. +84 −0 examples/Minimal-I2C/Minimal-I2C.ino
  4. +102 −0 examples/Minimal-SPI/Minimal-SPI.ino
  5. +48 −0 examples/rfid_uart/rfid_uart.ino
  6. +0 −14 library.json
  7. +8 −8 library.properties
  8. +93 −221 src/MFRC522.cpp
  9. +145 −69 src/MFRC522.h
  10. +21 −21 src/MFRC522Extended.cpp
  11. +107 −0 src/MFRC522_i2c.cpp
  12. +117 −0 src/MFRC522_spi.cpp
  13. +75 −0 src/MFRC522_uart.cpp
  14. +14 −8 src/deprecated.h
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ Arduino library for MFRC522 and other RFID RC522 based modules.

Read and write different types of Radio-Frequency IDentification (RFID) cards
on your Arduino using a RC522 based reader connected via the Serial Peripheral
Interface (SPI) interface.
Interface (SPI) interface, the i2c interface or the UART.


.. _development:
@@ -348,7 +348,7 @@ It has been extended with functionality to alter sector 0 on Chinese UID changea

Maintained by miguelbalboa until 2016.
Maintained by Rotzbua from 2016 until 2018.

Updated b dirkx from mid 2018.

.. _arduino: https://arduino.cc/
.. _ebay: https://www.ebay.com/
5 changes: 5 additions & 0 deletions changes.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
-- Add changes to unreleased tag until we make a release.

28 March 2020, v1.5.0
- Added support for I2C and UART readers
- Added callback functions (so you do not need to poll)
- Addex examples for these callbacks.

27 Oct 2018, v1.4.3
- Added counterfeit detection and hint about bad boards
- Improved hardware based reset
84 changes: 84 additions & 0 deletions examples/Minimal-I2C/Minimal-I2C.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
--------------------------------------------------------------------------------------------------------------------
Example sketch/program 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/miguelbalboa/rfid
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+Shft+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.
@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 Due/Mega2560
Signal Pin Pin Pin Pin Pin Pin
-----------------------------------------------------------------------------------------
RST/Reset RST 9 5 D9 RESET/ICSP-5 23 9
scl CLK 5 5 3 22
sda SC 4 4 2 21
*/
#include <MFRC522.h>

constexpr uint8_t RST_PIN = 2; // Configurable, see typical pin layout above

// The default address of the MFRC522 is 0X3C -- specify it here if you
// have it configured differently (pull up/down pins on the chip).
//
// MFRC522_I2C mfrc522(RST_PIN, 0x28 /*, chipAddr */); // Create MFRC522 instance

TwoWire i2cBus = TwoWire(0);
MFRC522_I2C dev = MFRC522_I2C(RST_PIN, 0x28, i2cBus);
MFRC522 mfrc522 = MFRC522(dev);

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)

i2cBus.begin(5, 4, 400000);

mfrc522.PCD_Init(); // Init MFRC522
mfrc522.PCD_DumpVersionToSerial(); // Show details of PCD - MFRC522 Card Reader details

Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks..."));
}

void loop() {
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent()) {
return; // no card in sight.
}

// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
Serial.println("Bad read (was card removed too quickly?)");
return;
};

if ( mfrc522.uid.size == 0) {
Serial.println("Bad card read (size = 0)");
return;
}

char buff[sizeof(mfrc522.uid.uidByte)* 5] = { 0 };
for (int i = 0; i < mfrc522.uid.size; i++) {
char tag[5]; // 3 digits, dash and \0.
snprintf(buff, sizeof(buff), "%s%d", i ? "-" : "", mfrc522.uid.uidByte[i]);
strncat(buff, tag, sizeof(tag));
};
Serial.println("Good scan: ");
Serial.println(buff);

// disengage with the card.
//
mfrc522.PICC_HaltA();
}

102 changes: 102 additions & 0 deletions examples/Minimal-SPI/Minimal-SPI.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
--------------------------------------------------------------------------------------------------------------------
Example sketch/program 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/miguelbalboa/rfid
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+Shft+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
-----------------------------------------------------------------------------------------
RST/Reset RST 9 5 D9 RESET/ICSP-5 RST
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
*/

#include <SPI.h>
#include <MFRC522.h>

constexpr uint8_t RST_PIN = 32; // Configurable, see typical pin layout above
constexpr uint8_t SS_PIN = 15; // Configurable, see typical pin layout above

MFRC522_SPI spiDevice = MFRC522_SPI(SS_PIN, RST_PIN);
MFRC522 mfrc522 = MFRC522(spiDevice); // Create MFRC522 instance

// Specify the wiring/pins in more detail.
//
// MFRC522_SPI spiDevice = MFRC522_SPI(SS_PIN, RST_PIN, PIN_SCK, PIN_MISO, PIN_MOSI);
// MFRC522 mfrc522 = MFRC522(spiDevice);
//
// Or do much the same - but also specify the bus
//
// SPI spiBus = SPI(HSPI);
// spiBus.begin(PIN_SCK, PIN_MISO, PIN_MOSI);
// MFRC522_SPI spiDevice = MFRC522_SPI(SS_PIN, RST_PIN, spiBus);
// MFRC522 mfrc522 = MFRC522(spiDevice);
//
// And if neeed - also change the bus settings.
//
// SPI spiBus = SPI(HSPI);
// SPISettings spiSettings = SPISettings(SPI_CLOCK_DIV4, MSBFIRST, SPI_MODE0))
// MFRC522_SPI spiDevice = MFRC522_SPI(SS_PIN, RST_PIN, spiBus, spiBusSettings);
// MFRC522 mfrc522 = MFRC522(spiDevice);

void setup() {
Serial.begin(9600); // Initialize serial communications with the PC
while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)

SPI.begin(14, 12, 13);
mfrc522.PCD_Init(); // Init MFRC522
mfrc522.PCD_DumpVersionToSerial(); // Show details of PCD - MFRC522 Card Reader details
Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks..."));
}

void loop() {
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent()) {
return;
}

// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
Serial.println("Bad read (was card removed too quickly?)");
return;
}

if (mfrc522.uid.size == 0) {
Serial.println("Bad card (size = 0)");
} else {
char tag[sizeof(mfrc522.uid.uidByte) * 4] = { 0 };
for (int i = 0; i < mfrc522.uid.size; i++) {
char buff[5]; // 3 digits, dash and \0.
snprintf(buff, sizeof(buff), "%s%d", i ? "-" : "", mfrc522.uid.uidByte[i]);
strncat(tag, buff, sizeof(tag));
};
Serial.println("Good scan: ");
Serial.println(tag);
};

// disengage with the card.
//
mfrc522.PICC_HaltA();
}
48 changes: 48 additions & 0 deletions examples/rfid_uart/rfid_uart.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* This example simply changes the state of the LED_PIN based on a known tag code.
* This code uses the NodeMCU (ESP-12E) layout for pin assignment.
* Pin 16 is the LED next to the USB connector on the NodeMCU board.
* Pin 2 is a generic GPIO (used here for initialization of RFID module).
*/

#include <MFRC522.h>

// Sample tag (assuming four bytes)
byte TEST_TAG[] = { 0x11, 0xBC, 0x4A, 0x10 };

// Tested on NodeMCU (ESP-12E)
const unsigned RST_PIN = 2;
const unsigned LED_PIN = 16;
const unsigned long RFID_POLLING_PERIOD_MS = 100;
unsigned long lastTimestamp = 0;

MFRC522_UART mfrc522(Serial, RST_PIN);
MFRC522 rfid(&mfrc522);

void setup() {
pinMode(LED_PIN, OUTPUT);

// RFID
rfid.PCD_Init();
rfid.PCD_SetAntennaGain(MFRC522::RxGain_max);
}

void loop(){

unsigned long currentTimestamp = millis();
if ((currentTimestamp - lastTimestamp) > RFID_POLLING_PERIOD_MS) {
lastTimestamp = currentTimestamp;

if (rfid.PICC_IsNewCardPresent()) {
if (rfid.PICC_ReadCardSerial()) {

// Compares the code obtained from a tag with our TEST_TAG
if (memcmp(rfid.uid.uidByte, TEST_TAG, sizeof(TEST_TAG) / sizeof(byte)) == 0) {
digitalWrite(LED_PIN, HIGH);
} else {
digitalWrite(LED_PIN, LOW);
}
}
}
}
}
14 changes: 0 additions & 14 deletions library.json

This file was deleted.

16 changes: 8 additions & 8 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name=MFRC522
version=1.4.3
author=GithubCommunity
maintainer=GithubCommunity
sentence=Arduino RFID Library for MFRC522 (SPI)
paragraph=Read/Write a RFID Card or Tag using the ISO/IEC 14443A/MIFARE interface.
name=MFRC522-spi-i2c-uart-async
version=1.5.1
author=GithubCommunity,miguelbalboa,dirkx@webweaving.org
maintainer=GithubCommunity,dirkx@webweaving.org
sentence=Arduino RFID Library for MFRC522 (SPI, I2C and UART) with asynchroneous callbacks
paragraph=Read/Write a RFID Card or Tag using the ISO/IEC 14443A/MIFARE interface. Modified from the original miguelbalboa to also support I2C and UART connections and provide, in addition to normal constant polling, an option to do asynchroneous callbacks. I.e. have a function called each time that a valid swipe has happend. Used at the https://makerspaceleiden.nl.
category=Communication
url=https://github.com/miguelbalboa/rfid
architectures=avr,STM32F1,teensy,esp8266,samd
url=https://github.com/makerspaceleiden/rfid
architectures=avr,STM32F1,teensy,esp8266,samd,esp32
Loading