GithubHelp home page GithubHelp logo

osslibraries / arduino_mfrc522v2 Goto Github PK

View Code? Open in Web Editor NEW
85.0 4.0 34.0 2.47 MB

Home Page: https://osslibraries.github.io/Arduino_MFRC522v2/

License: GNU Lesser General Public License v2.1

C++ 100.00%

arduino_mfrc522v2's Introduction

Arduino_MFRC522v2

image GitHub Actions - Arduino Compile Examples GitHub Actions - Arduino Lint image Releases image

Advanced Arduino driver 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) or I2C interface.

Hints for this version

  • Fork of https://github.com/miguelbalboa/rfid/
  • Changed license to GNU LESSER GENERAL PUBLIC LICENSE, Version 2.1.
  • Target group are experienced makers.
  • Code was heavily split up for better maintenance.
  • Hardware interface is fully customisable.
  • Use of software reset. No reset pin.
  • Some parts were removed.

Development

Feature status: open; focus on rfid; no applications;

Code status: open; fixes/typos or documentation updates; no specific code for other boards; avoid examples;

Maintenance status: sporadically;

Before buy

Please notice that there are many sellers (ebay, aliexpress, ...) who sell MFRC522 boards. The quality of these boards are extremely different. Some are soldered with wrong/low quality capacitors or fake/defect MFRC522.

Please consider buying several devices from different suppliers. So the chance of getting a working device is higher.

If you got a bad board and you can tell us how to detect those boards (silk, chip description, ...), please share your knowledge.

What works and not?

  • Works

    • Communication (Crypto1) with MIFARE Classic (1k, 4k, Mini).
    • Communication (Crypto1) with MIFARE Classic compatible PICCs.
    • Firmware self check of MFRC522.
    • Set the UID, write to sector 0, and unbrick Chinese UID changeable MIFARE cards.
    • Manage the SPI chip select pin (aka SS, SDA):
  • Works partially

    • Communication with MIFARE Ultralight.
    • Other PICCs (Ntag216).
    • More than 2 modules, require a multiplexer #191.
  • Doesn't work

    • MIFARE DESFire, MIFARE DESFire EV1/EV2, not supported by software.
    • Communication with 3DES or AES, not supported by software.
    • Peer-to-peer (ISO/IEC 18092), not supported by hardware.
    • Communication with smartphone, not supported by hardware.
    • Card emulation, not supported by hardware.
    • Use of IRQ pin. But there is a proof-of-concept example.
    • With Intel Galileo (Gen2) see #310, not supported by software.
    • Power reduction modes #269, not supported by software.
    • UART instead of SPI #281, not supported by software.
  • Need more?

    • If software: code it and make a pull request.
    • If hardware: buy a more expensive like PN532 (supports NFC and many more, but costs about $15 and not usable with this library).

Compatible IDE

This library works with Arduino IDE 1.6, older versions are not supported and will cause compiler errors. The built-in library manager is supported.

If you use your own compiler, you have to enable c++11-support.

Compatible boards

This library is compatible with boards implementing the Arduino-API. You also have to change pins. See pin layout.

Some user made some patches/suggestions/ports for other boards:

Support/issue

  1. First checkout what works and not and troubleshooting .

  2. It seems to be a hardware issue or you need support to program your project? Please ask in the official Arduino forum, where you would get a much faster answer than on GitHub.

  3. It seems to be a software issue? Open an issue on GitHub.

Code style

Please use fixed integers, see stdint.h. Why? This library is compatible with different boards which use different architectures (16bit and 32bit). Unfixed int variables have different sizes in different environments and may cause unpredictable behaviour.

Pin Layout

The following tables show the typical pin layout used.

Notes:

  • The SDA pin on the MFRC522 might be labeled as SS.
  • RST pin of the microcontroller-board is configurable, typically defined as RST_PIN in sketch/program.
  • SDA pin of the microcontroller-board is configurable, typically defined as SS_PIN in sketch/program.
  • Important: If your microcontroller supports multiple SPI interfaces, the library only uses the default (first) SPI of the Arduino framework.

Arduino

