Raspberry Pi and NFC ACR122u – English version

Hello everybody!

In this post I’ll show you, how to do a presence control using the ACR122u reader and the Raspberry Pi B+ 2, programing with javascript, Nodejs soquet.io and MYSQL.


Imagem de Amostra do You Tube








After Terminal opening, the first step is check if all thing are updated on our Raspberry

~$ sudo apt-get update

~$ sudo apt-get upgrade

Installing Node.js via package manager:

curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs
sudo apt-get install -y build-essential

For more information on how to install Node.js visit the official site nodejs.org.

to check that everything was installed correctly enter the code below:

~$ node -v

v0 . 12 . 9 

~$ npm -v

2 . 14 . 9

You’ll have something like this.

First you need install libudev-dev:

sudo apt-get install libudev-dev

Then you need to install libusb, this should do the trick:

sudo apt-get install libusb-dev

apt-get install libpcsclite1 libpcsclite-dev
npm install pcsclite
apt-get install pcscd

Now we need to install NFC Tools:

wget https://bintray.com/artifact/download/nfc-tools/sources/libnfc-1.7.1.tar.bz2

tar xjf libnfc-1.7.1.tar.bz2

cd libnfc-1.7.1

./configure –prefix=/usr –sysconfdir=/etc


./configure –with-drivers=all –prefix=/usr –sysconfdir=/etc


sudo make install

sudo apt-get install libtool

sudo apt-get install libsystemd-dev

sudo apt-get install libpcsclite1

sudo apt-get install flex

git clone git://anonscm.debian.org/pcsclite/PCSC.git

Now will install the dependencias of ACR122u reader:

— Install the ACS Driver —
make a dowload on oficial web site of ACR122u here.

unzip the file

~$ cd acsccid-x.y.z // to access the folder

~$  ./configure

~$ make

~$ make install

The installation can spend some minutes

Now you need to configure the file libccid_info.plist on cd /etc directory

~$ cd

~$ cd /etc

~$ sudo nano libccid_info.plist

Change the following line in the file:




Ctrl + x and press y to save!

~$ cd // to return on root folder (/home/pi..)

To verify that everything worked out so far, write:

~$ sudo nfc-list // comment: see result below

nfc-list uses libnfc 1.7.1
NFC device: ACS / ACR122U PICC Interface opened

~$ sudo nfc-scan-device -v // comment: see result below

nfc-scan-device uses libnfc 1.7.1
1 NFC device(s) found:
– ACS / ACR122U PICC Interface:
chip: PN532 v1.6
initator mode modulations: ISO/IEC 14443A (106 kbps), FeliCa (424 kbps, 212 kbps), ISO/IEC 14443-4B (106 kbps), Innovision Jewel (106 kbps), D.E.P. (424 kbps, 212 kbps, 106 kbps)
target mode modulations: ISO/IEC 14443A (106 kbps), FeliCa (424 kbps, 212 kbps), D.E.P. (424 kbps, 212 kbps, 106 kbps)

I believe that everything must have worked here! In case of problems leave a comment we will solve the problem.

Acabamos a primeira fase do nosso projeto onde temos:

  • The Raspberry with the OS installed and running;
  • The ACR122u reader configured and running.

Now create a folder by typing:

~$ cd // to ensure that the root folder

~$ mkdir rfid // to create the folder

~$ cd rfid // to enter the folder

Let’s start by installing the dependencies to our project …

~$ npm install express

~$ npm install pcsclite

~$ npm install socket.io

~$ npm install mysql

  • Ready believe we installed all dependencies, but if they encounter problems tell me to review the post.

Continuing with our project created in mysql database databesname the tables using the settings below:

`evento` text CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`qty` int(1) NOT NULL DEFAULT '1'
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;

 `nome` varchar(100) DEFAULT NULL,
 `foto` varchar(100) DEFAULT NULL,
 `rfid` text CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
 `dept` varchar(20) NOT NULL,
 `turno` varchar(10) NOT NULL,
 `divi` varchar(1) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
 `Qty` int(1) NOT NULL DEFAULT '1',
 `fone` varchar(30) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
 `email` varchar(50) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL
CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `coutbyid` AS select `ck`.`evento` AS `evento`,count(`ck`.`qty`) AS `count(``qty``)` from `ck` group by `ck`.`evento`;
 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `grupo` AS select `event`.`rfid` AS `rfid`,`event`.`foto` AS `foto`,`event`.`nome` AS `nome`,`event`.`turno` AS `turno`,`event`.`divi` AS `divi`,`event`.`dept` AS `dept`,`coutbyid`.`count(``qty``)` AS `count(``qty``)` from (`event` join `coutbyid` on((`event`.`rfid` = `coutbyid`.`evento`))) order by `event`.`nome`; 

Clone the files on GitHub:

sudo apt-get clone https://github.com/PabloBInotto/A-PRESENCE-CONTROL.git


sudo npm install

Let’s test it all worked out:

1º open the terminal in raspberry;

2º  Start new.js middleware that will be responsible for reading and writing of RFID tags in the code mysql:

~$ cd rfid

~$ node new

3º In another terminal to start the HTTP server of the node:

~$ cd rfid

~$ node sv-http

4º Open your browser and access the html we created last, the page that will display that is present or absent. In vavegador Type in: http://localhost:8000


If all right gave up page will be displayed!!


Place raspberry in Kiosk mode and automatically start the sv-http server and has open the page to display our presence control:

First we have to install the chromium

~$ sudo apt-get install chromium x11-xserver-utils unclutter

Now let’s edit the file auto start

~$ sudo nano /etc/xdg/lxsession/LXDE-pi/autostart

The file should look like the following lines:

@xscreensaver -no-splash

@xset s off
@xset -dpms
@xset s noblank

@lxterminal –command “node /home/pi/rfid/sv-http.js”

@sed -i ‘s/”exited_cleanly”: false/”exited_cleanly”: true/’ ~/.config/chromium/Default/Preferences
@chromium –noerrdialogs –kiosk http://www.page-to.display

Ctrl + C  – y  – enter

Now let’s make the raspberry connect without using keyboard and mouse

~$ sudo nano /etc/rc.local

su -l pi -c startx // deu certo

Add line before exit 0

Ctrl + C  – y  – enter

Let’s stop here.

  • The post goes on to the next update we will make a page for more dynamic record, without having to enter the rfid each new account. The way that this is not good.

I hope you enjoyed and that everything has worked out so far. Any problems leave a comment that soon I will answer!

Should they improve what was done let me know !!

Big hug to all 🙂