Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save alexey-bass/6b6e53e05d9a8d1468038ea78d536914 to your computer and use it in GitHub Desktop.
Save alexey-bass/6b6e53e05d9a8d1468038ea78d536914 to your computer and use it in GitHub Desktop.
/**
Useful links
https://wiki.wemos.cc/products:d1:d1_mini
https://cdn-images-1.medium.com/max/1400/1*YKc8KpAfMrlhrOLmNjdRwQ.png (D1 full pinout)
https://github.com/Jorgen-VikingGod/ESP8266-MFRC522
https://github.com/miguelbalboa/rfid
d1 mini rc52 wiring
https://discourse-cdn-sjc1.com/business5/uploads/mydevices/original/2X/e/ecedba79dc05f2c0b02b7fba8b3da2681590a11a.jpg
RST - D3
MISO - D6
MOSI - D7
SCK - D5
SDA - D8
*/
#include "ESP8266WiFi.h"
#include <SPI.h>
#include <MFRC522.h>
constexpr uint8_t RST_PIN = 0; // Configurable, see typical pin layout above 18
constexpr uint8_t SS_PIN = 15; // Configurable, see typical pin layout above 16
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
void setup() {
Serial.begin(74880); // Initialize serial communications with the PC
delay(1000);
Serial.println("Setup");
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
mfrc522.PCD_DumpVersionToSerial(); // Show details of PCD - MFRC522 Card Reader details
Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks..."));
Serial.println("Setup done");
}
void loop() {
// Serial.println("Loop...");
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent()) {
//delay(50);
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
//delay(50);
return;
}
// Show some details of the PICC (that is: the tag/card)
Serial.print(F("Card UID:"));
dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);
Serial.println();
// Dump debug info about the card; PICC_HaltA() is automatically called
//mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
delay(1000);
}
// Helper routine to dump a byte array as hex values to Serial
void dump_byte_array(byte *buffer, byte bufferSize) {
for (byte i = 0; i < bufferSize; i++) {
Serial.print(buffer[i] < 0x10 ? " 0" : " ");
Serial.print(buffer[i], HEX);
}
}
@cthulhu1988
Copy link

Thank you!! This is the only sketch I could get to work!

@alexey-bass
Copy link
Author

alexey-bass commented Mar 3, 2020

Thank you!! This is the only sketch I could get to work!

You welcome :-) I took me time too to find working solution

@ShaolinGardener
Copy link

I'm at a loss... I've tried 3 different boards (ESP32, ESP8266, and D1 MINI 8266) with 2 different IDEs (Arduino and PlatformIO) and a number of different pinouts. I either end up with a boot loop or a communication error such as this:
Firmware Version: 0xFF = (unknown)
WARNING: Communication failure, is the MFRC522 properly connected?
Scan PICC to see UID, SAK, type, and data blocks...
Setup done

I've literally copied and pasted your code into both IDEs and checked and rechecked the pins: Communication Failure.

Any help would be greatly appreciated.
PXL_20220403_145253644

@linaspasv
Copy link

@ShaolinGardener I am seeing a similar things too. Have you solved your issue? :-)

@alexey-bass
Copy link
Author

alexey-bass commented Oct 10, 2023

Sorry guys, I'm really not doing these projects anymore and can not help there.
I remember I had issues with cheap ESP boards and MFRC522, so I usually order 2 from different sellers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment