MFRC-522 not working with Orange Pi Zero


gailu

Recommended Posts

Hi Experts,

 

I am using Readily available MFRC522 NFC reader board. It works fine on Raspberry Pi but we are not able to read card on Orange Pi Zero. I followed steps in the below posts. Both are same and person posted confirmed that it works for him

 

https://forum.armbian.com/index.php/topic/617-wip-orange-pi-one-support-for-the-upcoming-orange-pi-one/page-9#entry5747

http://stackoverflow.com/questions/41350031/dual-rc522-on-orange-pi

 

Person who published the post says that he tested on 5.04 and I am using image Armbian_5.24_Orangepizero_Debian_jessie_3.4.113.img

 

We have checked wiring again and again and wiring looks all OK. read.py runs but when card is touched to the reader I do no see any output from read.py.

 

Any idea what could be the problem?

Link to post
Share on other sites
Donate and support the project!

Person who published the post says that he tested on 5.04 so I am trying to find image 5.04 to see if SPI is broken between 5.04 and 5.24/5.25. However I am not able to find 5.04 image for Orange Pi Zero. Can someone please provide any direction where could I find 5.04 image for Orange Pi Zero.

Link to post
Share on other sites

I run spidev_test (https://raw.githubusercontent.com/raspberrypi/linux/rpi-3.10.y/Documentation/spi/spidev_test.c) and following is the output.

 

Not sure how to interpret the output. Does below output look ok?

 

spi mode: 0
bits per word: 8
max speed: 500000 Hz (500 KHz)
 
00 00 00 00 00 00
00 00 00 00 00 00
00 00 00 00 00 00
00 00 00 00 00 00
00 00 00 00 00 00
00 00 00 00 00 00
00 00
Link to post
Share on other sites

@Igor,

 

Can you please let me know what is the expected data for spi loopback test i.e. shorting MOSI and MISO pins. I am reading all zeros in loopback test with spidev_test.c (orange pi zero / ubuntu xenial). I would like to ensure that all is fine with SPI on Orange Pi Zero before I debug with external SPI card.

 

For example expected data on Raspberry pi for spi loop back test is as follows as explained in (https://www.raspberrypi.org/documentation/hardware/raspberrypi/spi/README.md)

 

wget https://raw.githubusercontent.com/raspberrypi/linux/rpi-3.10.y/Documentation/spi/spidev_test.c
gcc -o spidev_test spidev_test.c
./spidev_test -D /dev/spidev0.0
spi mode: 0
bits per word: 8
max speed: 500000 Hz (500 KHz)

FF FF FF FF FF FF
40 00 00 00 00 95
FF FF FF FF FF FF
FF FF FF FF FF FF
FF FF FF FF FF FF
DE AD BE EF BA AD
F0 0D

Link to post
Share on other sites

@zador.blood.stained

 

Thanks for the details. I thinks I was missing this main information that you just provided. Everywhere I read that SPI readily available on OPis and I see /dev/spidev0.0 on plain vanilla image so I thought that this is what I need to use. My bad

 

My loopback test is successful now

Link to post
Share on other sites

@msev

 

Sure, because of forum help I got it working so its my turn to help others. Yes, I use RC-522 in python.

 

Here are steps. 

1. Install Armbian image for orange pi zero. Please use Ubuntu Xenial (not the debian jessie). Reason for Ubuntu Xenial instead of debian jessie is that in debian jessie image by default only spi0 is enabled so you will only see /dev/spidev0.0 while in ubuntu xenial image you will see two entries /dev/spidev0.0 and /dev/spidev1.0 we need /dev/spidev1.0 as explained by zador.blood.stained. If you know how to enable spi1 in debian jessie, you may go for that too (its not available out of the box currently)

 

2. Make Connection as follows

MOSI ——————————> pin 19

MISO ——————————-> pin 21
SCLK ——————————-> pin 23
SDA ——————————–> pin 24
RST ———————————> pin 22
IRQ ———————————-> NONE

 

3. Install all the required stuff as follows

 

a) apt-get update
b )apt-get install python-dev
c) git clone https://github.com/duxingkei33/orangepi_PC_gpio_pyH3.git
d) cd orangepi_PC_gpio_pyH3
e) python setup.py install
f) cd ..
g) git clone https://github.com/lthiery/SPI-Py.git
h) cd SPI-Py
i) python setup.py install
j) cd ..
k) git clone https://github.com/mxgxw/MFRC522-python.git
l) cd MFRC522-python
 
4. Now its time to edit MFRC522.py. I am providing the diff with the original.
< import pyA20.gpio as GPIO
---
> import RPi.GPIO as GPIO
110c110
<   def __init__(self, dev='/dev/spidev1.0', spd=1000000):
---
>   def __init__(self, dev='/dev/spidev0.0', spd=1000000):
112,114c112,114
< #    GPIO.setmode(GPIO.BOARD)
< #    GPIO.setup(22, GPIO.OUT)
< #    GPIO.output(self.NRSTPD, 1)
---
>     GPIO.setmode(GPIO.BOARD)
>     GPIO.setup(22, GPIO.OUT)
>     GPIO.output(self.NRSTPD, 1)
384c384
< #    GPIO.output(self.NRSTPD, 1)
---
>     GPIO.output(self.NRSTPD, 1)


5. Now Run Read.py

root@orangepizero:~/MFRC522-python# python Read.py
Welcome to the MFRC522 data read example
Press Ctrl-C to stop.
Card read UID: 186,123,162,171
Size: 8
Sector 8 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

Link to post
Share on other sites

@gailu 

Quote

Sure, because of forum help I got it working so its my turn to help others. Yes, I use RC-522 in python.

 

These directions no longer work as of 3.4.113-sun8i Ubuntu Xenial 16.04

What version of Ubuntu were you running when it worked? I second GokhanGokcein saying that, "spi output is always 0."
Any thoughts are welcome. This is the 2nd SPI/Armbian project that might sit in a drawer for quite awhile. :(

Link to post
Share on other sites

I got a MFRC522 module working on Orangepi Zero. I could get really long winded about how it took 3-4 tutorials, hopping around between GPIO libraries getting irritated with people for not posting kernel specifics and referring to Orangepi Zero/PC/One simply as 'OrangePi' but I'm not going to. Instead I took the information I gleaned, put it all together in one spot, all nice and tidy for the community.

All in all the steps are pretty similar to what I found here, other forums and tutorials. Except uses a better GPIO library specifically for the Orangepi Zero. Not a clone of RPI.GPIO, ported to Orangepi PC, ported to the Zero. So give this guy some credit! https://github.com/rm-hull/OPi.GPIO


You can download, install all dependencies and start reading tags with this one line. It goes without saying that it should be executed as root.

git clone https://github.com/BiTinerary/OrangePiZeroMFRC522.git && bash ./OrangePiZeroMFRC522/getAllTheStuff.sh

 

All the source of that one liner as well as pinout etc... is available at this repo.
https://github.com/BiTinerary/OrangePiZeroMFRC522

Link to post
Share on other sites
Guest
This topic is now closed to further replies.