Software SPI

Hello all! Many of you may face a problem in interfacing your sensors which use SPI interface with your arduino. I have modified existing RFID library so that you can connect RFID-MRC522 sensor (or any other SPI sensor) to any pin of arduino and use Software SPI technique to communicate.

Tested with Arduino UNO & NANO.

you can find it on: github.com/abhaysbharadwaj/RFID-MRC522

it uses the DigitalIO library to invoke software spi.

hope this helps someone! :) cheers!

Hi!
Thanks for you work! With your library my RFID start working!
But I had some truble when I added SD library to my project (used hardware SPI).
I used your example code and example code from SD library.
Here’s my code

//SD BEGIN
#include <SPI.h>
#include <SD.h>
//SD END
//RFID BEGIN
#include "RFID.h"
#include <DigitalIO.h> // our software SPI library
//RFID END


//RFID BEGIN
#define SS_PIN 8
#define RST_PIN 9
RFID rfid(SS_PIN, RST_PIN); //create an instance rfid for the class RFID
// varables to store data
String cardNum;
unsigned long RFID;
//RFID END

//SD BEGIN
Sd2Card card;
const int SD_CS = 4;
//SD END

void setup()
{ 
  Serial.begin(9600);
  pinMode(10,OUTPUT);
  Serial.println("initilizing RFID...");
  rfid.init(); // initilize the RFID module
  Serial.println("start ");
}

void loop()
{
 readRfid();
 printRfid();
 
}

void readRfid()
{
  if (rfid.isCard())
  {
    if (rfid.readCardSerial())
    {
      for (int i=0; i<=4; i++)//card value: "xyz xyz xyz xyz xyz" (15 digits maximum; 5 pairs of xyz)hence 0<=i<=4 //
      {
        RFID = rfid.serNum[i];
        cardNum += RFID; // store RFID value into string "cardNum" and concatinate it with each iteration
      }
    }
  }
  rfid.halt();
}

void printRfid()
{
 if (cardNum != '\0')//if string cardNum is not empty, print the value
 {
    Serial.println("Card found");
    Serial.print("Cardnumber: ");
    Serial.println(cardNum);
    printSD();
    cardNum.remove(0);
   //This is an arduino function.
  //remove the stored value after printing. else the new card value that is read
  // will be concatinated with the previous string.

  delay(500); 
 }
}

void printSD()
{
  if (!card.init(SPI_HALF_SPEED, SD_CS)) {
    Serial.println("initialization failed. Things to check:");
    Serial.println("* is a card inserted?");
    Serial.println("* is your wiring correct?");
    Serial.println("* did you change the chipSelect pin to match your shield or module?");
    return;
  } else {
    Serial.println("Wiring is correct and a card is present.");
  }
  // print the type of card
  Serial.print("\nCard type: ");
  switch (card.type()) {
    case SD_CARD_TYPE_SD1:
      Serial.println("SD1");
      break;
    case SD_CARD_TYPE_SD2:
      Serial.println("SD2");
      break;
    case SD_CARD_TYPE_SDHC:
      Serial.println("SDHC");
      break;
    default:
      Serial.println("Unknown");
  }

}

Error is libraries\DigitalIO\src/DigitalPin.h:104:69: error: new declaration ‘void badPinNumber()’

attribute((error(“Pin number is too large or not a constant”)));

UPD: Solve the problem by using SDFat library.