PN532 serial not found connected to Raspberry Pi

Asked by Adam

Hi the tagtool.py does not find my nfc reader. I used this tutorial http://learn.adafruit.com/adafruit-nfc-rfid-on-raspberry-pi/overview to connect my card to a raspberry pi.

The libnfc examples work and my reader is found. This is what I get from the nfc-list command.

nfc-list uses libnfc 1.6.0-rc1 (r1326)
NFC device: pn532_uart:/dev/ttyAMA0 - PN532 v1.6 (0x07) opened

I therefore know that my reader is connected correctly.

Using nfcpy and the 'python tagtool.py' command I get the following.

searching for a usable reader
searching for a usb bus reader
searching for a tty reader
searching for a usb tty reader
no reader found
no contactless reader

I am using rev 142. I have the serial and usb modules installed.

I've only just started learning python and I'm not a developer so I probably won't understand any complex answers.

Thanks and I hope you can help me.

Question information

Language:
English Edit question
Status:
Solved
For:
nfcpy Edit question
Assignee:
No assignee Edit question
Solved by:
Adam
Solved:
Last query:
Last reply:
Revision history for this message
Stephen Tiedemann (stephen-tiedemann) said :
#1

In step 2 of http://learn.adafruit.com/adafruit-nfc-rfid-on-raspberry-pi/building-libnfc you have modified the source code to get /dev/ttyAMA recognized. A similar step is required for nfcpy, you'll find the place in nfc/dev/__init__.py line 146. Replace ttyUSB with ttyAMA and if it then works please let me know.

Revision history for this message
Adam (adrockb) said :
#2

Hi Stephen,

I've amended the code like you said but I still get the same message. Is there somewhere else that I need to change this?

I changed nfc/dev/__init__.py on line 146. Replace ttyUSB with ttyAMA .

This is how it looks

else:
                    log.info("searching for a usb tty reader")
                    for devname in glob.glob("/dev/ttyAMA[0-9]"):
                        log.debug("trying usb tty reader {0}".format(devname))
                        for module in ("arygon_tty", "pn53x_tty"):
                            driver = import_driver(module)

Thanks

Adam

Revision history for this message
Adam (adrockb) said :
#3

Hi Stephen

Just thought I would try one more thing and it is now working. There was another place just above where you said with ttyUSB(0) so I changed that to ttyAMA(0). Here is where I mean.

 match = re.match(r"tty(?:\:(usb|com))?(?:\:([0-9]{1,2}))?$", path)
        if match is not None or path == "":
            line, port = match.groups() if match else (None, None)
            if line is None or line == "usb":
                if port is not None:
                    devname = "/dev/ttyAMA{0}".format(port) #THIS LINE IS THE ONE I CHANGED
                    log.debug("trying usb tty reader {0}".format(devname))
                    for module in ("arygon_tty", "pn53x_tty"):
                        driver = import_driver(module)
                        device = driver.init(devname)
                        if device is not None:
                            device._path = "tty:usb:{0}".format(port)
                            return device
                else:
                    log.info("searching for a usb tty reader")
                    for devname in glob.glob("/dev/ttyAMA[0-9]"):
                        log.debug("trying usb tty reader {0}".format(devname))
                        for module in ("arygon_tty", "pn53x_tty"):
                            driver = import_driver(module)
                            device = driver.init(devname)
                            if device is not None:
                                port = devname[-1]
                                device._path = "tty:usb:{0}".format(port)
                                return device

Thanks for your help. Now to see what I can do.

Adam

Revision history for this message
Tomas Hora (tomhora) said :
#4

Hi, I made the same changes in the __init__.py but it finds the reader (PN532 breakout board connected over UART) only after I comunicate with the reader using libnfc (eg. nfc-poll) after reboot. Once it communicates with the device it works like a charm (even after soft-reset) but after pluggin the rpi off the plug it does not find the reader. Any hints how to fix this behavior?

Using latest pyusb-1.0.0a2.

Revision history for this message
Stephen Tiedemann (stephen-tiedemann) said :
#5

If you're still having the problem please try again with the latest trunk revision. The driver architecture got some changes as well as the serial port implementation. You no longer have to change source code to get a ttyAMA recognized, just tell tagtool or any of the other example programs to use '--device tty:AMA0:pn53x'. The last part tells the driver to use on that port, this seems to be a safer aproach for serial connections as they do not really tell about the device connected, like USB does.