MFRC522 on XIAO ESP32C3

Hi everyone,

Was anybody been able to connect a MFRC522 Rfid/NFC module on XIAO ESP32C3?

Been trying without lucky :frowning:

Hi there,
And Welcome…
Can you post the Code your using we can suggest some edits.
Probably the CS for the SPI interface
HTH
GL :slight_smile: PJ

1 Like

Hi @PJ_Glasso , here it is

/*
 * This ESP32 code is created by esp32io.com
 *
 * This ESP32 code is released in the public domain
 *
 * For more detail (instruction and wiring diagram), visit https://esp32io.com/tutorials/esp32-rfid-nfc
 */

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

#define SS_PIN  6
#define RST_PIN 2

MFRC522 rfid(SS_PIN, RST_PIN);

void setup() {
  Serial.begin(9600);
  SPI.begin(); // init SPI bus
  rfid.PCD_Init(); // init MFRC522

  Serial.println("Tap an RFID/NFC tag on the RFID-RC522 reader");
}

void loop() {
  if (rfid.PICC_IsNewCardPresent()) { // new tag is available
    if (rfid.PICC_ReadCardSerial()) { // NUID has been readed
      MFRC522::PICC_Type piccType = rfid.PICC_GetType(rfid.uid.sak);
      Serial.print("RFID/NFC Tag Type: ");
      Serial.println(rfid.PICC_GetTypeName(piccType));

      // print UID in Serial Monitor in the hex format
      Serial.print("UID:");
      for (int i = 0; i < rfid.uid.size; i++) {
        Serial.print(rfid.uid.uidByte[i] < 0x10 ? " 0" : " ");
        Serial.print(rfid.uid.uidByte[i], HEX);
      }
      Serial.println();

      rfid.PICC_HaltA(); // halt PICC
      rfid.PCD_StopCrypto1(); // stop encryption on PCD
    }
  }
}

Hi there,
OK, I can try it, Which LIB are you using ,there are SEVERAL…?
can you add this SNIP to yours and find out which pins it thinks are sp & CS

 Serial.println("--------------");
 Serial.print("MOSI: ");
  Serial.println(MOSI);
  Serial.print("MISO: ");
  Serial.println(MISO);
  Serial.print("SCK: ");
  Serial.println(SCK);
  Serial.print("SS: ");
  Serial.println(SS);  
 Serial.println("--------------");

HTH
GL :slight_smile: PJ

If you could post the Compiler output first 5 lines, Last 20 b4 upload. We can narrow it down further. :v:

1 Like

Hi :slight_smile:

I’m using the MFRC522 lib

00:13:04.238 -> 
00:13:04.238 -> MOSI: 6
00:13:04.238 -> MISO: 5
00:13:04.238 -> SCK: 4
00:13:04.238 -> SS: 7
00:13:04.238 -> --------------

It’s working now, thank you so much :pray:

Hi there,
Great , Mark it as the solution so others can find it… Good troubleshooting ,You see the pins are NOT the correct ones, Use some define’s in the code for the right pins. Your picture is wired correctly I see…LOL and it will work.

#define SPI_MOSI  10
#define SPI_MISO  9
#define SPI_SCK   8
#define SS 3 // any GPIO can be used , I like to stay with the D3, D4, D5, I stay away from the D1 and D0 often they are used elsewhere and effect the Boot loader mode.

image

HTH
GL :slight_smile: PJ

1 Like