Arduino UNO + Ethernet + RFID not working

I'm having trouble connecting both my Ethernet Shield (HR911105A) and my RFID Reader (MFRC522) to my Arduino. When I plug them in separately, everything works as expected. But when I plug them both in, I'm not able to read cards from my RFID reader, at all.

I've searched online for answers and it says to use different SS ports, and also deactivating one SPI before communcating with the other, if I've been correct. I've read lots of different topics and nothing that I've tried is working. :frowning:

Every bit of help would be so appreciated!

Here's my code:

#include <SPI.h>
#include <MFRC522.h>
#include <Ethernet.h>

#define RST_PIN         7          // Configurable, see typical pin layout above
#define SS_PIN          6         // 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
  SPI.begin();
  
  // disable Ethernet
  pinMode(10,OUTPUT);
  digitalWrite(10,HIGH);

  // disable SD
  pinMode(4,OUTPUT);
  digitalWrite(4,HIGH);
  
  mfrc522.PCD_Init();
  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;
 }
 
  int UID = getUID();
  Serial.print("UID: ");
  Serial.println(UID);
  
 // Dump debug info about the card; PICC_HaltA() is automatically called
 mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
}

int getUID() {
  unsigned int hex_num;
  hex_num =  mfrc522.uid.uidByte[0] << 24;
  hex_num += mfrc522.uid.uidByte[1] << 16;
  hex_num += mfrc522.uid.uidByte[2] <<  8;
  hex_num += mfrc522.uid.uidByte[3];
  return hex_num;
}

I'm using this library:

Attached is my schematic. The shield is placed on top of an Arduino UNO with SPI connected to 13, 12, 11. SS is connected to 9 and RST to 8. The RFID reader works properly when connected to the exact same pins directly on the Arduino UNO (without the Ethernet shield on top).

Am I missing something?

Show us how you wired your project, best is to post a schemata or at least a picture of the wiring.

Also post a link to the library (MFRC522) you are using.

Thank you pylon for your response.

I'm using this library:

Attached is my schematic. The shield is placed on top of an Arduino UNO with SPI connected to 13, 12, 11. SS is connected to 9 and RST to 8. The RFID reader works properly when connected to the exact same pins directly on the Arduino UNO (without the Ethernet shield on top).

Am I missing something?

Does the library set pin 10 as an Output? It needs to be for the Arduino to be SPI master, whether it uses pin 10 as a chip select or something else.

CrossRoads:
Does the library set pin 10 as an Output? It needs to be for the Arduino to be SPI master, whether it uses pin 10 as a chip select or something else.

The sketch that OP posted does (although the comment that goes with the code is wrong).

Does the rfid reader work when the ethernet shield is connected but not initialized? Don't even include the ethernet library for this test.

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

#define RST_PIN         7          // Configurable, see typical pin layout above
#define SS_PIN          6         // Configurable, see typical pin layout above

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

void setup()
{
  // disable ethernet and SD SPI
  digitalWrite(10, HIGH);
  digitalWrite(4, HIGH);

// rest of your rfid code

CrossRoads:
Does the library set pin 10 as an Output? It needs to be for the Arduino to be SPI master, whether it uses pin 10 as a chip select or something else.

Thank you for your response CrossRoads. I do set pin 10 as an output in my code above, yes!

PaulS:
The sketch that OP posted does (although the comment that goes with the code is wrong).

What is wrong with the comment? I searched around the forums and found out that I should try and disable the Ethernet SS by setting it to HIGH (the Ethernet which by my understanding goes through pin 10). Or did I get that wrong?

SurferTim:
Does the rfid reader work when the ethernet shield is connected but not initialized? Don't even include the ethernet library for this test.

I've tried without including the Ethernet library, still with no result. :frowning:

When you tried it with the ethernet shield connected, did you disable the w5100 and SD SPI by setting D10 and D4 HIGH?

SurferTim:
When you tried it with the ethernet shield connected, did you disable the w5100 and SD SPI by setting D10 and D4 HIGH?

Yes I did. It didn't help unfortunately :frowning:

The wiring does not correspond with the code you posted.

Did you check if your Ethernet shield is working? Can you transmit data with it? "HR911105A" is not the shield but the RJ45 connector on it. It seems that you bought a cheap Chinese Ethernet shield and experience teaches that they often have a bad quality such as two pins connected by to much tin and the like. If yours have such a defect this might be responsible for the errors you see.

If connected with the Ethernet shield do you get the MFRC522's serial number or nothing at all from the shield?

What is wrong with the comment?

  // disable Ethernet
  pinMode(10,OUTPUT);

That is NOT what that code does. Setting pin 10 as OUTPUT defines the Arduino as an SPI master.

The NEXT line disables the Ethernet card.

PaulS:

  // disable Ethernet

pinMode(10,OUTPUT);



That is NOT what that code does. Setting pin 10 as OUTPUT defines the Arduino as an SPI master.

The NEXT line disables the Ethernet card.

Both combined disable the w5100, just as the next lines disable the SD card. I used this in many of my examples, but I no longer use the pinMode calls. It screws up the Due SPI.

  // disable Ethernet
  pinMode(10,OUTPUT);
  digitalWrite(10,HIGH);

  // disable SD
  pinMode(4,OUTPUT);
  digitalWrite(4,HIGH);