ACR122U NFC USB reader on a Raspberry Pi
|
The ACR122U USB NFC Reader is usually connected to a PC or laptop but, of course, nothing is keeping you from connecting it to a Raspberry Pi instead. It took me some time and effort to get it all up and running but with some experimenting it finally worked out pretty good. For future reference and other Raspberry Pi users Googling for clues on how to install the drivers and packages, I describe the procedure below.
Installing the ACR122U USB NFC tag reader on a Raspberry Pi running Raspbian
The type of NFC reader I am using for this experiment is a ACR122U-A9 by Advanced Card Systems. This reader is connected by USB to a Raspberry Pi model 2B running Raspbian (version May 2015, release date 2015-05-05, Debian Wheezy, kernel 3.18).
First, we need to update the package lists and download and install some required packages:
sudo apt-get update
sudo apt-get -y install subversion autoconf debhelper flex libusb-dev libpcsclite-dev libpcsclite1 libccid pcscd pcsc-tools libpcsc-perl libusb-1.0-0-dev libtool libssl-dev cmake checkinstall
Then we download, extract, configure and install libnfc:
wget https://github.com/nfc-tools/libnfc/releases/download/libnfc-1.7.0-rc7/libnfc-1.7.0-rc7.tar.gz
tar -xvzf libnfc-1.7.0-rc7.tar.gz
cd libnfc-1.7.0-rc7
./configure --with-drivers=acr122_usb
make
sudo make install
If all went well, issuing this command will list your ACR122U and any tags present:
sudo nfc-list
But if it shows “nfc-list: error while loading shared libraries: libnfc.so.4: cannot open shared object file: No such file or directory” instead, then try this:
sudo sh -c "echo /usr/local/lib > /etc/ld.so.conf.d/usr-local-lib.conf"
sudo ldconfig
After doing so, you can try again with the command “nfc-list”.
sudo nfc-list
If it says “Unable to claim USB interface” then you need to prevent modprobe from autoloading the pn533 and nfc modules by blacklisting them. To do so, create the file “blacklist-libnfc.conf” by using nano:
sudo nano /etc/modprobe.d/blacklist-libnfc.conf
Add the following two lines to the empty file, save (CTRL+O), and exit (CTRL+X):
blacklist pn533
blacklist nfc
Then all you need to do is this:
sudo modprobe -r pn533 nfc
Finally, “nfc-list” should now work without errors.
sudo nfc-list
It will show you some information about the NFC reader and the NFC tag, if one is present.
And now you can use the ACR122U USB NFC Reader on your Raspberry Pi!
Very thank you for your article.
But I am struck since I disabled the pn533, the LED and Buzzer on the ACR122U doesn’t work. I am using acr122u-a9.
hello, i’ve installed acr122u on raspberry following your steps (thanks a lot!! ). now i need a program for read what kind of nfc tags from acr122u on raspbian. Do you have some advises?
thank you very much!!
Mat
help me please, i missing error when acces : get https://libnfc.googlecode.com/files/libnfc-1.7.0-rc7.tar.gz
HTTP request sent, awaiting response… 404 Not Found
then i continued, when i type nfc-list,
error (Operation not permitted)
nfc-list: Error: Unable to open NFC device: acr122_usb:001:005
thanks !
Thanks for alerting me! The files apparently were removed from GoogleCode and are now only on Github: https://github.com/nfc-tools/libnfc/releases.
The wget command should now be:
wget https://github.com/nfc-tools/libnfc/releases/download/libnfc-1.7.0-rc7/libnfc-1.7.0-rc7.tar.gz
I will update the post a.s.ap. 🙂
Hi Roy, the post has been updated with the new url for the wget command. Hopefully this works for you, let me know if there are any problems.
thankyou for help, it’s helpfull
the link now work, but i have any problem at the driver of nfc (error libnfc.driver.acr122_usb)
can you give a solutions to fix the problem, please
Did you create and edit the blacklist file (/etc/modprobe.d/blacklist-libnfc.conf) as mentioned in the post?
If you did so and it didn’t work, can you give me the complete error message and tell me after which command it occurs?
it’s the complete error :
[email protected]:~ $ nfc-list
nfc-list uses libnfc 1.7.0-rc7
error libnfc.driver.acr122_usb Unable to claim USB interface (Operation not permitted)
nfc-list: ERROR: Unable to open NFC device: acr122_usb:001:004
I think, i did all the instructions, help me please !
It looks like the blacklisting didn’t work. Did you try:
sudo nano /etc/modprobe.d/blacklist-libnfc.conf
Add lines:
blacklist pn533
blacklist nfc
Disable kernel modules:
modprobe -r pn533 nfc
Restart pcscd:
sudo service pcscd restart
Also try rebooting the Pi, let me know if this works.
i had the same problem, but when i use the nfc-list command with sudo . it works.
[email protected]:~ $ sudo nfc-list
nfc-list uses libnfc 1.7.0-rc7
NFC device: ACS / ACR122U PICC Interface opened
2 ISO14443A passive target(s) found:
ISO/IEC 14443A (106 kbps) target:
ATQA (SENS_RES): 00 44
UID (NFCID1): 04 b1 53 ba 7a 48 80
SAK (SEL_RES): 00
Thanks Rolando, and good to hear that you got it working. I will add the sudo command to the tutorial 🙂
Ok thanks, i’ll try it.
Do you have a tutorial to write and read smartcard using java program on raspberry please ?
I’m not very experienced in Java programming, but I’ll see what I can do for you. It might take a while though :p
Also, if you still can’t get your ACR122U drivers to work on your Pi, you could try to install it on a fresh, clean image of Raspbian.
you right, i think i’ll reinstall the PI, what version of raspbian that you suggest ?
give me solutions for this problem please, i never using the python program, so i just using java.
I used version May 2015, release date 2015-05-05, Debian Wheezy, kernel 3.18 for the tutorial. Just use a recent version, it should not really matter.
I will try put up a short Java tutorial soon.
thankyou sir, do you hve a library javaFX.smartcardio ?
Hi Roy, javax.smartcardio is included in Java, as far as I know. I have put up a very rough draft version of the tutorial, you can find it here: ACR122U NFC: programming with Java and Eclipse on a Raspberry Pi. It has example code on how to access the NFC122U and how to read the UID of a tag. I will put up some more information on how to actually read/write tags soon.
i have acs acr122u smartcard reader. and I am using it with raspberry pi 2. everything works fine normally. but sometimes i am getting some errors.
what is wrong with it ? reader reads 25 nfc uid but i see 21 uid 4 error message which error below.
smartcard.Exceptions.CardConnectionException: Unable to connect with protocol: T0 or T1. Card is unpowered
Hi, i have a problem with pn533 Module ; my error is “modprobe: FATAL: Module pn533 not found.” , what should i do ,please ?
Perhaps you know the reason. I set everything up according to your instructions, R pi 3, downloaded the last raspbian.
The reader in the scan mode through pcsc_scan in the standby mode hangs somewhere for about 5-10 minutes and the reader is turned off. In what there can be a reason and where to search for additional information on a problem? Thank you.
Is your power supply able to provide sufficient current to your Pi, card reader and all other attached devices?
For a Pi3 it should be 2.5A power supply. Is the red power LED on the Pi blinking?
Edit: also, are you connecting the card reader directly to the Pi or through a USB hub?
Yes, 2.5A power supply. Power LED work fine. No, directly. There are suspicions that the cable is weak, changed to a more powerful finish by the result. Also in the cantab added commands (@reboot modprob -r pn533 nfc). Without this, the module pn533 after restarting is turned on again (the blacklist and modeprob -r is not able to)
[email protected]:~/libnfc-1.7.0-rc7 $ sudo modprobe -r pn533 nfc
modprobe: FATAL: Module pn533 not found.
Hello I’m getting this error when run this command can u please help me
hi,
this works for me as long as the card is on the reader at the time of running the command sudo nfc-list. if however I run the command without a card present it returns back to console input within a second. is there a way I can extend the detection period or indeed make it indefinite? thanks
hi good day. Thank you for your great tutorial. it was very easy to follow and you are very informative. i have a question though
Do you have any suggestions for acr122u-NFC reader to be interface with monodevelop (C#) on raspbian?
– Does this tutorial when installed correctly as you stated will make acr122u led and buzzer work?
hi
in my case the tutorial works fine:
> sudo nfc-list
nfc-list uses libnfc 1.7.0-rc7
NFC device: ACS / ACR122U PICC Interface opened
1 ISO14443A passive target(s) found:
ISO/IEC 14443A (106 kbps) target:
ATQA (SENS_RES): 00 44
UID (NFCID1): 04 29 4f f2 33 43 81
SAK (SEL_RES): 00
but:
the green/red light doesn’t light up and i cannot access with my java prog on the nfc-reader.
any ideas?
Have you tired to use it as an NFC card emulation and emulate it as an NFC tag?
Same pb for me
nfc-list uses libnfc 1.7.0-rc7
NFC device: ACS / ACR122U PICC Interface opened
but:
the green/red light doesn’t light up and i cannot access with my python prog on the nfc-reader.
I have an ACR122U-A9… I have tried two seperate machines, each running Ubuntu 18.04.. the pcsc driver ‘works’ but often hangs the device in mfoc etc.
using the above instructions and the acr122_usb driver , blacklisting the suggested modules, and stopping pcscd results in this message: error libnfc.driver.acr122_usb Unable to set alternate setting on USB interface (Connection timed out)
nfc-list: ERROR: Unable to open NFC device: acr122_usb:003:019
I’m stummped – any ideas?
Same problem….did you solve it?
– Does this tutorial when installed correctly as you stated will make acr122u led and buzzer work?