Signal MFRC522 Uno / 101 Mega Nano v3 Leonardo / Micro Pro Micro Yun
RST/Reset RST 9 5 D9 RESET / ICSP-5 RST Pin9
SPI SS SDA 10 53 D10 10 10 Pin10
SPI MOSI MOSI 11 / ICSP-4 51 D11 ICSP-4 16 ICSP4
SPI MISO MISO 12 / ICSP-1 50 D12 ICSP-1 14 ICSP1
SPI SCK SCK 13 / ICSP-3 52 D13 ICSP-3 15 ICSP3

ESP8266

Signal MFRC522 Wemos D1 mini
RST/Reset RST D3
SPI SS SDA D8
SPI MOSI MOSI D7
SPI MISO MISO D6
SPI SCK SCK D5

ESP32

Signal MFRC522 WROOM-32
RST/Reset RST 21
SPI SS SDA 5
SPI MOSI MOSI 23
SPI MISO MISO 19
SPI SCK SCK 18

Teensy

Signal MFRC522 2.0 ++2.0 3.1
RST/Reset RST 7 4 9
SPI SS SDA 0 20 10
SPI MOSI MOSI 2 22 11
SPI MISO MISO 3 23 12
SPI SCK SCK 1 21 13

Hardware

There are three hardware components involved:

  • Microcontroller

    • An Arduino or compatible executing the Sketch using this library.
    • Prices vary from USD 7 for clones, to USD 75 for "starter kits" (which might be a good choice if this is your first exposure to Arduino; check if such kit already includes the Arduino, Reader, and some Tags).
  • Proximity Coupling Device (PCD)

    • The PCD is the actual RFID Reader based on the NXP MFRC522 Contactless Reader Integrated Circuit.
    • Readers can be found on many online stores for around USD 5: search for "rc522".
    • You can also find them on several web stores. They are often included in "starter kits", so check your favourite electronics provider as well.
  • Proximity Integrated Circuit Card (PICC)

    • The PICC is the RFID Card or Tag using the ISO/IEC 14443A interface, for example Mifare or NTAG203.
    • One or two might be included with the Reader or "starter kit" already.

Protocols

  • The microcontroller and the reader use SPI for communication.

    • The protocol is described in the NXP MFRC522 datasheet.
    • See the Pin Layout section for details on connecting the pins.
  • The reader and the tags communicate using a 13.56 MHz electromagnetic field.

    • The protocol is defined in ISO/IEC 14443-3:2011 Part 3 Type A.
      • Details are found in chapter 6 "Type A – Initialization and anticollision".
      • See https://wg8.de/wg8n1496_17n3613_Ballot_FCD14443-3.pdf for a free version of the final draft (which might be outdated in some areas).
      • The reader does not support ISO/IEC 14443-3 Type B.

Security

  • The UID of a card can not be used as a unique identification for security related projects. Some Chinese cards allow to change the UID which means you can easily clone a card. For projects like access control, door opener or payment systems you must implement an additional security mechanism like a password or normal key.

  • This library only supports crypto1-encrypted communication. Crypto1 has been known as broken for a few years, so it does NOT offer ANY security, it is virtually unencrypted communication. Do not use it for any security related applications!

  • This library does not offer 3DES or AES authentication used by cards like the Mifare DESFire, it may be possible to be implemented because the datasheet says there is support. We hope for pull requests :).

