Unpredictable behaviour of RC522 with ESP Microcontroller

Greetings Everyone, I've been trying to use the RC522 with ESP32. When I use RC522 alone with esp32 it works fine but when I use WiFi, sometimes RC522 works whereas sometimes it just doesn't respond at all. I'm pretty sure that there is no issue in code at all, has anyone know what's going wrong?
Thanks in Advance!

Hi @sdg123

With your project it's not possible to know,

but with your topic I know what's going wrong.

You haven't posted enough information for us to help you;
You haven't posted your sketch;
You haven't posted any schematics of your project.

RV mineirin

Hi, I've connected the RC522 to the VSPI pins of ESP32. I just came across the following post https://arduino.stackexchange.com/questions/71764/nodemcu-unable-to-communicate-with-mfrc522-rfid-reader and I think there might be an issue with the power supply because whenever I reset the esp often rc522 starts working. But when I check the voltage across the rc522, I don't find out any variation in it.

Post a pic of your project. Describe how you are powering the project. Post your code. Why post your code when it could be a hardware issue? Because I can look at your code and see if you are trying to do something like use portB pins as outputs or putting 5V on the CLK pin or using the other ADC with WiFi, or is using one of the FLASH Pins, or some other thing.

#include <WiFi.h>
#include <MFRC522.h>

#define led 5
#define led2 8
#define RFID_RST         22
#define RFID_SS          21

WiFiClient client;
WiFiServer server(80);
MFRC522 mfrc522(RFID_SS, RFID_RST);


void setup()
{
  // put your setup code here, to run once:
  Serial.begin(115200);
  WiFi.begin("Name", "Password");
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(200);
    Serial.print("..");
  }
  mfrc522.PCD_Init();
  Serial.println();
  Serial.println("NodeMCU is connected!");
  Serial.println(WiFi.localIP());
  server.begin();
  pinMode(led, OUTPUT);
  pinMode(led2, OUTPUT);
}

void loop()
{
  // put your main code here, to run repeatedly:
  client = server.available();  //Gets a client that is connected to the server and has data available for reading.
  if (client == 1)
  {
    String request =  client.readStringUntil('\n');
    Serial.println(request);
    request.trim();
    if (request == "GET /led1on HTTP/1.1")
    {
      digitalWrite(led, HIGH);
    }
    if (request == "GET /led1off HTTP/1.1")
    {
      digitalWrite(led, LOW);
    }
    if (request == "GET /led2on HTTP/1.1")
    {
      digitalWrite(led2, HIGH);
    }
    if (request == "GET /led2off HTTP/1.1")
    {
      digitalWrite(led2, LOW);
    }
  }
  client.println("HTTP/1.1 200 OK");
  client.println("Content-Type: text/html");
  client.println("");
  client.println("<!DOCTYPE HTML>");
  client.println("<html>");
  client.println("<style> body { background: url(https://st1.bgr.in/wp-content/uploads/2021/02/Free-Fire.jpg) no-repeat} </style>");
  client.println("<title>HTML Webpage</title>");
  client.println("<h1>Welcome to the Webpage!</h1>");
  client.println("<h3>LED Controls<h3>");
  client.println("<br>");
  client.println("<a href=\"/led1on\"\"><button>LED 1 ON</button></a>");
  client.println("<a href=\"/led1off\"\"><button>LED 1 OFF</button></a><br/>");
  client.println("<a href=\"/led2on\"\"><button>LED 2 ON</button></a>");
  client.println("<a href=\"/led2off\"\"><button>LED 2 OFF</button></a><br/>");
  client.println("</html>");

  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));
}

I'm powering the project directly 5V from the laptop and powering the rc522 from the 3.3V regulator of esp32. when I comment the WiFi part rc522 works fine without any hesitation. when I'm using WiFi sometimes rc522 works or otherwise I've to reset the esp twice or thrice to make it work properly.

My suggestion would be, 1st put a 470uF electrolytic and a 103 ceramic cap as close to the 3.3V pin as possible.

The ESP32 will do a current surge when getting ready for WiFi transmission. Powering a device that does a 26ma, the rc522, surge may get in the way of the ESP32's requirements.

If the cap's do not work, then you'll need to wire in a separate 3.3V regulator for the rc-thing.

What if I add an LC filter, which could limit the sudden current surge but will it affect the WiFi transmission significantly.

Let us know how that works out for you.

Sure

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.