Raspberry Pi Interface with PN532 NFC Module
Demonstration
Physical connections
Notes
- The PN532 module has connections for UART, SPI,
I2C,
selectable by jumper. So far I have only tried the SPI
interface
(The jumpers are upper left on the picture.
The UART connection are on the same pins as
I2C; the labels are on the other side of the board.)
- SPI connections:
- SCK, MISO, MOSI, GND as expected
- SS to either CE0 or CE1; I think libnfc can handle
either, but the example uses CE0.
See libnfc
configuration information for setup
- VCC can be 3.3V, so no level shifting is needed for
the Raspberry Pi.
- No connections to IRQ or RSTO
Python code
import subprocess
import time
def nfc_raw():
lines=subprocess.check_output("/usr/bin/nfc-poll", stderr=open('/dev/null','w'))
return lines
def read_nfc():
lines=nfc_raw()
return lines
try:
while True:
myLines=read_nfc()
buffer=[]
for line in myLines.splitlines():
line_content=line.split()
if(not line_content[0] =='UID'):
pass
else:
buffer.append(line_content)
str=buffer[0]
id_str=str[2]+str[3]+str[4]+str[5]
print (id_str)
except KeyboardInterrupt:
pass
Notes
- It might make sense to put more of the decoding into
read_nfc(), which basically does nothing at present.
Wilfrid Laurier University
© 2019 Wilfrid Laurier University