Hi, on Youtube I found an old Blynk project that can add and remove 10 RFID cards in EEPROM instead of hard coding the card numbers.
The current code has a lot going on in the loop, I was going to see if I could get it working and once I understood its function work at cleaning it up. I have the code running and the Blynk LCD display and buttons are working. Meaning when I hit the “unlock” V3 , the display populates. Also the “skip” V2 as well as the “begin” V1. So I am fairly certain that it is not “flooding” at this point. I am successfully running the “dump info” sketch and it looks to me this sketch has the same RFID elements but it is not displaying the card numbers as the video shows. Can someone point me in the right direction?
I should note that I’m using a D1 Mini. Therefore the D reference to pin numbers.
this video…
Working “dump info” code
/*
* --------------------------------------------------------------------------------------------------------------------
* Example sketch/program showing how to read data from a PICC to serial.
* --------------------------------------------------------------------------------------------------------------------
* This is a MFRC522 library example; for further details and other examples see: https://github.com/miguelbalboa/rfid
*
* Example sketch/program showing how to read data from a PICC (that is: a RFID Tag or Card) using a MFRC522 based RFID
* Reader on the Arduino SPI interface.
*
* When the Arduino and the MFRC522 module are connected (see the pin layout below), load this sketch into Arduino IDE
* then verify/compile and upload it. To see the output: use Tools, Serial Monitor of the IDE (hit Ctrl+Shft+M). When
* you present a PICC (that is: a RFID Tag or Card) at reading distance of the MFRC522 Reader/PCD, the serial output
* will show the ID/UID, type and any data blocks it can read. Note: you may see "Timeout in communication" messages
* when removing the PICC from reading distance too early.
*
* If your reader supports it, this sketch/program will read all the PICCs presented (that is: multiple tag reading).
* So if you stack two or more PICCs on top of each other and present them to the reader, it will first output all
* details of the first and then the next PICC. Note that this may take some time as all data blocks are dumped, so
* keep the PICCs at reading distance until complete.
*
* @license Released into the public domain.
*
* Typical pin layout used:
* -----------------------------------------------------------------------------------------
* MFRC522 Arduino Arduino Arduino Arduino Arduino
* Reader/PCD Uno/101 Mega Nano v3 Leonardo/Micro Pro Micro
* Signal Pin Pin Pin Pin Pin Pin
* -----------------------------------------------------------------------------------------
* RST/Reset RST 9 5 D9 RESET/ICSP-5 RST
* SPI SS SDA(SS) 10 53 D10 10 10
* SPI MOSI MOSI 11 / ICSP-4 51 D11 ICSP-4 16
* SPI MISO MISO 12 / ICSP-1 50 D12 ICSP-1 14
* SPI SCK SCK 13 / ICSP-3 52 D13 ICSP-3 15
*/
#include <SPI.h>
#include <MFRC522.h>
constexpr uint8_t RST_PIN = D3; // Configurable, see typical pin layout above
constexpr uint8_t SS_PIN = D4; // Configurable, see typical pin layout above
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
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
mfrc522.PCD_DumpVersionToSerial(); // Show details of PCD - MFRC522 Card Reader details
Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks..."));
}
void loop() {
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent()) {
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
return;
}
// Dump debug info about the card; PICC_HaltA() is automatically called
mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
}
Code I’m working with…
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SPI.h>
#include <MFRC522.h>
#include <EEPROM.h>
#define SS_PIN D4
#define RST_PIN D3
#define BTN_PIN D0
#define SLN_PIN D8
MFRC522 mfrc522(SS_PIN, RST_PIN);
unsigned long uidDec, uidDecTemp;
int ARRAYindexUIDcard;
int EEPROMstartAddr;
long adminID = 11;
bool beginCard = 0;
bool addCard = 1;
bool skipCard = 0;
int LockSwitch;
unsigned long CardUIDeEPROMread[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
int PiezoPin = D0;
char auth[] = "***";
char ssid[] = "**";
char pass[] = "**";
WidgetLCD lcd(V0);
void setup() {
//Serial.begin(115200);
pinMode(SLN_PIN, OUTPUT); digitalWrite(SLN_PIN, LOW);
pinMode(BTN_PIN, INPUT_PULLUP);
pinMode(PiezoPin, OUTPUT);
pinMode(D1, OUTPUT); //use for ground on piezzo
digitalWrite(D1,LOW); //
SPI.begin();
mfrc522.PCD_Init();
//Serial.println("beforeblynk");
Blynk.begin(auth, ssid, pass);
lcd.clear(); //Use it to clear the LCD Widget
EEPROM.begin(512);
DisplayWAiT_CARD();
EEPROMreadUIDcard();
digitalWrite(PiezoPin, HIGH), delay(100), digitalWrite(PiezoPin, LOW);
//Serial.println("Setup");
}
void loop() {
digitalWrite(SLN_PIN, LOW);
if (digitalRead(BTN_PIN) == HIGH) {
digitalWrite(SLN_PIN, HIGH); //unlock
lcd.print(0, 0, " BUTTON UNLOCK ");
lcd.print(0, 1, " DOOR OPEN ");
digitalWrite(PiezoPin, HIGH), delay(200), digitalWrite(PiezoPin, LOW);
delay(2000);
DisplayWAiT_CARD();
}
if (beginCard == 0) { //0
if ( ! mfrc522.PICC_IsNewCardPresent()) { //Look for new cards.
//Serial.println("not new card");
Blynk.run();
return;
}
if ( ! mfrc522.PICC_ReadCardSerial()) { //Select one of the cards.
//Serial.println("select card");
Blynk.run();
return;
}
}
//Read "UID".
for (byte i = 0; i < mfrc522.uid.size; i++) {
uidDecTemp = mfrc522.uid.uidByte[i];
uidDec = uidDec * 256 + uidDecTemp;
}
if (beginCard == 1 || LockSwitch > 0)EEPROMwriteUIDcard(); //uidDec == adminID
if (LockSwitch == 0) {
//CardUIDeEPROMread.
for (ARRAYindexUIDcard = 0; ARRAYindexUIDcard <= 9; ARRAYindexUIDcard++) {
if (CardUIDeEPROMread[ARRAYindexUIDcard] > 0) {
if (CardUIDeEPROMread[ARRAYindexUIDcard] == uidDec) {
lcd.print(0, 0, "CARD ACCESS OPEN");
lcd.print(3, 1, uidDec);
digitalWrite(SLN_PIN, HIGH); //unlock
digitalWrite(PiezoPin, HIGH), delay(200), digitalWrite(PiezoPin, LOW);
delay(2000);
break;
}
}
}
if (ARRAYindexUIDcard == 10) {
lcd.print(0, 0, " Card not Found ");
lcd.print(0, 1, " ");
lcd.print(0, 1, "ID : ");
lcd.print(5, 1, uidDec);
for (int i = 0; i <= 2; i++)delay(100), digitalWrite(PiezoPin, HIGH), delay(100), digitalWrite(PiezoPin, LOW);
digitalWrite(SLN_PIN, LOW); //lock();
delay(2000);
}
ARRAYindexUIDcard = 0;
DisplayWAiT_CARD();
}
Blynk.run();
}
BLYNK_WRITE(V1) {
int a = param.asInt();
if (a == 1) beginCard = 1; else beginCard = 0;
}
BLYNK_WRITE(V2) {
int a = param.asInt();
if (a == 1) {
skipCard = 1;
if (EEPROMstartAddr / 5 < 10) EEPROMwriteUIDcard();
} else {
skipCard = 0;
}
}
BLYNK_WRITE(V3) {
int a = param.asInt();
if (a == 1) {
digitalWrite(SLN_PIN, HIGH); //unlock
lcd.print(0, 0, " APP UNLOCK OK ");
lcd.print(0, 1, " DOOR OPEN ");
digitalWrite(PiezoPin, HIGH), delay(200), digitalWrite(PiezoPin, LOW);
delay(2000);
DisplayWAiT_CARD();
}
}
void EEPROMwriteUIDcard() {
if (LockSwitch == 0) {
lcd.print(0, 0, " START REC CARD ");
lcd.print(0, 1, "PLEASE TAG CARDS");
delay(500);
//Serial.println("start card");
}
if (LockSwitch > 0) {
if (skipCard == 1) { //uidDec == adminID
lcd.print(0, 0, " SKIP RECORD ");
lcd.print(0, 1, " ");
lcd.print(0, 1, " label : ");
lcd.print(11, 1, EEPROMstartAddr / 5);
EEPROMstartAddr += 5;
skipCard = 0;
} else {
//Serial.println("writeCard");
EEPROM.write(EEPROMstartAddr, uidDec & 0xFF);
EEPROM.write(EEPROMstartAddr + 1, (uidDec & 0xFF00) >> 8);
EEPROM.write(EEPROMstartAddr + 2, (uidDec & 0xFF0000) >> 16);
EEPROM.write(EEPROMstartAddr + 3, (uidDec & 0xFF000000) >> 24);
EEPROM.commit();
delay(10);
lcd.print(0, 1, " ");
lcd.print(0, 0, "RECORD OK! IN ");
lcd.print(0, 1, "MEMORY : ");
lcd.print(9, 1, EEPROMstartAddr / 5);
EEPROMstartAddr += 5;
delay(500);
}
}
LockSwitch++;
if (EEPROMstartAddr / 5 == 10) {
lcd.clear();
lcd.print(0, 0, "RECORD FINISH");
delay(2000);
EEPROMstartAddr = 0;
uidDec = 0;
ARRAYindexUIDcard = 0;
EEPROMreadUIDcard();
}
}
void EEPROMreadUIDcard() {
for (int i = 0; i <= 9; i++) {
byte val = EEPROM.read(EEPROMstartAddr + 3);
CardUIDeEPROMread[ARRAYindexUIDcard] = (CardUIDeEPROMread[ARRAYindexUIDcard] << 8) | val;
val = EEPROM.read(EEPROMstartAddr + 2);
CardUIDeEPROMread[ARRAYindexUIDcard] = (CardUIDeEPROMread[ARRAYindexUIDcard] << 8) | val;
val = EEPROM.read(EEPROMstartAddr + 1);
CardUIDeEPROMread[ARRAYindexUIDcard] = (CardUIDeEPROMread[ARRAYindexUIDcard] << 8) | val;
val = EEPROM.read(EEPROMstartAddr);
CardUIDeEPROMread[ARRAYindexUIDcard] = (CardUIDeEPROMread[ARRAYindexUIDcard] << 8) | val;
ARRAYindexUIDcard++;
EEPROMstartAddr += 5;
}
ARRAYindexUIDcard = 0;
EEPROMstartAddr = 0;
uidDec = 0;
LockSwitch = 0;
DisplayWAiT_CARD();
}
void DisplayWAiT_CARD() {
lcd.print(0, 0, " ATTACH THE ");
lcd.print(0, 1, " CARD ");
//Serial.println("attach card");
}