element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Raspberry Pi
  • Products
  • More
Raspberry Pi
Blog NFC on RaspberryPi with PN532, py532lib and i2c
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Raspberry Pi to participate - click to join for free!
Featured Articles
Announcing Pi
Technical Specifications
Raspberry Pi FAQs
Win a Pi
GPIO Pinout
Raspberry Pi Wishlist
Comparison Chart
Quiz
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Former Member
  • Date Created: 14 Dec 2012 3:12 PM Date Created
  • Views 8376 views
  • Likes 2 likes
  • Comments 4 comments
Related
Recommended
  • python
  • i2c
  • rpiintermediate
  • raspberry_pi
  • nfc

NFC on RaspberryPi with PN532, py532lib and i2c

Former Member
Former Member
14 Dec 2012
imageWant to build this project?
View Parts

 

My entry to the "Double the Memory Challenge":  Can be seen in full here: http://hubcitylabs.org/nfc-on-raspberrypi-with-pn532-py532lib-and-i2c/ 

 

See how to enable I2C on your RaspberryPI here: http://www.danyo.ca/enabling-i2c-on-your-raspberrypi/

 

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.

py532lib

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.  
image

Wiring

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.

Software

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()
pn532.SAMconfigure()
 
card_data = pn532.read_mifare().get_data()
 
print(card_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

  • Adafruit NFC Breakout Board
  • PN532 at NXP
  • LibNFC

 

 

element14
Product Name*DescriptionBuy All PartsBuy All Parts
Raspberry Pi Model B with SD CardRaspberry Pi Model B with SD CardRaspberry Pi model B and 8GB SD Card with NOOBS preinstalled
Optical MouseOptical MouseBasic USB optical mouse
Raspberry Pi Power SupplyRaspberry Pi Power Supply120-240v to 5V power supply with micro USB connector
KeyboardKeyboardBasic USB keyboard
Adafruit Pi CobblerAdafruit Pi CobblerGPIO breakout kit for Raspberry Pi
BreadboardBreadboardBasic breadboard with 830 connection points
Jumper wire bundleJumper wire bundleJumper wires for use on breadboard
(2) 3.3k resistors(2) 3.3k resistors3.3K ohm, 250mW carbon film resistors
PN532 breakout board PN532 breakout board PN532 NFC/RFID controller breakout board

 

*Products and resources listed are listed to help members build their own Pi Projects. They are suggestions and listed for educational purposes. For substitutions of any parts, please post a question asking the original author.
  • Sign in to reply
  • dazed
    dazed over 7 years ago

    the images, at the tie of writing, are cached on oldweb.today

    oldweb.today

     

    oldweb.today

    it are the urls, so I dunno how it's gonna render

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • clem57
    clem57 over 8 years ago in reply to balearicdynamics

    Since author was last on...

    LAST LOGGED INSeptember 6, 2013

    I am doubtful the links can be fixed. Plus the information is dated as well.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • balearicdynamics
    balearicdynamics over 8 years ago

    Me too, it seems that something was broken.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • lbomb
    lbomb over 8 years ago

    I can't see the images on this page and the link at the top is sending me to a completely different url.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube