RFID-MFRC522 module on Orangepi Zero running Armbian 5.27 Ubuntu Xenial.
When trying to get an RFID module to work with Orangepi Zero, there was alot of mixed information across forums and instructions. Some directions didn't even specify board model, only referencing OrangePi but supplying GPIO pins.
Additionally, at the time of this repo's creation, all tutorials found use some hodgepodge mix match of other GPIO (RPI.GPIO/PyA20.GPIO) libraries that require editing MFRC522's source code, etc... Anyways, this is an attempt to collect all that information, simplify it, correct it and document it in one place.
- Module: MFRC522 aka RFID-RC522 module |Buy|
- Board: Orangepi Zero v1.4 |Buy|
- Kernel: Armbian 5.27 3.4.113-sun8i Ubuntu Xenial 16.04 |Download|
- GPIO Library for Orangepi Zero: https://github.com/rm-hull/OPi.GPIO
- SPI Library: https://github.com/lthiery/SPI-Py.git
Included in this repo is a modified clone of the above MFRC522 repo. The appropriate lines have been editted to work with Orangepi Zero. This includes replacing line 1 import RPI.GPIO as GPIO
with import OPi.GPIO as GPIO
in all scripts and changing Line 110 (in MFRC522.py) from spidev0.0
to spidev1.0
.
This is the proper way to connect MFRC522 module to Orangepi Zero board via SPI. First column lists pin names as seen on module, verbatim. Second is the Orangepi Zero's literal pin number. Third column is the OPiZero's pin function as seen from a data sheet. Third column is especially useful when trying to match up modules pin titles to schematic of a different board.
Both pin numbers and functions listed below are useful depending on reference material and if trying to determine proper pinout for a SPI/I2C module on a different board model.
MFRC522 | OPi Zero Pin Number | Pin Function |
---|---|---|
SDA | Pin 24 |
SPI1_CS/PA13 |
SCK | Pin 23 |
SPI1CLK/PA14 |
RST | Pin 22 |
UART2_RTS/PA02 |
MISO | Pin 21 |
SPI1_MISO/PA16 |
MOSI | Pin 19 |
SPI1_MOSI/PA15 |
GND | Pin 6 |
GND |
3.3v | Pin 1 |
3.3v |
- The coordinantes that have been struck were based on this popular, but misleading picture.
git clone https://github.com/BiTinerary/OrangePiZeroMFRC522.git && bash ./OrangePiZeroMFRC522/getAllTheStuff.sh
or the long manual way...
apt-get install python-dev -y
apt-get install python-pip -y
pip install --upgrade pip
pip install setuptools
git clone https://github.com/rm-hull/OPi.GPIO.git
cd OPi.GPIO
pip install .
cd ..
git clone https://github.com/lthiery/SPI-Py.git
cd SPI-Py
pip install .
cd ..
git clone https://github.com/BiTinerary/OrangePiZeroMFRC522.git
python ./OrangePiZeroMFRC522/MFRC522-python/Read.py
Swipe RFID chip >> Run command/script associated with that RFID tag. A hardware spin off of https://github.com/BiTinerary/PersonalAPI
triggerRead.py is the same source as original Read.py with a few modifications, mainly in the middle. Print statements were removed throughout the source files (dump/read/MFRC/Write) just to clean up the output. I added a hashFile.txt which stores the UID of RFID chips as keys and commands as values. So that effectively when a RFID chip is scanned, a corresponding command is executed. This all happens line 45-58
I'm using a practical version of this repo and the triggerRead.py script mentioned above for a Google Sheet/API punching TimeClock, over here: https://github.com/BiTinerary/TimeClockPi
The main MFRC522 script in this repo is just a modified fork of https://github.com/mxgxw/MFRC522-python
RM-Hull has some other cool repos with more coming down the pipe.