RC522 doesn't work on Aruino uno WiFi Rev2

Hello everyone!

It's been a couple of days that I've been trying to make the RC522 work on my Arduino uno WiFi Rev2, but with no success.

I connected the RFID module like this

without connecting the SDA pin because it is not specified in the above image.

Then I used the MFRC522.h library but it gives me several errors at compile time. I'll show you the example code that I'm using and then the errors that I get.

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

#define RST_PIN   9    // Configurable, see typical pin layout above
#define SS_PIN    10    // Configurable, see typical pin layout above

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


#define NEW_UID {0xDE, 0xAD, 0xBE, 0xEF}

MFRC522::MIFARE_Key key;

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 card
  Serial.println(F("Warning: this example overwrites the UID of your UID changeable card, use with care!"));
  
  for (byte i = 0; i < 6; i++) {
    key.keyByte[i] = 0xFF;
  }
}
void loop() {
  if ( ! mfrc522.PICC_IsNewCardPresent() || ! mfrc522.PICC_ReadCardSerial() ) {
    delay(50);
    return;
  }
  
  Serial.print(F("Card UID:"));
  for (byte i = 0; i < mfrc522.uid.size; i++) {
    Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
    Serial.print(mfrc522.uid.uidByte[i], HEX);
  }
  Serial.println();

  byte newUid[] = NEW_UID;
  if ( mfrc522.MIFARE_SetUid(newUid, (byte)4, true) ) {
    Serial.println(F("Wrote new UID to card."));
  }

  mfrc522.PICC_HaltA();
  if ( ! mfrc522.PICC_IsNewCardPresent() || ! mfrc522.PICC_ReadCardSerial() ) {
    return;
  }
  Serial.println(F("New UID and contents:"));
  mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
  
  delay(2000);
}
In file included from /home/mauro/Arduino/libraries/MFRC522/src/MFRC522.cpp:7:0:
/home/mauro/Arduino/libraries/MFRC522/src/MFRC522.cpp: In static member function 'static const __FlashStringHelper* MFRC522::GetStatusCodeName(MFRC522::StatusCode)':
/home/mauro/.arduino15/packages/arduino/hardware/megaavr/1.8.5/cores/arduino/Arduino.h:30:20: error: cannot convert 'const char*' to 'const __FlashStringHelper*' in return
 #define F(str) (str)
                    ^
/home/mauro/Arduino/libraries/MFRC522/src/MFRC522.cpp:1282:29: note: in expansion of macro 'F'
   case STATUS_OK:    return F("Success.");
                             ^
/home/mauro/.arduino15/packages/arduino/hardware/megaavr/1.8.5/cores/arduino/Arduino.h:30:20: error: cannot convert 'const char*' to 'const __FlashStringHelper*' in return
 #define F(str) (str)
                    ^
/home/mauro/Arduino/libraries/MFRC522/src/MFRC522.cpp:1283:31: note: in expansion of macro 'F'
   case STATUS_ERROR:   return F("Error in communication.");
                               ^
/home/mauro/.arduino15/packages/arduino/hardware/megaavr/1.8.5/cores/arduino/Arduino.h:30:20: error: cannot convert 'const char*' to 'const __FlashStringHelper*' in return
 #define F(str) (str)
                    ^
/home/mauro/Arduino/libraries/MFRC522/src/MFRC522.cpp:1284:34: note: in expansion of macro 'F'
   case STATUS_COLLISION:  return F("Collission detected.");
                                  ^
/home/mauro/.arduino15/packages/arduino/hardware/megaavr/1.8.5/cores/arduino/Arduino.h:30:20: error: cannot convert 'const char*' to 'const __FlashStringHelper*' in return
 #define F(str) (str)
                    ^
/home/mauro/Arduino/libraries/MFRC522/src/MFRC522.cpp:1285:32: note: in expansion of macro 'F'
   case STATUS_TIMEOUT:  return F("Timeout in communication.");
                                ^
/home/mauro/.arduino15/packages/arduino/hardware/megaavr/1.8.5/cores/arduino/Arduino.h:30:20: error: cannot convert 'const char*' to 'const __FlashStringHelper*' in return
 #define F(str) (str)
                    ^
/home/mauro/Arduino/libraries/MFRC522/src/MFRC522.cpp:1286:32: note: in expansion of macro 'F'
   case STATUS_NO_ROOM:  return F("A buffer is not big enough.");
                                ^
/home/mauro/.arduino15/packages/arduino/hardware/megaavr/1.8.5/cores/arduino/Arduino.h:30:20: error: cannot convert 'const char*' to 'const __FlashStringHelper*' in return
 #define F(str) (str)
                    ^
/home/mauro/Arduino/libraries/MFRC522/src/MFRC522.cpp:1287:38: note: in expansion of macro 'F'
   case STATUS_INTERNAL_ERROR: return F("Internal error in the code. Should not happen.");
                                      ^
