RFID RC522 on Raspberry PI with NodeJS


It's kind of hard to succeed in this. Most of tutorials are uncomplete. Here is my compilation.

Everything is done on the PI

0) Install node
wget http://node-arm.herokuapp.com/node_latest_armhf.deb
sudo dpkg -i node_latest_armhf.deb

1) Update your PI: 
sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade
sudo rpi-update
sudo apt-get clean

2) Configure the SPI group:
sudo groupadd -f --system spi
sudo adduser pi spi # assuming the pi account is the one that will access SPI
sudo nano /etc/udev/rules.d/90-spi.rules

Then add this to the file :
SUBSYSTEM=="spidev", GROUP="spi"

3) Configure the PI:
sudo apt-get install build-essential
sudo npm install -g node-gyp
sudo raspi-config
  under Advanced Options - enable Device Tree
  under Advanced Options - disable SPI
sudo reboot

4) Compile the spi_bcm2835 driver:
wget http://www.airspayce.com/mikem/bcm2835/bcm2835-1.46.tar.gz
tar -zxf bcm2835-1.46.tar.gz
cd bcm2835-1.46
./configure
make
sudo make check
sudo make install
sudo modprobe spi_bcm2835

Note : There's maybe new versions here : http://www.airspayce.com/mikem/bcm2835/ 

5) Make a node project
mkdir RC522
cd RC522
npm install rc522-rfid-promise --save
nano rc522.js

Put this into:
var rc522 = require("rc522-rfid-promise");

console.log("Ready to scan");

rc522.startListening()
  .then(function(tagId){ console.log(tagId); })
  .catch(function(err) { console.log(err); });



Note : You could use the rc522-rfid lib if you can compile it without error. 

6) Do some wiring


7) Run the project 

sudo node rc522.js

Note : theoricaly the sudo is useless as we add the "pi" user to the spi group. But I was searching why it don't work...

Scan a tag.

Commentaires

  1. hello , i have one error ,


    gyp_main.py: error: no such option: --no-parallel
    gyp ERR! configure error
    gyp ERR! stack Error: `gyp` failed with exit code: 2
    gyp ERR! stack at ChildProcess.onCpExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:355:16)
    gyp ERR! stack at emitTwo (events.js:87:13)
    gyp ERR! stack at ChildProcess.emit (events.js:172:7)
    gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:200:12)
    gyp ERR! System Linux 4.4.9-v7+
    gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
    gyp ERR! cwd /home/pi/node_modules/rc522-rfid-promise
    gyp ERR! node -v v4.2.1
    gyp ERR! node-gyp -v v3.0.3
    gyp ERR! not ok

    RépondreSupprimer
  2. I get the following when i execute

    Ready to scan
    undefined

    RépondreSupprimer

Enregistrer un commentaire

Posts les plus consultés de ce blog

Vidange - Laguna III Coupé 2.0 DCI 150