Tuesday, March 2, 2021

How To Setup Raspberry and RFID RC522 With very simple

Setup the RFID RC522 to Raspi like this:

- SDA connects to GPIO8 (Physical Pin 24)

- SCK connects to GPIO11 (Physical Pin 23)

- MOSI connects to GPIO10 (Physical Pin 19)

- MISO connects to GPIO9 (Physical Pin 21)

- GND connects to Breadboard Ground Rail. (20)

- RST connects to GPIO25 (Physical Pin 22)

- 3.3v connects to 3.3v (Physical Pin 1)





Enabled SPI (Interfaces)

pi@pi:~ $ sudo raspi-config

enabled SPI and reboot

pi@pi:~ $ sudo reboot


Test

pi@pi:~ $ lsmod | grep spi

spidev                 20480  0

spi_bcm2835            20480  0


Install

pi@pi:~ $ sudo pip3 install spidev

Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple

Requirement already satisfied: spidev in /usr/lib/python3/dist-packages (3.4)

pi@pi:~ $ sudo pip3 install mfrc522

Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple

Collecting mfrc522

  Downloading https://files.pythonhosted.org/packages/d5/b5/d33c0634cece0931c3c4e0978b0db58f248045c3b379ccf2d512b76fe044/mfrc522-0.0.7-py3-none-any.whl

Requirement already satisfied: RPi.GPIO in /usr/lib/python3/dist-packages (from mfrc522) (0.7.0)

Requirement already satisfied: spidev in /usr/lib/python3/dist-packages (from mfrc522) (3.4)

Installing collected packages: mfrc522

Successfully installed mfrc522-0.0.7


Make Directory and Python file

pi@pi:~ $ mkdir ~/pi-rfid

pi@pi:~ $ nano ~/pi-rfid/read.py

#!/usr/bin/env python
import RPi.GPIO as GPIO

from mfrc522 import SimpleMFRC522



reader = SimpleMFRC522()

try:

        id, text = reader.read()

        print(id)

        print(text)

finally:

        GPIO.cleanup()



Save it and test the file and tap the card

pi@pi:~ $ python3 ~/pi-rfid/read.py

627793730761


pi@pi:~ $ python3 ~/pi-rfid/read.py

658172191773