1

I'm trying to connect x9 RC522 RFID readers to an RPI.

I'm wondering if it can be done using the standard RPi GPIO pins or if I need some other controller.

Also, it's worth mentioning that it will need to be able to distinguish between the readers, and know which one is providing which data.

And I'm not sure if I use a port expander, something like this, if the data stream will get "tagged" to identify which reader it came from.

Kaigo
  • 163
  • 1
  • 3
  • 8

2 Answers2

3

did this exact thing using 5x RFID-RFC522 Readers.

You can use the RST Pins to select the reader you want to use. Connect all the other pins in parallel (see schematic below). Just set all the RST pins to low, except the one on the pin you want to use. Set that one to high. Then initialize SPI, read/write, and close SPI again.

I wrote a more detailed explanation here.

This is the schematics and code I made:

Schematic for 2 readers: Schematic for 2 readers

Schematic for 4 readers: Schematic for 4 readers

Code to run it all (using pimylifeup's MFRC522-Python Library):

import RPi.GPIO as GPIO
from mfrc522 import SimpleMFRC522
import spidev

class NFC(): def init(self, bus=0, device=0, spd=1000000): self.reader = SimpleMFRC522() self.close() self.bus self.boards = {}

    self.bus = bus
    self.device = device
    self.spd = spd

def reinit(self):
    self.reader.READER.spi = spidev.SpiDev()
    self.reader.READER.spi.open(self.bus, self.device)
    self.reader.READER.spi.max_speed_hz = self.spd
    self.reader.READER.MFRC522_Init()

def close(self):
    self.reader.READER.spi.close()

def addBoard(self, rid, pin):
    self.boards[rid] = pin

def selectBoard(self, rid):
    if not rid in self.boards:
        print("readerid " + rid + " not found")
        return False

    for loop_id in self.boards:
        GPIO.output(self.boards[loop_id], loop_id == rid)
    return True

def read(self, rid):
    if not self.selectBoard(rid):
        return None

    self.reinit()
    cid, val = self.reader.read_no_block()
    self.close()

    return val

def write(self, rid, value):
    if not self.selectBoard(rid):
        return False

    self.reinit()
    self.reader.write_no_block(value)
    self.close()
    return True


if name == "main": nfc = NFC() nfc.addBoard("reader1",5) nfc.addBoard("reader2",6)

data = nfc.read("reader1")
nfc.write("reader2",data)

Lugico
  • 41
  • 3
1

I found a few issues with the code while trying to run it on my Raspberry Pi 3...

  1. in the init area, the first self.bus throws an error because it's not being set to anything. a few lines down you do set it a value, so I removed the first instance of it, and it cleared that error.

  2. when the code gets to the nfc.read function, an error is thrown during the FOR loop in the self.SelectBoard function. the error is "Runtime Error: the GPIO channel has not been set up as an OUTPUT." this was fixed by adding the following line of code to the self.addboard function... GPIO.setup(pin, GPIO.OUT) that sets whatever pin you are using as the reset/chip select pin to an output. after these changes, the code runs smoothly.

I hope this helps anyone who is also using multiple of these RFID-RC522 modules for anything.