Operating with two slave devices


I am working on a project, where RFID chip (MFRC-522) will read a tag and then send the UID into a database through an Ethernet Shield. But I’m stuck on switching between the two devices.

I changed the slave select pin and thought, I can now switch between the two, but for some reason, only one can work in the sketch. Here’s the code:

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

byte mac[] = {0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02};

#define  uchar unsigned char
#define uint  unsigned int

uchar fifobytes;
uchar fifoValue;

// create AddicoreRFID object to control the RFID module
AddicoreRFID myRFID;

EthernetClient client;

const int ssSD = 4; //SD slave select pin
const int ssEthernet = 10; //Ethernet chip slave select pin

const int chipSelectPin = 8; //RFID slave select pin
const int NRSTPD = 5; //RFID some pin

const int pirPin = 7;
//RGB diode on pin 3,6,9

//Maximum length of the array
#define MAX_LEN 16

void setup() {
  // Open serial communications and wait for port to open
  // disable SD card
  pinMode(ssSD, OUTPUT);
  digitalWrite(ssSD, HIGH);
  // disable RFID
  pinMode(chipSelectPin, OUTPUT);
  digitalWrite(chipSelectPin, HIGH);
  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
  pinMode(ssEthernet, OUTPUT);
  digitalWrite(ssEthernet, HIGH);
  // start the SPI library and RFID
  pinMode(chipSelectPin, OUTPUT);              // Set digital pin 10 as OUTPUT to connect it to the RFID /ENABLE pin 
    digitalWrite(chipSelectPin, LOW);         // Activate the RFID reader
  pinMode(NRSTPD, OUTPUT);                     // Set digital pin 10 , Not Reset and Power-down
    digitalWrite(NRSTPD, HIGH);

void loop() {
  digitalWrite(chipSelectPin, LOW); 
  uchar i, tmp, checksum1;
  uchar status;
        uchar str[MAX_LEN];
        uchar RC_size;
        uchar blockAddr;  //Selection operation block address 0 to 63
        String mynum = "";

        str[1] = 0x4400;
  //Find tags, return tag type
  status = myRFID.AddicoreRFID_Request(PICC_REQIDL, str);
  //Anti-collision, return tag serial number 4 bytes
  status = myRFID.AddicoreRFID_Anticoll(str);
  if (status == MI_OK) {
          checksum1 = str[0] ^ str[1] ^ str[2] ^ str[3];
          Serial.print("The tag's number is:\t");
            Serial.print(" , ");
            Serial.print(" , ");
            Serial.print(" , ");

          Serial.print("Read Checksum:\t\t");
          Serial.print("Calculated Checksum:\t");
            // Should really check all pairs, but for now we'll just use the first
            if(str[0] == 197)                      //You can change this to the first byte of your tag by finding the card's ID through the Serial Monitor
                Serial.println("\nHello Craig!\n");
            } else if(str[0] == 244) {             //You can change this to the first byte of your tag by finding the card's ID through the Serial Monitor
                Serial.println("\nHello Erin!\n");
  myRFID.AddicoreRFID_Halt(); //Command tag into hibernation

void printIPAddress()
  Serial.print("My IP address: ");
  for (byte thisByte = 0; thisByte < 4; thisByte++) {
    // print the value of each byte of the IP address:
    Serial.print(Ethernet.localIP()[thisByte], DEC);


The code, as it is, prints the IP address and then loops through the code but the reader doesn’t work.

If I delete the printIPAddress() method, the RFID works normally.

But if I read a card and then tell it to printIPAddress(), it doesn’t work from there further.

(Don’t worry about the rest of the project, I should be able to manage from now on if someone helps me solve this. If not, I will post again :D)

Thank you very much!