"view site" you buy generic lexaproslimming tabletsmost reliable source viagralithium carbonate no prescriptionbuy amoxicilin for humains viagra nl
north american pharmacy"drugstore"viagra on craigslistherebuy lasixshop"view site"link"about"pharmastore"drugstore"pfizer viagra onlinerevatio costgo

NFC on RaspberryPi with PN532, py532lib and i2c

Over the past few weeks, we at HubCityLabs have been busy! We’ve started work on a project will let us control access to our facilities with NFC cards, and later on, bio-metrics. Since for each access point, there will be multiple readers (NFC, fingerprint, retina scanners…) for each host (a RaspberryPi), we settled on using I2C as a standard for communication between the host and the peripherals. Our chosen language was Python, since it seems to be the de-facto language on the RaspberryPi.


Out of the requirements above was born the need for a PN532/i2c package in Python3, so I created a project called py532lib. I chose to use Quick2Wire‘s Python API for Linux as it provides clean access to I2C, SPI, and for GPIO (on RaspberryPI). Currently, only I2C is supported in py532lib, however, in the long run we should be able to add SPI and UART communication capabilities to the PN532 under a single, seamless API.

Please be gentle, as this is my first ever attempt at coding anything in Python! I’ve done my best to make it easy to use, and respect as many PEP8 rules as possible. Forks and pull-requests will be welcomed with open arms.


First you’ll need to follow the instructions from my earlier post, about enabling I2C for your RaspberryPi.

Second, you’ll need to make sure that the jumpers on the Adafruit NFC Breakout Board are set for I2C communications.

PN532 Wiring I2C RPi

The wiring schematic above is easy as pie. From the RaspberryPi, simply connect 3.3V and GND to the Breakout Board on JP4, then connect the SDA and SCL signals. As noted in NXP’s PN532 Application Note, 3.3k pull-up resistors should be used. If everything is connected properly, you should be able to see the PN532 on the I2C bus at the RaspberryPI’s shell.

sudo i2cdetect -y 1

     0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- 24 -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

Note: If you have an older RaspberryPI, you will need to do “sudo i2cdetect -y 0″ instead.


Now that py532lib are installed and available to your Python’s PATH, you should be able to write the following:

from py532lib.i2c import *
from py532lib.frame import *
from py532lib.constants import *

pn532 = Pn532_i2c()

card_data = pn532.read_mifare().get_data()


Now that py532lib is in polling mode, put an NFC card in the Breakout Board’s field, and it will return the card’s data.

Hopefully someone will find this useful! Cheers!

Related Links


DanyO is a hacker at the HubCityLabs Hackerspace. He has been a maker with a penchant for software and electronics for two decades.

More Posts - Website

