Mega + Ethernet 2 + RFID 522 + i2c LCD

Hi there, so I have a project based on a Mega 2560. I have an ethernet shield 2 (w5500), a PCF8574AT i2c LCD and an RFID RC522.

The issue is with the LCD and RFID module connection.
I'm a bit confused on how to connect them. They both work with separate sketches but not together. I tried different pin combinations. So far I have:

(working with the Dumpinfo.ino sketch from the RFID library example)

RFID:

Reset: A0 (on the ethernet shield)
SS: 53
MOSI: 51
MISO: 50
SCK: 52
(lcd i2c working)

SDA: 20
SCL: 21

now, if I use the code below (Dumpinfo sketch from RFID library with i2c LCD code added) it looks like they are conflicting and the RFID won't work anymore.

#include <SPI.h>
#include <MFRC522.h>
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x3F,16,2);

#define RST_PIN         A0          // Configurable, see typical pin layout above
#define SS_PIN          53         // 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..."));

   lcd.init(); // initialize the lcd 
   lcd.backlight();
   lcd.print("hello, world!");
}

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

and this is the error I get

Firmware Version: 0xFF = (unknown)
WARNING: Communication failure, is the MFRC522 properly connected?

For the RFID, I tried using the pin 10 to 13 on the ethernet shield instead of 50-53 on the mega but still nothing. How do I connect them properly?

Thanks!

How's your power supply?

3.3V for the RFID and 5V for the LCD (currently the usb is plugged as well as a 12V power supplier in the DC socket)

leech:
3.3V for the RFID and 5V for the LCD (currently the usb is plugged as well as a 12V power supplier in the DC socket)

If you got them both plugged in at the same time it will use the usb power. You should try it without connecting it to the usb. Also does it work without the ethernet shield?

Hi there,

I finally had time to test all the cases and it looks like the issue is about the external supply AND the Ethernet Shield.

So I tested all the possible combinations of wiring and boards (Fake Mega and original Genuino as well as Fake Ethernet and original Ethernet 2)

This is the wiring I have and it definitely works:

RC522:

SS     - 53
SCK   - 52
MOSI - 51
MISO - 50
RST   - A5
V+    - 3.3V


LCD (I2C):

SCL  - 21
SDA - 20

This is basically what I tried (while running the sketch):

  • only USB powered
  • add external power
  • remove external power (keep USB)

Without Ethernet shield (either W5100 or W5500) it always works without issues (both LCD and RFID simultaneously)
With the Ethernet shield plugged instead, after I remove the external power, it keeps working for a few seconds and after that the RFID just stops working. Restarting the sketch or even re-uploading it will always throw errors like Firmware Version: 0xFF = (unknown) and in order to have it working I need to unplug the usb from the laptop and plug it back.

I'm now powering it only from the external supply (12V) and although it seems to be better, there's still some issues where sometimes the RFID stops working (and reset is needed to have it back). the LCD instead is always working.

Any idea about what might be the issue?

This is the code I'm using now

#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
#include <SPI.h>
#include <MFRC522.h>

// 5 is A5
#define RST_PIN         5
#define SS_PIN          53

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

LiquidCrystal_I2C lcd(0x27,16,2);
String card_UID = "";
String old_UID = "a";

void setup() {
  Serial.begin(9600);
  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

  lcd.init(); // initialize the lcd 
  lcd.backlight();

}

void loop() {

  lcd.setCursor(0, 0);
  lcd.print(millis() / 1000);
  
  // Look for new cards
  if ( ! mfrc522.PICC_IsNewCardPresent())
    return;

  // Select one of the cards
  if ( ! mfrc522.PICC_ReadCardSerial())
    return;

  Serial.print("CARD UID: ");
  dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);
  Serial.println(card_UID);
  //update the lcd if new card
  if(card_UID != old_UID){
    lcd.setCursor(0, 1);
    lcd.print(card_UID);
    old_UID = card_UID;
  }
}

void dump_byte_array(byte *buffer, byte bufferSize) {
    card_UID = "";
    for (byte i = 0; i < bufferSize; i++) {
        card_UID += buffer[i];
    }
}

Try using a 3.3 external power supply to power the rfid reader.

maybe it's a bit early to say it's fixed but I have a strong feeling that it was a faulty jumper cable (the 3.3V). It was the only thing I didn't change because they were new. I changed it and now it looks like it's working without issue. I'll test it a few more times..

edit: yes it was too early. Still issues. I'm on holiday now, I'll try powering the rfid module separately next week when I'm back.