RFID reader not working with LCD

Hello,
I am working on school porject which uses esp32's wifi, mfrc522 rfid reader and basic 16x2 lcd display. since i couldnt made everything to work together I just made a program that reads RFID card's UID, which worked perfectly. than i started adding lines from original code one by one to find a problem. what i found is that RFID reader stops readind UID's once lcd.begin(16,2); is added to code. Could anybody help me with this?
Thanks :slight_smile:

Check the pins used by the LCD and RFID. Make sure none are in conflict.

That is my best guess in absence of any real information on your program or circuit. A schematic and your well formatted code would go a long way towards filling in the holes.

Please read the forum guidelines to see how to properly post code and some information on making a good post.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.

Please post a schematic. Written descriptions are always more ambiguous than a drawing. Hand drawn, photographed and posted is fine. Include all pin names/numbers, components, their part numbers and/or values and power supplies.

Also data sheets for relevant components can be a big help.

This is code using which UIDs are read correctly:

#include <MFRC522.h>
#include <SPI.h>
#include <esp_now.h>
#include <WiFi.h>
#include <LiquidCrystal.h>

#define CS_RFID 21
#define RST_RFID 0
#define laserSenzor 34
#define enter 35
#define zelenaled 33
#define rdecaled 32
#define casPrSignal 1100

MFRC522 rfid(CS_RFID, RST_RFID);

String uidString;

const int rs = 4, en = 22, d4 = 2, d5 = 17, d6 = 3, d7 = 1;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

bool laserCilj;
bool startst = 0;
bool ciljst = 0;
unsigned long casZacetek;
unsigned long casKonec;
unsigned long casSignal = 0;
int casVoznje;
int minute;
int sekunde;
int tisocinke;
int meni = 0;
bool povezav = 0;


typedef struct struct_massage {
  bool d;
} struct_massage;

struct_massage myData;

void OnDataRecv(const uint8_t *mac, const uint8_t *incomingData, int len) {
  memcpy(&myData, incomingData, sizeof(myData));
  laserCilj = myData.d;
  casSignal = millis();
}

void setup() {

  Serial.begin(115200);
  SPI.begin();
  rfid.PCD_Init();
}

void loop() {
  //look for new cards
  if (rfid.PICC_IsNewCardPresent()) {
    readRFID();
    delay(1000);
  }
}

void readRFID() {
  rfid.PICC_ReadCardSerial();

  Serial.print("Tag UID: ");

  uidString = String(rfid.uid.uidByte[0]) + " " + String(rfid.uid.uidByte[1]) + " " + String(rfid.uid.uidByte[2]) + " " + String(rfid.uid.uidByte[3]);
  Serial.println(uidString);
}

as soon as i add lcd.begin(); to void setup, UIDs are no longer displayed on serial monitor.

i checked the connections and i cant fiind any pins that would be shared by rfid and lcd

also, rfid reader is only SPI device, lcd is connected using parralel comunication

Yes we rather hoped you would post the code that you are having trouble with, working code - well it works so we can't say much about it.

However code is only part of the story with an embedded processor like the Arduino so we need to see the schematic to make sense of any code errors you have made.

We also need to know what sort of Arduino you have. The pin numbers might suggest a Mega but there are other possibilities, but that will be on the schematic won't it?

PS. hand drawn is fine, Fritzing is not.

I see no conflicts either. I am not real familiar with the ESP32, here is a page that covers ESP32 pin usage. Maybe information that is useful? >> ESP32 Pinout Reference: Which GPIO pins should you use? | Random Nerd Tutorials

Please, a schematic.


I use esp32 wroom 32u.
As i already mentioned, the code i have trouble with is exactly the same as one above, with only exception of added lcd.begin(); in void setup(). As soon as this single line is added i dont get any rfid readings anymore.

I am pretty sure lcd and rfid reader are connected corectly to the esp32 since they both work if using them one by one in the code (without changing the wiring, only code). When i try to use them together Serial monitor simply remains empty and doesnt show any readings.

I tried adding lines from lcd part of code to rfid part, one by one with testing if it works everytime and it stopped working when i added lcd.begin

GPIO3 and GPIO 1 are RX -TX used in serial port.

This image is more clear.

1 Like

choosing different pins for d6 and d7 on lcd solved the issue for me :smile:

does it mean that it is better to not use tx and rx pins in projects at all, or they only affect serial monitor?

anyways, thanks for the answer, you saved me another few hours (or even days haha) not knowing what is the problem :sweat_smile:

Hi!

Glad to hear!

It can be used to another function if you are not using Serial.begin and Serial.print on code.

Best regards.

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