Follow Me:

  • Pingback: NFC on RaspberryPi with PN532, py532lib and i2c #piday #raspberrypi @Raspberry_Pi « adafruit industries blog

  • Pingback: ต่อ NFC กับ Raspberry Pi | Raspberry Pi Thailand

  • nghia


    Great to see R-Pi with NFC.

    Are the IRQ (on JP4) and P35 (JP3) signals left unconnected/floating?

    I thought these signals (especially IRQ) needs to be fixed to ensure the PN532 starts in normal mode.

    Thanks for your feedback.

    • DanyO83


      My understanding is that these pins can be left un-connected.

      The schematic above works like a charm, you just have to keep polling the PN532 through I2C.

  • Bob

    That is very useful, thanks :-)
    Will also work perfectly with the Elechouse board (PN532 too) in I2C:

    Do *not* use python 2.x, as it will hang while sending the SAMCONFIGURATION message (source of the issue inside quick2wire’s I2C lib).

    • Jeff Cotten

      the Samconfiguration message is still hanging for me as well and I’m using Python 3.2.3

  • Christian

    hi im trying to install this, but i cant find a installation script for the packages for python so when i try to run the code at the bottom of your article i get an error saying:
    ImportError: No module named py532lib.i2c

  • kudlata

    I have an error: “OverflowError: Python int too large to convert to C long” in File “quick2wire/”, line 72, in transaction ioctl(self.fd, I2C_RDWR, addressof(ioctl_arg))

    • Jeff Cotten
      • Jeff Cotten

        It looks like if you git clone the hikaru-gatekeeper you’ll get the old quick2wire and old py532 libraries. You’ll have to download the new py532 libraries independantly of hikaru-gatekeeper if you want it to work on Rev2 boards. The latest py532 library has the fix for i2c_channel not being hard-coded to “0″

  • Jeff Cotten

    Has anyone had any luck getting a Verizon Samsung Galaxy S3 to be read by the PN532 chip? I’ve been able to get the chip to pick up the Nexus 4′s NFC chip.

  • Samuel

    Sorry if this sounds stupid.

    I’ve been using the PN532 board over UART (following Adafruits own tutorials) and it’s not going very well, So I have a few questions.

    Adafruit said that the card works fine for 3.3v connections, what are the pull-up resistors for (Could I also use the 4050 level shifter chip that comes with the board)?

    Does this allow the PN532′s built in emulation mode, I’m hoping to use the PN532 to “clone/emulate” a card I already own.

    Thankyou in advance, I’m fairly good with linux in general but not so much electronics.

  • Manolis

    For me it doesn’t work. I get the same result with you when running “sudo i2cdetect -y 0″ but when I run (with sudo because otherwise says Permission denied: ‘/dev/i2c-1′) nothing happens.

  • Alex

    Sorry, but I have not understood one point. How can I install the py532lib?

  • coda

    Hi! Great tutorial! I got every thing working up until when I connect the module and run “sudo i2cdetect -y 1″ or “sudo i2cdetect -y 0″ and it doesn’t detect that I connected the NFC module. I have done several reboots but without luck. I followed the wiring diagram like a slave. So you know what could be wrong?

    • Adli

      coda.may i have your email..i wanna get connected and ask about this project if you dont mind.

    • Lozza

      Hi Coda, did you resolve this? I too cannot detect the PN532 Breakout Board. I’m sure my wiring is set up correctly.

  • gus

    the ID value on I2c bus for my PN532 adafruit breakout board change All the time ! (beetween 24 and 25). i don’t understand why, i have the exact same wiring diagram like your.

    • chimp

      I have the same problem.

    • yanoosh

      Maybe someone will find this useful. I had similar problem when using chip PCA9554 on I2C. Reason for address change were not connected address lines on chip. Problem was fixed when I connected address lines to ground, or VCC via pull up resistor to clearly determine chip address.

  • rogerhyam

    Hi DanyO,

    Thanks for this. I found it very useful in getting my board running and detecting tags. (It is the same as the Elechouse board but came off ebay).

    Your code in the library looks really nice.

    I am now wrestling with the Mifare specifications and trying to work out how to query cards to do something useful. I really need another layer of abstraction – NFC Data Exchange Format perhaps? This is all too low level for me!

    Some demo code of reading and writing to a tag would be really welcome. Do you have any suggestions?

    Many thanks,


  • HPW


    I inserted some sleep commands because in debug mode I got output like bytearray(b’Kx01x01x00x04x08x04x02xb2rxbe’).
    What could cause this issue

    from py532lib.i2c import *
    from py532lib.frame import *
    from py532lib.constants import *
    import pdb
    import time
    pn532 = Pn532_i2c()
    # pdb.set_trace()
    for i in range(40):
    card_data = pn532.read_mifare().get_data()
    # print(card_data)
    me = “:”.join(“{:02x}”.format(int(c)) for c in card_data)

  • teach12

    Ah I’m lost…. How do I install the software part…. Is there any step by step instructions… like downloading/installing/etc… I’m aiming to create a nice little device for my class where it reads nfc card data out loud through the speaker… I was going to do an arduino, but the pi would event be better becasue of TTS. Any help?

  • nancy

    hii…i followed the above steps but not able to read the tag data. I have installed py532lib and added in the python path, after that when i run the code of you article, earlier it was coming import error: no module name py532lib.i2c…i didn’t change anything just install python-smbus and now the error is import error: no module name i2c.

    How to solve this issue?

  • Ariel84

    I can’t see the manual

local viagra storesauthor and punishershop need to buy viagralexapro from mexicogoviagra agesex powar tablet"about"accutane buybuy cialis overnight shippingcoregafree sample viagra or cialischeap deltasonecheap online pills order viagraherepaxil on linebuy zocor without prescriptionstore