CM Panel technical documentation Buy

Node-RED and PN532 NFC RFID module on CM-Panel basic

This article illustrates how to connect a PN532 RFID reader to a CM-Panel basic and how to manage it using Node-RED

We will use the SPI bus to talk with the PN532 board. Wire this lines:

PN532 EXP-1
VCC 3V3
GND GND
SCK 39 SPI0_SCLK
MSO 37 SPI0_MISO
MOSI 38 SPI0_MOSI
SS 36 SPI0_CE0

and insert these lines in /boot/config.txt to enable the SPI interface and move it on the pin 35-39 used by teh CM3-Panel:

dtparam=spi=on
dtoverlay=spi-gpio35-39

Set the dipswitch on the PN532 board to enable the SPI bus instead of I2C

Install Node-RED:

Install this node inside Node-RED :

And this software from the command line:

sudo apt update
sudo apt install python-pip 
sudo pip install RPi.GPIO
sudo pip install spidev

Links

Read a NFC card in Python

Install the NFC tools:

sudo apt update
sudo apt install libnfc5 libnfc-bin libnfc-examples

Configure the NFC tool editing this file:

sudo nano /etc/nfc/libnfc.conf

and adding on it these two lines:

device.name = "_PN532_SPI"
device.connstring = "pn532_spi:/dev/spidev0.0:280000"

List connected NFC readers:

nfc-scan-device -v

nfc-scan-device uses libnfc 1.7.1
1 NFC device(s) found:
- pn532_i2c:/dev/i2c-1:
    pn532_i2c:/dev/i2c-1
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)

Read a card or tag by first starting nfc-poll then physically holding a NFC/RFID tag or card in front of the reader:

nfc-poll 

nfc-poll uses libnfc 1.7.1
NFC reader: pn532_i2c:/dev/i2c-1 opened
NFC device will poll during 30000 ms (20 pollings of 300 ms for 5 modulations)
ISO/IEC 14443A (106 kbps) target:
    ATQA (SENS_RES): 00  04  
       UID (NFCID1): 77  d3  d1  ad  
      SAK (SEL_RES): 08  
nfc_initiator_target_is_present: Target Released
Waiting for card removing...done.

Install git on your CM3-Panel:

sudo apt install git

Then clode this Python library:

git clone https://github.com/HubCityLabs/py532lib.git

move inside the directory:

cd py532lib

and edit this Python3 program in a file called readcard.py:

from py532lib.i2c import *
from time import sleep

pn532=Pn532_i2c()
pn532.SAMconfigure()

while True:
        data=pn532.read_mifare().get_data()
        if  len(data)==11:
                uid="%02X%02X%02X%02X" % (data[7],data[8],data[9],data[10])
                print(uid)
                sleep(1)
        else:
                sleep(1)

run it by typing:

python3 readcard.py

Links

Products related

CM-Panel-Basic

Features Index Buy

All-in-one 7 inch touch WiFi terminal powered by Raspberry Pi CM4S
  • 7 inch TFT display 800x480
  • Capacitive touch
  • MIPI Camera connector
  • WiFi @ 2.4 GHz
CM-Panel-POE

Features Index Buy

All-in-one 7 inch touch POE terminal powered by Raspberry Pi CM4S
  • 7 inch TFT display 800x480 pixel
  • Capacitive touch
  • Embedded micro UPS for safe shutdown
  • Power Over Ethernet @ 10/100 Mbit
  • Hi-resolution audio up to 384KHz@32bit
  • Real Time Clock with backup battery
  • 3 USB Host port
  • 1 RS485/422/RS232 port
  • 1 Relay
  • MIPI Camera connector
  • WiFi @ 2.4 GHz (optional)
CM-Home

Features Index Buy

Home Automation board powered by Raspberry Pi CM4S lite module
  • Power-in @ 12 to 24VDC
  • Double opto-isolated RS-485 ports
  • 2 relays
  • 2 USB 2.0 host port
  • Ethernet port at 10/100Mbit
  • MIPI Camera connector
  • Stereo audio out on 3.5 mm jack

Home page CM Panel technical documentation Buy