How to read a tag from PN532 in Python?

3.4k Views Asked by At

I want to experiment with the PN532 that comes connected with an arduino UNO. I have never touched anything similar, and in fact it took me quite a few tries to be able to play with LEDs on another arduino board I have.

Can someone provide me with a concrete example of reading data from the pn532 when I use a tag or card on it in Python?

2

There are 2 best solutions below

0
On BEST ANSWER

I did found a way that might be partially correct. Since Eugenes' answer does not provide a definitive way that we know will work, it cannot be considered a full answer so I will most probably accept this one if nothing else changes.

First of all since the PN532 does not continuously monitor for signals and emits data, we will have to program it the usual way in order for it to behave according to what we want to achieve.

This can be done using the same software that you program any other Arduino device.

Make sure you have chosen the correct port from the tools menu. If you don't know which port is that, in windows go to Start>All Programs>Accessories>System Tools>System Information>Components>Ports>Serial. For Linux going to /dev/serial/by-id should do.

Then I would recommend using the examples provided by the manufacturer here. Make sure you choose the right connection type or else you will see no data coming from the device (Most probably you will want I2C).

Once that is done, and your device emits data each time a tag is used on it (check with a serial terminal configured at 115200 Baud rate) then you are ready to start working with python.

Again I recommend this module to read your data from the serial port. It even comes with a ready to use example of a wxWidgets terminal to read your data from the PN532. If of curse you use another python library and you think its better do say so in the comments.

1
On

Take a look at https://github.com/HubCityLabs/py532lib. The standard library is in C, somebody wrote a Python wrapper for the C library that you can use.