Wiznet W5100 & RC522 doesn't work together

Hi,

Using arduino UNO + Wiznet W5100 Ethernet Shield + RC522 RFID.

When i connect RC522 directly arduino UNO according to below schematic, it works perfectly.

But if i connect RC522 after plug-in the ethernet shield it returns "WARNING: Communication failure, is the MFRC522 properly connected?"

My Connection with ethernet shield as below (well i'm basicly doing the same connection as schematic);

and using this code (from RC522 examples folder,i've added ethernet class because thought that may cause problem)

/*
 * --------------------------------------------------------------------------------------------------------------------
 * 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>
#include <Ethernet.h>
#define RST_PIN         9          // Configurable, see typical pin layout above
#define SS_PIN          10         // Configurable, see typical pin layout above
MFRC522 mfrc522(SS_PIN, RST_PIN);  // Create MFRC522 instance
byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// Enter the IP address for Arduino, as mentioned we will use 192.168.0.16
// Be careful to use , insetead of . when you enter the address here
IPAddress ip(192,168,1,193);
char server[] = "192.168.1.208";
// Initialize the Ethernet server library
EthernetClient client;

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
 delay(4); // Optional delay. Some board do need more time after init to be ready, see Readme
 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() {
 // Reset the loop if no new card present on the sensor/reader. This saves the entire process when idle.
 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));
}

With below code, if i connect RC522 to uno directly (without ethernet shield) it works fine, but when i add ethernet shield it doesn't work.

Why?

#define SS_PIN          10         // Configurable, see typical pin layout above
MFRC522 mfrc522(SS_PIN, RST_PIN);  // Create MFRC522 instance

Bad idea, pin 10 is used by the Ethernet Shield for the Wiznet 5100 chip select. Use another pin (6 or 7 seems to be available in your setup)!

pylon:

#define SS_PIN          10         // Configurable, see typical pin layout above

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




Bad idea, pin 10 is used by the Ethernet Shield for the Wiznet 5100 chip select. Use another pin (6 or 7 seems to be available in your setup)!

Problem solved with pylon’s suggestion, thanks.

I’ve completed the project and sharing the code if somebody needs it in the future;

Arduino Code

#include <Ethernet.h>
#include <SPI.h>
#include <MFRC522.h>
#include <TextFinder.h>
#include <String.h>
#include <Servo.h>
Servo kilit;
String readString;
int servopozisyon;
int kirmiziled = 4;
int yesilled = 2;

#define RST_PIN     9       // 
#define SS_PIN      7      //
String uID;
MFRC522 mfrc522(SS_PIN, RST_PIN);   // Create MFRC522 instance
byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 1, 193);
char server[] = "192.168.1.208";
EthernetClient client;
TextFinder finder( client );
void setup()
{
  Serial.begin(9600);
  while (!Serial);
  SPI.begin();
  mfrc522.PCD_Init();
  ShowReaderDetails();
  Serial.println(F("Scan PICC to see UID, type, and data blocks..."));
  Ethernet.begin(mac, ip);
  pinMode(kirmiziled,OUTPUT);
  pinMode(yesilled,OUTPUT);  
  digitalWrite(kirmiziled,HIGH);
  digitalWrite(yesilled,LOW);
  kilit.attach(6);  
  kilit.write(30);
  servopozisyon=30;
  delay(5000);
}//setup

void loop()
{
  if ( ! mfrc522.PICC_IsNewCardPresent())
  {
    return;
  }
  // Select one of the cards
  if ( ! mfrc522.PICC_ReadCardSerial())
  {
    return;
  }
uID="";
readString="";  
int val1 = (mfrc522.uid.uidByte[0]);
int val2 = (mfrc522.uid.uidByte[1]);
int val3 = (mfrc522.uid.uidByte[2]);
int val4 = (mfrc522.uid.uidByte[3]);
String valA = String(val1);
String valB = String(val2);
String valC = String(val3);
String valD = String(val4);
uID = valA + valB + valC + valD;
Serial.print(uID);
if (client.connect(server, 8089))
{
Serial.print("\n");  
Serial.println("Connection with database established");
Serial.print("\n");
// Make a HTTP request:
client.print( "GET /ofisklima/KartSor.php?");
client.print("kartno=");
client.print(uID);
client.println( " HTTP/1.1");
client.print( "Host: " );
client.println(server);
client.println( "Connection: close" );
client.println();
client.println();
Serial.print("\n");
Serial.print("Disconnect");
Serial.print("\n");
while (client.connected())
{
char c = client.read();
readString += c; //places captured byte in readString
}//while (client.connected())
client.stop();
}//if (client.connect(server, 8089))
Serial.print("\n");
Serial.print(readString);
Serial.print("\n");
if(readString.indexOf("[KART OK]") > 0)
{
Serial.print("GEÇERLİ KART");
if (kilit.read()==180)
{
kilit.write(30);
digitalWrite(kirmiziled,HIGH);
digitalWrite(yesilled,LOW);
}//kilitle
else
{
kilit.write(180);
digitalWrite(kirmiziled,LOW);
digitalWrite(yesilled,HIGH);
}
Serial.print("\n");
Serial.print("Servo Pozisyon : ");
Serial.print(kilit.read());
Serial.print("\n");
}
if(readString.indexOf("[KART NOT OK]") > 0)
{
Serial.print("GEÇERSİZ KART");
kilit.write(30);
Serial.print("\n");
Serial.print("Servo Pozisyon : ");
Serial.print(kilit.read());
Serial.print("\n");
}
readString="";  
delay(1000);
}//loop

void ShowReaderDetails() {
  // Get the MFRC522 software version
  byte v = mfrc522.PCD_ReadRegister(mfrc522.VersionReg);
  Serial.print(F("MFRC522 Software Version: 0x"));
  Serial.print(v, HEX);
  if (v == 0x91)
    Serial.print(F(" = v1.0"));
  else if (v == 0x92)
    Serial.print(F(" = v2.0"));
  else
    Serial.print(F(" (unknown)"));
  Serial.println("");
  // When 0x00 or 0xFF is returned, communication probably failed
  if ((v == 0x00) || (v == 0xFF)) {
    Serial.println(F("WARNING: Communication failure, is the MFRC522 properly connected?"));
  }
}

PHP Code :

<?php
error_reporting(0);
ini_set('display_errors', 0);
$baglan=mysql_connect("server","username","password") or die (mysql_error());
mysql_select_db("ofisklima") or die (mysql_error());
mysql_query("set names latin5");
$sor=mysql_query("select * from kartlar where kartno='".$_GET["kartno"]."'") or die (mysql_error());
if (mysql_num_rows($sor)>=1)
{
print "[KART OK]";
/*$content = "OK - ".$_GET["kartno"]."";
$fp = fopen("KARTOK_".Date("YmdHis").".txt","wb");
fwrite($fp,$content);
fclose($fp);*/
$veri=mysql_fetch_row($sor);
$isim=$veri[2];
$logkaydet=mysql_query("insert into loglar (kart,kisi,durum) values ('".$_GET["kartno"]."','".$isim."','TANIMLI KART OKUMA')") or die (mysql_error());
}
else
{
print "[KART NOT OK]";
/*$content = "NOT OK - ".$_GET["kartno"]."";
$fp = fopen("KARTNOTOK_".Date("YmdHis").".txt","wb");
fwrite($fp,$content);
fclose($fp);*/
$logkaydet=mysql_query("insert into loglar (kart,kisi,durum) values ('".$_GET["kartno"]."','TANIMSIZ KART','TANIMSIZ KART OKUMA')") or die (mysql_error());
}
?>