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)
Hello, I get "AUTH ERROR(status2reg & 0x08) != 0" errors when I write data on the tags with my smartphone before I read them with the rc522(Read.py).
ReplyDelete(It works like in your example if a remove the Data again)
I also get this error when I use other Tags like the NTAG213! Any Ideas what causes my problem ?
Merci beaucoup pour ces configurations qui ont fait refonctionner mon rc522 avec mon pi :)
ReplyDeleteIl avait toujours fonctionner puis du jour au lendemain plus rien. Les lignes rajoutées dans le /boot/config.txt ont résolu le problème
It is a good Quality RFID Post thanks for sharing .
ReplyDeleteSorry ge3ko1. My work is very busy.
ReplyDeleteSPI-Py and MFRC522-python are example code.
Maybe data structure (Data format) of card (write with smartphone) difference from example code for read it.
It display error message.
I should find more information and modify example code for use it. Or find new library for read data from card (write with smartphone).
Good luck ;)
very nice for get information use rfid-RC522 on Raspbian .
ReplyDeleteHi,I following you tutorial..but when i touch the card..it dooesnt have any information from my card and it without any error massage..how can i solve it?
ReplyDeleteI think you use new raspbian image or new kernel. (4.4.x)
Deletespi-bcm2708 is missing on new kernel.
and Device Tree overlays parameter changed.
change file /boot/config.txt with below line.
dtparam=spi=on
or use sudo raspi-config command to enable SPI
see more information
https://github.com/raspberrypi/firmware/tree/master/boot/overlays
If I have free time, I will check it again.
See on post by xvolte
https://www.raspberrypi.org/forums/viewtopic.php?f=37&t=106313&sid=c2f08cd89fee0405fa1422b70fdfce72&start=25
Maybe it can help use.
Change the RST PIN to PIN 18.
Change on MFRC22.py file. (Change spidev and pin)
https://github.com/mxgxw/MFRC522-python/blob/master/MFRC522.py
Good Luck ;)
Any idea as to the instructions for doing this on a raspberry pi 3?
ReplyDeleteThanks for sharing informative post with us.
ReplyDeleteDaccess security services provider in pune.
vehicle tracking system suppliers in mumbai
Works exactly the same on PI 3. Don't forget to enable SPI
ReplyDeletedoes not work the same on pi 3 been looking for a solution for hours
ReplyDeleteDear ,
ReplyDeleteI connected the 7" inch LCD(800*400 pixel) which is connected to the Raspberry pi through HDMI and USB. The setup is working properly.
The second link is to connect the RFID-RC522 to the Pi. This independently works without any issues.
The issue is when i install both, the RFID-RC522 reader doesn't work. It aborts the connection.
how we have to solve other wise how we connect the RFID-RC522 with I2C for read Tag ID
Can you please help me out with this issue?
1.https://alselectro.wordpress.com/2016/08/20/7-touch-screen-lcd-for-raspberry-pi-driver-installation-with-virtual-keyboard/
2.http://raspmer.blogspot.in/2015/07/how-to-use-rfid-rc522-on-raspbian.html
RFID-RC522 is SPI Interface. It cannot connect with I2C.
DeleteI don't know driver of 7" inch LCD. It will have some problem
with SPI.???
Maybe you should recheck about SPI config. It should enabled.
I wanted a c program for rc522 rfid sensor. Where will I find one? The python one runs perfectly, but I need a c program for my project
ReplyDeleteTry to see.
Deletehttps://github.com/paguz/RPi-RFID
https://github.com/paulvha/rfid-rc522
https://dev.hawry.net/rc522-on-the-raspberry-pi-without-python/
Not sure if my comment went through...
ReplyDeleteI was asking if I can connect my RFID reader/writer to these pins: https://ibb.co/fNxuH6 since I am using a touchsreen. There is also a conflict with SPI since both use it so should I change the RFID to CE2? If so where in the code should all this be initialized?
Found this tutorial on how to enable these pins: https://tutorials.technology/tutorials/69-Enable-additonal-spi-ports-on-the-raspberrypi.html
DeleteNow need to figure out how to modify the RFID code so that it matches these new pins setup.
I think.
DeleteIf you use spi1-3cs overlay.
https://tutorials.technology/tutorials/69-Enable-additonal-spi-ports-on-the-raspberrypi.html
SPI1
GPIO20 (Pin Header Number 38) – MOSI
GPIO19 (Pin Header Number 35) – MISO
GPIO21 (Pin Header Number 40) – SCLK
GPIO18 (Pin Header Number 12) – CE0
See more detail of overlay and parameter
https://github.com/raspberrypi/firmware/tree/master/boot/overlays
check about correct pin on raspberry pi.
and change the code from /dev/spidev0.x to /dev/spidev1.x for use spi1
*** I never use or test spi1
Have a good luck
whenever we not place the Tag correctly at time only showing the error
ReplyDeleteHello
ReplyDeletei need help. i want to use this with a web interface where you can see the checks in a web page. i hope someone could help me
thanks a lot
howdy was quite recently checking whether you disapproved of a remark.
ReplyDeletehttps://www.starnfc.com/
Thank you very much for this post. I didn't notice the IRQ pin to PIN 18 in other posts and because of that I have been looking for a way to fix it for a long day.
ReplyDeleteWelcome. Good news for you.
DeleteI updated this post for fix RFID-RC522 not work with new kernel version of Raspbian.
The new kernel use spi_bcm2835 instead spi-bcm2708.
Include IRQ pin to PIN 18 for pi-rc522 library.
Hope you enjoy with it.
Hi, Its not working for new kernel version. I did all your steps. How do I fix this?
ReplyDeleteWhat's about you problem? Please explain.
DeleteMaybe you try to check your connection pin. Is it all correct?
ReplyDeleteThanks a lot for the good News, your Post was very helpfull. Could you please give a wiring-example how to connect two rc522 to Rpi3 using irq-pin and spi0/ce0/ce1 ? Thank you in advance for ervery hint.
GPIO - Raspberry PI Document
Deletehttps://www.raspberrypi.org/documentation/usage/gpio/
SPI PIN
- SPI0: MOSI (GPIO10); MISO (GPIO9); SCLK (GPIO11); CE0 (GPIO8), CE1 (GPIO7)
- SPI1: MOSI (GPIO20); MISO (GPIO19); SCLK (GPIO21); CE0 (GPIO18); CE1 (GPIO17); CE2 (GPIO16)
You can connect use SPI0 for first and SPI1 for second of RFID-RC522 and select IRQ-Pin other pin for second of RFID-RC522.
Then change spidev device to 1 for spi1 and pins in code file for support them.
https://github.com/ondryaso/pi-rc522/blob/master/pirc522/rfid.py
*** I don't test it.
Hello,
ReplyDeletei want to override the keys i have. Will change the ID from Number xxxxxxxxx to a name. What i have to do with the KeyChange.py??
thx
https://blog.atlasrfidstore.com/rfid-basics-read-write-tags
Deletehttps://www.getkisi.com/blog/how-to-calculate-facility-code-using-card-bit-calculators
https://blog.atlasrfidstore.com/encoding-rfid-tags-3-things-to-know
Man, thanks for updating this for the new kernel version, love you
ReplyDeleteFZP
how to clear the RFID tag?
ReplyDeleteThank you for your post. This is excellent information. It is amazing and wonderful to visit your site.
ReplyDeleteRFID key cards
RFID key cards hotel
Custom hotel key cards
Thankyou so much for the precious information you have given to us
ReplyDeleteGuard Tour System
hi i am using raspberry pi 3 B + with latest raspbian stretch.. i followed your steps..all my pins are correctly connected but when i start the read.py code and touch the rfid tag to the reader, nothing happens..any help please???
ReplyDeleteThanks for sharing your valuable information and time. Please keep updating.
ReplyDeleteRFID Singapore
Relevant post! Keep sharing such kind of post. Explore DsaTech for CCTV Installation Services and all your security needs.
ReplyDelete