1

I am following this tutorial to get my raspberry pi set up with an RFID module. Unfortunately, I cannot get it to work.

Specifications

  • Raspberry pi 4 Model B
  • Raspbian GNU/Linux 11 (bullseye)
  • Mifare RC522 RF IC
  • Using Thonny to run it

Set up

enter image description here

enter image description here

enter image description here

Current Issue/Code & Warnings

As I was going through the tutorial mentioned above, I got to the point where I would run my code and it would not allow me to interact with the hardware itself. For clarity, I seem to be stuck when using the SimpleMFRC522 instantiation for my read.py (as well as my write.py). When I go to tap the card onto the RFID scanner, nothing happens and I am unsure why.

Read.py

#!/usr/bin/env python

import RPi.GPIO as GPIO
from mfrc522 import SimpleMFRC522

reader = SimpleMFRC522()

try:
        print("Tap the card")
        id, text = reader.read()
        print(id)
        print(text)
finally:
        GPIO.cleanup()

Read.py output

Python 3.9.2 (/user/bin/python3)
>>> %Run read.py
 /usr/local/lib/python3.9/dist-packages/mfrc522/MFRC522.py:151: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings.
   GPIO.setup(pin_rst, GPIO.OUT)

 Tap the Card

enter image description here

Things I've Tried

  • Reinstall Raspbian OS
  • Swapped out the RFID Scanner with a new one
  • Confirmed that the SPI is active in config.txt file (mentioned in the tutorial)
  • Completed all sudo commands mentioned in the tutorial
2
  • The SPI part is tricky. You might like to see how I set up and debug in my answer to the following question. (Part 3 and Appendices A, B. I did no use any sudo commands, but just Thonny python). raspberrypi.stackexchange.com/questions/138612/…
    – tlfong01
    Aug 11, 2022 at 4:42
  • The SimpleMFRC522 might not like your Thonny microPython's SPI, and this might be the root cause of your problem.
    – tlfong01
    Aug 11, 2022 at 5:40

2 Answers 2

1

is your user account member of the 'spi' group? to see what groups you are in:

groups addi

and to add your user to a specific group:

sudo usermod -a -G spi addi

this adds the user 'addi' to the group 'spi' which you need to be in to access spi

0

The most popular tutorials don't work (at least when I tried). It is possible there may be different breakout boards.

I decided to debug and found what appear to be incorrect connections.

I found the following works reliably with all the code I tried.

The following may help.

Datasheet:-
    MFRC522
    Standard 3V MIFARE reader solution
    Rev. 3.8 — 17 September 2014

SPI needs to be enabled.

Correct connections
    3.3v connects to Pin 17
    MOSI connects to Pin 19
    MISO connects to Pin 21
    SCK connects to Pin 23
    GND connects to Pin 25
    SDA connects to Pin 24

     3.3v      17 || 18
    SPI0_MOSI  19 || 20
    SPI0_MISO  21 || 22
    SPI0_SCLK  23 || 24  CE0
     GND       25 || 26  CE1

The connection to RST pin 22 does not appear to be necessary (or even accessed by the software).

The pin labelled SDA actually appears to be NSS "SPI signal input" according to the MFRC522 datasheet. Connecting this to SPI CE0 and ignoring RST appears to work.

"NRSTPD" reset and power-down input:
power-down: enabled when LOW; internal current sinks are switched off, the
oscillator is inhibited and the input pins are disconnected from the outside
world
reset: enabled by a positive edge

Hard power-down is enabled when pin NRSTPD is LOW. This turns off all internal
current sinks including the oscillator. All digital input buffers are separated
from the input pins and clamped internally (except pin NRSTPD). The output pins
are frozen at either a HIGH or LOW level.

Your Answer

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

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