/home/mauro/.arduino15/packages/arduino/hardware/megaavr/1.8.5/cores/arduino/Arduino.h:30:20: error: cannot convert 'const char*' to 'const __FlashStringHelper*' in return
 #define F(str) (str)
                    ^
/home/mauro/Arduino/libraries/MFRC522/src/MFRC522.cpp:1288:32: note: in expansion of macro 'F'
   case STATUS_INVALID:  return F("Invalid argument.");
                                ^
/home/mauro/.arduino15/packages/arduino/hardware/megaavr/1.8.5/cores/arduino/Arduino.h:30:20: error: cannot convert 'const char*' to 'const __FlashStringHelper*' in return
 #define F(str) (str)
                    ^
/home/mauro/Arduino/libraries/MFRC522/src/MFRC522.cpp:1289:34: note: in expansion of macro 'F'
   case STATUS_CRC_WRONG:  return F("The CRC_A does not match.");
                                  ^
/home/mauro/.arduino15/packages/arduino/hardware/megaavr/1.8.5/cores/arduino/Arduino.h:30:20: error: cannot convert 'const char*' to 'const __FlashStringHelper*' in return
 #define F(str) (str)
                    ^
/home/mauro/Arduino/libraries/MFRC522/src/MFRC522.cpp:1290:35: note: in expansion of macro 'F'
   case STATUS_MIFARE_NACK: return F("A MIFARE PICC responded with NAK.");
                                   ^
/home/mauro/Arduino/libraries/MFRC522/src/MFRC522.cpp:1291:23: error: cannot convert 'const char*' to 'const __FlashStringHelper*' in return
   default:     return "Unknown error");
                       ^~~~~~~~~~~~~~~
/home/mauro/Arduino/libraries/MFRC522/src/MFRC522.cpp:1291:38: error: expected ';' before ')' token
   default:     return "Unknown error");
                                      ^
/home/mauro/Arduino/libraries/MFRC522/src/MFRC522.cpp:1291:38: error: expected primary-expression before ')' token
In file included from /home/mauro/Arduino/libraries/MFRC522/src/MFRC522.cpp:7:0:
/home/mauro/Arduino/libraries/MFRC522/src/MFRC522.cpp: In static member function 'static const __FlashStringHelper* MFRC522::PICC_GetTypeName(MFRC522::PICC_Type)':
/home/mauro/.arduino15/packages/arduino/hardware/megaavr/1.8.5/cores/arduino/Arduino.h:30:20: error: cannot convert 'const char*' to 'const __FlashStringHelper*' in return
 #define F(str) (str)
                    ^

Multiple libraries were found for "SPI.h"
 Used: /home/mauro/.arduino15/packages/arduino/hardware/megaavr/1.8.5/libraries/SPI
Multiple libraries were found for "MFRC522.h"
 Used: /home/mauro/Arduino/libraries/MFRC522
exit status 1
Error compiling for board Arduino Uno WiFi Rev2.

I don't really know how to solve it, please someone help me, I'm going crazy

spike32:
without connecting the SDA pin because it is not specified in the above image.

I believe the pin marked "SDA" on the module acts as the SS pin when you're using SPI communication, which you are. So you need to connect the pin marked "SDA" on the module to the pin you have set as SS_PIN in your sketch.

Of course, that's not the cause of the compilation error. This error is caused by a bug in the Arduino megaAVR Boards core library:

Although it's not the ideal fix, I was able to solve the error by making the change described here:

Here's how you can do it:

Open /home/mauro/.arduino15/packages/arduino/hardware/megaavr/1.8.5/cores/arduino/Arduino.h in a text editor. Note that your file browser software might be configure to hide the .arduino folder by default.

At line 31, add the following:

#define __FlashStringHelper char

Save the file.

pert:
I believe the pin marked "SDA" on the module acts as the SS pin when you're using SPI communication, which you are. So you need to connect the pin marked "SDA" on the module to the pin you have set as SS_PIN in your sketch.

Of course, that's not the cause of the compilation error. This error is caused by a bug in the Arduino megaAVR Boards core library:
F() Flash Macro No Longer Recognized · Issue #62 · arduino/ArduinoCore-megaavr · GitHub

Although it's not the ideal fix, I was able to solve the error by making the change described here:
F() Flash Macro No Longer Recognized · Issue #62 · arduino/ArduinoCore-megaavr · GitHub

Here's how you can do it:

Open /home/mauro/.arduino15/packages/arduino/hardware/megaavr/1.8.5/cores/arduino/Arduino.h in a text editor. Note that your file browser software might be configure to hide the .arduino folder by default.

At line 31, add the following:

#define __FlashStringHelper char

Save the file.

Thank you very much, you saved me! Now it works properly

You're welcome. I'm glad to hear it's working now. Enjoy!
Per