Hi everyone,
Was anybody been able to connect a MFRC522 Rfid/NFC module on XIAO ESP32C3?
Been trying without lucky
Hi everyone,
Was anybody been able to connect a MFRC522 Rfid/NFC module on XIAO ESP32C3?
Been trying without lucky
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 PJ
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 PJ
If you could post the Compiler output first 5 lines, Last 20 b4 upload. We can narrow it down further.
Hi
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
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.
HTH
GL PJ
Hi, I did copy Danielpās configuration, but I am having trouble getting to work.
/*
#include <SPI.h>
#include <MFRC522.h>
#define SPI_MOSI 6
#define SPI_MISO 5
#define SPI_SCK 4
#define SS 7 //
#define SS_PIN 7
#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,
and welcome hereā¦
So looking at your code, You should edit the post and use the code tags above ā</>ā paste it in there , makes it easier to read and you will get better help also. That being said , I see the same issue the WRONG pins are defined change them to match what I posted and it should work. Also it is good practise in your code to print what it thinks the pins are with some print statements, ie.
pinMode(fspi->pinSS(), OUTPUT); //VSPI SS
pinMode(hspi->pinSS(), OUTPUT); //HSPI SS
digitalWrite(SS, HIGH); // <-- Set CS pin HIGH to deselect
Serial.println("--------------");
Serial.println(SS);
Serial.println(MOSI); // master out, slave in
Serial.println(MISO); // master in, slave out
Serial.println(SCK); // clock
Serial.println("--------------");
HTH
GL PJ
ie, should be ā¦ this
#include <SPI.h>
#include <MFRC522.h>
#define SPI_MOSI 10
#define SPI_MISO 9
#define SPI_SCK 8
#define SS 20 // I like 3, 4, 5 GPIO's
#define SS_PIN 7
#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");
Serial.println();
Serial.println("--------------");
Serial.println(SS);
Serial.println(MOSI); // master out, slave in
Serial.println(MISO); // master in, slave out
Serial.println(SCK); // clock
Serial.println("--------------");
}
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
}
}
}
try that