Current kernel in document (Raspbian GNU/Linux 9 Kernel Version 4.14.70-v7+ #1144)
Enable SPI Interface
- Use command
$ sudo raspi-configselect menu
5 Interfacing Options -> SPI -> Yes -> OK -> FinishOr
- Edit on /boot/config.txt.
change this line
dtparam=spi=on
#blacklist spi-bcm2708
Reboot Raspberry PI
sudo shutdown -r now
Re-Check SPI Interface software
$ dmesg | grep spi
[ 5.408904] bcm2708_spi 20204000.spi: master is unqueued, this is deprecated
[ 5.659213] bcm2708_spi 20204000.spi: SPI Controller at 0x20204000 (irq 80)
$ lsmod | grep spi
spidev 16384 0
spi_bcm2835 16384 0
If you found, software is enabled.
Install Software for use RFID-RC522
sudo apt-get install python-dev
git clone https://github.com/lthiery/SPI-Py.git
cd SPI-Py
sudo python setup.py install
git clone https://github.com/mxgxw/MFRC522-python.git
cd MFRC522-python
Install Python RC522 library
$ git clone https://github.com/ondryaso/pi-rc522.git
$ cd pi-rc522
$ sudo python setup.py install
Install Pins between Raspberry PI and RFID-RC522
RFID-RC522 Pin |
Raspberry PI Pin |
Raspberry PI Pin name |
---|---|---|
SDA |
24 |
GPIO8 |
SCK |
23 |
GPIO11 |
MOSI |
19 |
GPIO10 |
MISO |
21 |
GPIO9 |
IRQ |
18 |
GPIO24 |
GND |
Any |
Any Ground |
RST |
22 |
GPIO25 |
3.3V |
1 |
3V3 |
You can test read card.
$ cd examples
$ python Read.py
Starting
If touch the card, it will display.
Detected: 10
Card read UID: XX,XX,XX,XX
Setting tag
Selecting UID [XX, XX, XX, XX, XX]
Authorizing
Changing used auth key to [XX, XX, XX, XX, XX, XX] using method B
Reading
Calling card_auth on UID [XX, XX, XX, XX, XX]
S1B0: [0, 0, 105, 36, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
Deauthorizing
Changing auth key and method to None
^C
Ctrl+C captured, ending read.
And test write card.
$ python KeyChange.py
Starting
Detected: 10
Card read UID: XX,XX,XX,XX
Setting tag
Selecting UID [XX, XX, XX, XX, XX]
Authorizing
Changing used auth key to [255, 255, 255, 255, 255, 255] using method A
Writing modified bytes
Calling card_auth on UID [XX, XX, XX, XX, XX]
Changing pos 2 with current value 0 to 105
Changing pos 3 with current value 0 to 36
Changing pos 4 with current value 0 to 64
Writing [0, 0, 105, 36, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] to S1B0
Not calling card_auth - already authed
S1B0: [0, 0, 105, 36, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
Calling card_auth on UID [XX, XX, XX, XX, XX]
Changing pos 0 with current value 0 to 18
Changing pos 1 with current value 0 to 52
Changing pos 2 with current value 0 to 86
Changing pos 3 with current value 0 to 120
Changing pos 4 with current value 0 to 150
Changing pos 5 with current value 0 to 146
Changing pos 6 with current value 255 to 15
Changing pos 7 with current value 7 to 7
Changing pos 8 with current value 128 to 143
Changing pos 9 with current value 105 to 105
Changing pos 10 with current value 255 to 116
Changing pos 11 with current value 255 to 0
Changing pos 12 with current value 255 to 82
Changing pos 13 with current value 255 to 53
Changing pos 14 with current value 255 to 0
Changing pos 15 with current value 255 to 255
Writing [18, 52, 86, 120, 150, 146, 15, 7, 143, 105, 116, 0, 82, 53, 0, 255] to S1B3
Changing auth key and method to None
Stopping crypto1
You can learning python code for use RFID read and write data.
MIFARE (MFRC522) datasheet : http://www.nxp.com/documents/data_sheet/MFRC522.pdf
Python RC522 library : https://github.com/ondryaso/pi-rc522
Example Project for use NFC and Raspberry PI
- Attendance system using Raspberry Pi and NFC Tag reader by Yim
http://www.instructables.com/id/Attendance-system-using-Raspberry-Pi-and-NFC-Tag-r/
Reference :
Device Tree overlays of Raspberry PI Firmware
MIFARE (MFRC522) datasheet
http://www.nxp.com/documents/data_sheet/MFRC522.pdf
MFRC522-python (current not support in new firmware)