Troubleshooting

  • I don't get input from reader or WARNING: Communication failure, is the MFRC522 properly connected?

    • Check your physical connection, see Pin Layout.
    • Check your pin settings/variables in the code, see Pin Layout.
    • Check your pin header soldering. Maybe you have cold solder joints.
    • Check voltage. Most breakouts work with 3.3V.
    • SPI only works with 3.3V, most breakouts seem 5V tolerant, but try a level shifter.
    • SPI does not like long connections. Try shorter connections.
    • SPI does not like prototyping boards. Try soldered connections.
    • According to reports #101, #126 and #131, there may be a problem with the soldering on the MFRC522 breakout. You could fix this on your own.
  • Firmware Version: 0x12 = (unknown) or other random values.

    • The exact reason of this behaviour is unknown.
    • Some boards need more time after PCD_Init() to be ready. As workaround add a delay(4) directly after PCD_Init() to give the PCD more time.
    • If this sometimes appears, a bad connection or power source is the reason.
    • If the firmware version is reported permanent, it is very likely that the hardware is a fake or has a defect. Contact your supplier.
  • Sometimes I get timeouts or sometimes tag/card does not work.

    • Try the other side of the antenna.
    • Try to decrease the distance between the MFRC522 and your tag.
    • Increase the antenna gain per firmware: MFRC522.PCD_SetAntennaGain(MFRC522.RxGain_max);.
    • Use better power supply.
    • Hardware may be corrupted, most products are from China and sometimes the quality is really poor. Contact your seller.
  • My tag/card doesn't work.

    • Distance between antenna and token too large (>1cm).
    • You got the wrong type PICC. Is it really 13.56 MHz? Is it really a Mifare Type A?
    • NFC tokens are not supported. Some may work.
    • Animal RFID tags are not supported. They use a different frequency (125 kHz).
    • Hardware may be corrupted, most products are from China and sometimes the quality is really poor. Contact your seller.
    • Newer versions of Mifare cards like DESFire/Ultralight maybe not work according to missing authentication, see security or different protocol.
    • Some boards bought from Chinese manufactures do not use the best components and this can affect the detection of different types of tag/card. In some of these boards, the L1 and L2 inductors do not have a high enough current so the signal generated is not enough to get Ultralight C and NTAG203 tags to work, replacing those with same inductance (2.2uH) but higher operating current inductors should make things work smoothly. Also, in some of those boards the harmonic and matching circuit needs to be tuned, for this replace C4 and C5 with 33pf capacitors and you are all set. (Source: Mikro Elektronika)
  • My mobile phone doesn't recognize the MFRC522 or my MFRC522 can't read data from other MFRC522.

    • Card simulation is not supported.
    • Communication with mobile phones is not supported.
    • Peer to peer communication is not supported.
  • I can only read the card UID.

    • Maybe the AccessBits have been accidentally set and now an unknown password is set. This can not be reverted.
    • Probably the card is encrypted. Especially official cards like public transport, university or library cards. There is no way to get access with this library.
  • I need more features.

    • If software: code it and make a pull request.
    • If hardware: buy a more expensive chip like the PN532 (supports NFC and many more, but costs about $15).

License

GNU LESSER GENERAL PUBLIC LICENSE, Version 2.1.

It is not allowed to change the license.

Dependency

  • Arduino.h

    • From: Arduino IDE / target specific
    • License: (target: Arduino) GNU Lesser General Public License 2.1
  • SPI.h

    • From: Arduino IDE / target specific
    • License: (target: Arduino) GNU Lesser General Public License 2.1
  • stdint.h

    • From: Arduino IDE / Compiler and target specific
    • License: different

History

