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:

it uses the DigitalIO library to invoke software spi.

hope this helps someone! :) cheers!

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

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

#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;

Sd2Card card;
const int SD_CS = 4;

void setup()
  Serial.println("initilizing RFID...");
  rfid.init(); // initilize the RFID module
  Serial.println("start ");

void loop()

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

void printRfid()
 if (cardNum != '\0')//if string cardNum is not empty, print the value
    Serial.println("Card found");
    Serial.print("Cardnumber: ");
   //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.


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?");
  } 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:
    case SD_CARD_TYPE_SD2:


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.