0

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.

3
  • There are many readers. They may not all connect in the same way. Please add details of the ones you plan to use.
    – joan
    Apr 13, 2022 at 16:06
  • Did you already connect one RFID reader to your RPi? If not, try this first. What software did you use? Show how the reader is connected to the RPi. In case of SPI connection, is the reader master or slave? Please edit your question to answer.
    – Bodo
    Apr 13, 2022 at 16:23
  • This RFID module: components101.com/wireless/rc522-rfid-module
    – Kaigo
    Apr 14, 2022 at 12:03

2 Answers 2

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)
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.