The MFRC522 library was first created in Jan 2012 by Miguel Balboa (from http://circuitito.com) based on code by Dr. Leong (from http://B2CQSHOP.com) for "Arduino RFID module Kit 13.56 Mhz with Tags SPI W and R By COOQRobot".

It was translated into English and rewritten/refactored in the fall of 2013 by Søren Thing Andersen (from http://access.thing.dk).

It has been extended with functionality to alter sector 0 on Chinese UID changeable MIFARE card in Oct 2014 by Tom Clement (from http://tomclement.nl).

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

arduino_mfrc522v2's People

Contributors

aiolos avatar anistor avatar asomov avatar cuthbertnibbles avatar danielcbit avatar denisvm avatar dependabot[bot] avatar eckankar avatar gargantuanman avatar gpancot avatar grapheo12 avatar heziegl avatar ivankravets avatar mayatforest avatar mdxs avatar miguelbalboa avatar nicolacoppola avatar omersiar avatar randptr avatar ricardojlrufino avatar rotzbua avatar seisfeld avatar sophiekovalevsky avatar sthing avatar surr avatar tjclement avatar tonycallear avatar tuyethoa08041997 avatar unknown-consortium avatar wa4osh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

arduino_mfrc522v2's Issues

Document generation broken by latest `sphinx` 7.2.x

sphinx 7.2.x removed a helper function which is used by extensions.

Solution

Stay with 7.1.x.

References

breathe-doc/breathe#943

https://github.com/svenevs/exhale/issues

Logoutput

 /opt/hostedtoolcache/Python/3.11.4/x64/lib/python3.11/site-packages/breathe/project.py:116: RemovedInSphinx80Warning: Sphinx 8 will drop support for representing paths as strings. Use "pathlib.Path" or "os.fspath" instead.
  self._default_build_dir = os.path.dirname(app.doctreedir.rstrip(os.sep))
making output directory... done
/opt/hostedtoolcache/Python/3.11.4/x64/lib/python3.11/site-packages/exhale/configs.py:1408: RemovedInSphinx80Warning: Sphinx 8 will drop support for representing paths as strings. Use "pathlib.Path" or "os.fspath" instead.
  _one     = containmentFolder == app.srcdir

Extension error (exhale):
Handler <function environment_ready at 0x7f7e45f46840> for event 'builder-inited' threw an exception (exception: startswith first arg must be str or a tuple of str, not _StrPath)
make: *** [Makefile:20: html] Error 2

Communication failure with MFRC522v2, but the original MFRC522 had no such issues

I'm trying to read Mifare Classic 1K cards using Seeeduino Lotus. It works with the original https://github.com/miguelbalboa/rfid library, detecting the card and showing its UID.

However, when I try MFRC522v2 version 2.0.4 and use the sample code from the documentation, it shows:

= (unknown)
WARNING: Communication failure, is the MFRC522 properly connected?
Scan PICC to see UID, SAK, type, and data blocks...

Note that the wiring is exactly the same in both cases, with the default pins being used, as specified in the documentation. If I upload back the original sketch, it works.

I noticed that the example from the original MFRC522 library specifies both the SPI SS pin and the reset pin like this:

#define RST_PIN 9
#define SS_PIN 10

however the example from has only the SS pin specified:

MFRC522DriverPinSimple ss_pin(10);

Is this the issue? How do I tell what's the reset pin?

PICC does not recover from HALT

Step 1: Describe your environment

  • OS version: windows 10
  • Arduino IDE version: platformio
  • MFRC522 Library version: master
  • Arduino device: esp32
  • MFRC522 device: version 0x92 = v2.0

Step 2: Describe the problem

Affected file(s) or example(s):

This affects at least:

  • ChangeUID.ino

May affect other examples, i did not check

Steps to reproduce:

  1. run the code
  2. the card does not recover and read back the new uid (even though it is changed) as long as it stays in the field

Observed Results:

Expected Results:

  • It should reset and read back the new UID

Relevant Code:

Consider also this other example, where it fails to read the card for the second time:

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."));
  
}

void loop() {

  delay(2000);
  
  // 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() ) {
    Serial.println("first read failed");
    return;
  } 
    Serial.println("first read successful");
  
  delay(100);

  Serial.println(mfrc522.PICC_HaltA() == MFRC522::StatusCode::STATUS_OK ? "halt successful" : "halt failed");


  delay(100);

  // i even try to wake it up and it succeeds
  byte bufferATQA[10];
  byte bufferSizeATQA = sizeof(bufferATQA);
  if(mfrc522.PICC_WakeupA(bufferATQA, &bufferSizeATQA) != MFRC522::StatusCode::STATUS_OK) {
    Serial.println("wakeup failed");
    return;
  }
    Serial.println("wakeup successful");
        
    
  bool isnewcardpresentstatus =  mfrc522.PICC_IsNewCardPresent();
  Serial.println(isnewcardpresentstatus ? "new card present" : "no new card present");

  bool readcardstatus = mfrc522.PICC_ReadCardSerial();
  Serial.println(readcardstatus ? "read card serial successful" : "read card serial failed");

   if ( !isnewcardpresentstatus || !readcardstatus ) {
    Serial.println("second read failed");
    return;
  }
    Serial.println("second read successful");
  
}

Console output:

first read successful
halt successful
wakeup successful
no new card present
read card serial failed
second read failed 

Issue while reading RFID and detect removal

Step 1: Describe your environment

  • OS version: N/A
  • Arduino IDE version: 2.2.1
  • MFRC522 Library version: 2.0.4
  • Arduino device: UNO
  • MFRC522 device: Standard blue card?

The Arduino was tested with VIN on 5V and then VIN on 10V. It's powered by VIN.

Step 2: Describe the problem

Affected file(s) or example(s):

#include <MFRC522v2.h>
#include <MFRC522DriverSPI.h>
#include <MFRC522DriverPinSimple.h>
#include <MFRC522Debug.h>

#define ENABLE_SERIAL
#define SS_PIN 10
#define RST_PIN 9
#define SIGNAL_PIN 7 // To propagate information to firmata arduino High is Valid medal detected Low otherwise
#define REFRESH_DELAY 500

byte MedalID[4] = {0x13, 0x76, 0x8E, 0x31}; // The ID to check for the medal
bool cardRemoved = false;
int counter = 0;
bool current, previous;

MFRC522DriverPinSimple ss_pin(10);
MFRC522DriverSPI driver{ss_pin};
MFRC522 mfrc522{driver};

void setup()
{
#ifdef ENABLE_SERIAL
  // Init RS232
  Serial.begin(115200);
  Serial.println("Initialization");
#endif

  // Init SPI bus
  SPI.begin();

  // Init MFRC522
  mfrc522.PCD_Init();

  // Init signal gate
  pinMode(SIGNAL_PIN, OUTPUT);
  pinMode(A0, OUTPUT);
  digitalWrite(SIGNAL_PIN, LOW);
}

void loop()
{
  blinkLED();
  // Look for new cards
  if (!mfrc522.PICC_IsNewCardPresent())
  {
#ifdef ENABLE_SERIAL
    Serial.println("Skipping, no new card present.");
#endif
    return;
  }
  if (!mfrc522.PICC_ReadCardSerial())
  {
#ifdef ENABLE_SERIAL
    Serial.println("Skipping, unable to read card.");
#endif
    return;
  }

#ifdef ENABLE_SERIAL
  Serial.print("New RFID detected : ");
  PrintHex(mfrc522.uid.uidByte, mfrc522.uid.size);
  Serial.println("");
#endif

  digitalWrite(SIGNAL_PIN, VerifyRFID(MedalID, mfrc522.uid.uidByte) ? HIGH : LOW);

  // Check if Card was removed
  cardRemoved = false;
  counter = 0;

  previous = !mfrc522.PICC_IsNewCardPresent();

  while (!cardRemoved)
  {
    current = !mfrc522.PICC_IsNewCardPresent();

    if (current && previous)
      counter++;

    previous = current;
    cardRemoved = (counter > 2);
  }

#ifdef ENABLE_SERIAL
  Serial.println("RFID was removed");
#endif
  digitalWrite(SIGNAL_PIN, LOW);
  mfrc522.PICC_HaltA();
}

bool VerifyRFID(byte *RequiredID, byte *CheckedID)
{
  if ((RequiredID[0] == CheckedID[0]) && (RequiredID[1] == CheckedID[1]) && (RequiredID[2] == CheckedID[2]) && (RequiredID[3] == CheckedID[3]))
    return true;
  else
    return false;
}

#ifdef ENABLE_SERIAL
void PrintHex(uint8_t *data, uint8_t length) // prints 8-bit data in hex with leading zeroes
{
  char tmp[16];
  for (int i = 0; i < length; i++)
  {
    sprintf(tmp, "0x%.2X", data[i]);
    Serial.print(tmp);
    Serial.print(" ");
  }
}
#endif

const int ledPin = A0;            // The pin the LED is connected to
int ledState = LOW;               // Tracks the state of the LED
unsigned long previousMillis = 0; // Will store last time LED was updated
const long interval = 1000;       // Interval at which the LED should blink (milliseconds
void blinkLED()
{
  unsigned long currentMillis = millis(); // Get the current time

  if (currentMillis - previousMillis >= interval)
  {
    // Save the last time the LED blinked
    previousMillis = currentMillis;

    if (ledState == LOW)
    {
      ledState = HIGH; // If the LED is off, turn it on
    }
    else
    {
      ledState = LOW; // If the LED is on, turn it off
    }

    digitalWrite(ledPin, ledState); // Apply the LED state
  }
}

Observed Results:

The above code is working well but after some time (in minutes, hard to guess) seems to always return a LOW signal on SIGNAL_PIN. I added some test code with a blinking LED to detect whether it's stuck on the while clause or elsewhere. It seems that it's stuck after some time on if (!mfrc522.PICC_IsNewCardPresent()) as the LED keeps blinking, no matter if I move or not the RFID close to the sensor. When I restart the Arduino, things work again.

EDIT:
After some investigation, it looks like if it stays too long in the while loop, it goes back to the start of the loop function and never quits isNewCardPresent condition resulting in LOW signal
EDIT2: : Even out of the while loop (when a card is present waiting for removal), it goes into LOW signal

Expected Results:

When an RFID is read and as long it's not removed, I want to put my SIGNAL_PIN to HIGH. When it's removed or when the ID doesn't match my MedalID I want the SIGNAL_PIN to be low.

I don't like the way I'm forced to check card removal, and this random isNewCardPresent returning value is really annoying.

Am I supposed to use PICC_HaltA somewhere else ? Adding some pause time like 150 ms at begin of the loop doesn't seem to change the problem

MKR GSM 1400 not work with RFID - RC522

Background:
I'm new to Arduino and I was having trouble setting up the Arduino MKR GSM 1400 to read the RC522 reader using the MFRC522 library. I wanted to leave this issue as a guide for anyone trying to configure the board.

Using the following guide I was able to set it up: https://www.hackster.io/Ajay_Vishaal/the-protector-bce054

Pin Diagram:
Screenshot 2023-08-15 211650

Dump Info program:

/*
 * --------------------------------------------------------------------------------------------------------------------
 * 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
 *
 * More pin layouts for other boards can be found here: https://github.com/miguelbalboa/rfid#pin-layout
 */

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

#define SS_PIN A6 // Configurable, see typical pin layout above
#define RST_PIN 7 // Configurable, see typical pin layout above

MFRC522 mfrc522(SS_PIN, RST_PIN);  // Create MFRC522 instance

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();			// Init SPI bus
	mfrc522.PCD_Init();		// Init MFRC522
	delay(4);				// Optional delay. Some board do need more time after init to be ready, see Readme
	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() {
	// 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
	mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
}

Not working with arduino pro mini

Step 1: Describe your environment

  • OS version: windows 11
  • Arduino IDE version: latest
  • MFRC522 Library version: latest
  • Arduino device: arduino pro mini 3.3v
  • MFRC522 device: RFID-RC522

Step 2: Describe the problem

I have an Arduino pro mini and it says: WARNING: Communication failure, is the MFRC522 properly connected?
My wiring is such as of an Arduino nano since NO PIN LAYOUTS FOR MINI HAS BEEN DOCUMENTED!

Steps to reproduce:

  1. Get an Arduino pro mini
  2. Try connecting it!

Observed Results:

  • WARNING: Communication failure, is the MFRC522 properly connected?

Relevant Code:

  /*
 * ------------------------------------------------------------------------------------------------------------------
 * 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+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
 * -----------------------------------------------------------------------------------------
 * 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(9600);  // 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.
  delay(4);
  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));
}

Pulling additional "Digital self test" references

What is the best way for me to pull the FIFO buffer contents of the self test, so I can submit them as a pull request? I have boards which report 0x92 and 0xB2, both of which appear to read cards successfully, but both fail the digital self test.

The ICs on my three boards (qty 2 0xB2, qty 1 0x92) all look the same with a single "pin one" dot and no other markings. The PCB of 0x92 is a bit lighter blue color than the 0xB2

Aside: One of the boards I received didn't read any cards and I noticed one of the inductors had fallen off the board...
IMG_20230209_130344_442

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.