PN532 v3 with Raspberry Pi 3

Asked by Lukas Vana (fabian) on 2016-09-16


I'm trying to connect PN532 version 3 to my Raspberry Pi 3. I connected it to UART pins:

In /dev there is ttyAMA0 device, but it don't work, so I tried /dev/ttyS0, whish works with nfc-list tool. In my /etc/nfc/libnfc.conf is:
device.connstring = "pn532_uart:/dev/ttyS0"
and I can get:
root@raspberrypi:~# nfc-list
nfc-list uses libnfc 1.7.1
NFC device: pn532_uart:/dev/ttyS0 opened

When I'm trying on first try I always get:

root@raspberrypi:~/nfcpy/trunk/examples# python --device tty:S0:pn532
[nfc.clf] searching for reader on path tty:S0:pn532
[nfc.clf.pn532] input/output error while waiting for ack
[main] no contactless reader available

Second try:

root@raspberrypi:~/nfcpy/trunk/examples# python --device tty:S0:pn532
[nfc.clf] searching for reader on path tty:S0:pn532
Traceback (most recent call last):
  File "", line 581, in <module>
  File "/root/nfcpy/trunk/examples/", line 461, in run
    while self.run_once() and self.options.loop:
  File "/root/nfcpy/trunk/examples/", line 388, in run_once
    clf = nfc.ContactlessFrontend(path)
  File "/root/nfcpy/trunk/nfc/clf/", line 71, in __init__
    if path and not
  File "/root/nfcpy/trunk/nfc/clf/", line 145, in open
    self.device = device.connect(path)
  File "/root/nfcpy/trunk/nfc/clf/", line 104, in connect
    device = driver.init(tty)
  File "/root/nfcpy/trunk/nfc/clf/", line 395, in init
    if not == set_baudrate_rsp:
  File "/root/nfcpy/trunk/nfc/clf/", line 138, in read
    LEN = frame[3]
IndexError: bytearray index out of range

Third and next tries:

root@raspberrypi:~/nfcpy/trunk/examples# python --device tty:S0:pn532
[nfc.clf] searching for reader on path tty:S0:pn532
[main] no contactless reader available

Now when I try nfc-list again it throws error, too:

root@raspberrypi:~/nfcpy/trunk/examples# nfc-list
nfc-list uses libnfc 1.7.1
error libnfc.driver.pn532_uart pn53x_check_communication error
nfc-list: ERROR: Unable to open NFC device: pn532_uart:/dev/ttyS0

When I reconnect PN532 I can reproduce it again exactly the same.

I have latest version of nfcpy 0.11.1:
root@raspberrypi:~# pip list|grep nfc
nfcpy (0.11.1)

I have found interesting info about RPI3 tty changes: "The raspberry pi 3 has changed things around a bit: ttyAMA0 now refers to the serial port that is connected to the bluetooth. The old serial port is now called ttyS0. So if you have an RPI3, everywhere you see "ttyAMA0" below, you should read "ttyS0"."

Have you some idea about my errors? Thanks!

Question information

English Edit question
nfcpy Edit question
No assignee Edit question
Solved by:
Lukas Vana (fabian)
Last query:
Last reply:

This is unfortunately true, there is a problem with the UART on GPIO 14/15 of an RPi 3. I've learned that the change from ttyAMA0 to ttyS0 is not just the device node but it's quite different hardware behind. The ttyAMA0 is a full hardware UART that can can go much faster than 115.2 kbps and therefore nfcpy increases the baudrate to 921.6 kbps. But ttyS0 is much less capable 'mini uart' that seems unable to reliably work at higher baudrates (there's a lot of related info out there, one good overview is and one of the discussions I found is

The lates version on master branch will not increase the serial speed if running with ttyS0 on RPi. That works well but of course also a bit slower. To get faster speed either use an FTDI friend and connect through USB or you could also map the hardware uart on ttyAMA0 back to the GPIO pins and assign the 'min uart' to Bluetooth (see the first link above for how that works).

BTW. where have you got that PN532 board. It's a nice form factor, looks better than Adafruit's breakout board.

Thanks for the reply and info!

I also tried to connect PN532 through "CP2102 USB to UART Bridge Controller". Again nfc-list with pn532_uart:/dev/ttyUSB0:115200 was able to read cards, bud nfcpy not.

I'll try to map ttyAMA0 back according to the instructions.

PN532 is from Czech eshop:, but it's available also on DX:

Sorry, there is another RPi issue around USB Serial adapters. That was fixed on the master branch just a couple of days ago, so you'd need to grab the source from there (or wait for the next releaseif you want to stick to PyPI) A summary of the issue is at

Thanks for the info about the PN532 board.

I swapped ttyS0 and ttyAMA0 and nfcpy works ok:

root@raspberrypi:~/nfcpy/trunk/examples# python --device tty:AMA0
[nfc.clf] searching for reader on path tty:AMA0
[nfc.clf] using PN532v1.6 at /dev/ttyAMA0
** waiting for a tag **
Type2Tag ID=07502889

Thank you your help!