Use this forum to chat about hardware specific topics for the ESP8266 (peripherals, memory, clocks, JTAG, programming)

User avatar
By nikxha
#20269 Hi all,

for me this was really simple:
(Description here: https://github.com/esp8266/Arduino)
Download the Arduino IDE (1.6.4), put in http://arduino.esp8266.com/package_esp8 ... index.json to "Additional Boards Manager URLs"-Field then under Boards Manager choose esp8266...and install...
After that you can choose esp8266-Module as the Board.

Now download from https://github.com/miguelbalboa/rfid the library (you just need MFRC522.h and MFRC522.cpp). Put both into the folder of your Project and load them in your code with : #include "MFRC522.h"

Here is how I connected the Pins:
---------------------------------------------------------------------------------------------------------
* MFRC522 esp8266
* -----------------------------------------------------------------------------------------------------------
*RST GPIO15
*SDA(SS) GPIO2
*MOSI GPIO13
*MISO GPIO12
*SCK GPIO14
*GND GND
*3,3V 3,3V
* -----------------------------------------------------------------------------------------------------------
With this small example you should be able to connect to your WiFi Network and read a Rfid-Card (Output of the UID of the Card check on Serial):

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

#define RST_PIN 15 // RST-PIN für RC522 - RFID - SPI - Modul GPIO15
#define SS_PIN 2 // SDA-PIN für RC522 - RFID - SPI - Modul GPIO2

const char *ssid = "mySSID"; // change according to your Network - cannot be longer than 32 characters!
const char *pass = "myWLanPassword"; // change according to your Network

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

void setup() {
Serial.begin(9600); // Initialize serial communications
delay(250);
Serial.println(F("Booting...."));

SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522

WiFi.begin(ssid, pass);

int retries = 0;
while ((WiFi.status() != WL_CONNECTED) && (retries < 10)) {
retries++;
delay(500);
Serial.print(".");
}
if (WiFi.status() == WL_CONNECTED) {
Serial.println(F("WiFi connected"));
}

Serial.println(F("Ready!"));
Serial.println(F("======================================================"));
Serial.println(F("Scan for Card and print UID:"));
}

void loop() {
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent()) {
delay(50);
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
delay(50);
return;
}
// Dump debug info about the card; PICC_HaltA() is automatically called
mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
Serial.println(F("======================================================"));
}
(Most of the code found around the web.... so feel free to comment or to adapt to your needs)

BR
nikxha
User avatar
By tegila
#24438 Hi @nikxha,

Are you sure your code is fully working?
I did a try with two ESP8266 ESP-12 + RFID-RC522 but they are producing the error as described below:
Code: Select all0�~?�4�!�Y�$��2:����OAE�a��$��c���Booting....
..........Ready!
======================================================
Scan for Card and print UID:
Card UID: F7 22 CC 25
PICC type: MIFARE 1KB
Sector Block   0  1  2  3   4  5  6  7   8  9 10 11  12 13 14 15  AccessBits
  15     63   00 00 00 00  00 00 FF 07  80 69 FF FF  FF FF FF FF  [ 0 0 1 ]
         62   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ]
         61   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ]
         60   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ]
         59  MIFARE_Read() failed: A MIFARE PICC responded with NAK.
         58  MIFARE_Read() failed: Timeout in communication.
...
          0  MIFARE_Read() failed: Timeout in communication.
        255  MIFARE_Read() failed: Timeout in communication.
        254  MIFARE_Read() failed: Timeout in communication.
        253  MIFARE_Read() failed: Timeout in communication.
...


Could you give me some light or show some of your output?

Thanks