Skip to main content

NFC library for Raspberry Pi

This is a port of Seeed Studios's PN532 Arduino Library for using the PN532 chip with Raspberry Pi.

Features

  • Support all interfaces of PN532 (I2C, SPI, HSU)
  • Read/write Mifare Classic Card
  • Communicate with android 4.0+(Lists of devices supported)
  • Card emulation (NFC Type 4 tag)

To Do

  • Works with Don's NDEF Library
  • To support more than one INFO PDU of P2P communication
  • To read/write NFC Type 4 tag

Getting Started

  • PyPI

    1. Install with pip
      pip install pn532pi
      
    2. Follow examples
  • Direct Download

    1. Download zip file and extract the 4 folders(pn532pi, quick2wire, examples and test)
    2. Follow the examples of the two libraries.
  • Clone Git Repository

    1. Get pn532 library

        git clone --recursive https://github.com/gassajor000/pn532pi.git
      
    2. Follow the examples of the two libraries

Power

The Raspberry Pi 3.3v regulator does not provide enough current to drive the PN532 chip. If you try to run the PN532 off your Raspberry Pi 3.3v it will reset randomly and may not respond to commands. Instead you will need another power source (3.3v or 5v) to power the PN532. It is generally safe to tap into the 5v pin on the Raspberry Pi so long as your power supply can provide enough power for the PN532 and the pi.

I2C Interface

I2C is short for Inter-integrated Circuit. I2C interface needs only 4 wires to connect PN532 with Raspbeery Pi. I2C Connection

To use the I2C bus 1 to control PN532, refer to the code below.

from pn532pi import Pn532I2c, Pn532
	
i2c = Pn532I2c(1)
nfc = Pn532(i2c)

def setup():
    nfc.begin()
    # ...

Examples

To run an example you will need to change the interface flags to the interface you are using. For SPI you may also have to change the slave select pin to the pin you have connected.

# Set the desired interface to True
SPI = True
I2C = False
HSU = False

...
if SPI:
    PN532_SPI = Pn532Spi(Pn532Spi.SS0_GPIO8)
    nfc = Pn532(PN532_SPI)

Then you can just call python <example file>.py from a terminal.

Help debugging

We are willing to provide debug help for this library however there is currently only one maintainer doing this in his free time. Don't be surprised if responses take a couple days. Also, as hardware issues can be quite difficult to debug remotely, if your issue cannot be replicated using the test setup (pi 3B+) then there may not be much we can do.

For Remote IO Errors (I2C communciation errors) we also require that you take a logic capture of the i2c failure. This is needed to determine whether the pi or the nfc chip is the cause of the communication failure. Below is a recommendation for an affordable logic analyzer that can be run with the opensource Pulse View application or with the Selaea app.

HiLetgo USB Logic Analyzer

Contribution

It's based on Adafruit_NFCShield_I2C. Seeed Studio rewrite the library to make it easy to support different interfaces and platforms. @Don writes the NDEF library to make it more easy to use. @JiapengLi adds HSU interface. @awieser adds card emulation function. @gassajor000 ported to python/Raspberry Pi

[Mega]: http://arduino.cc/en/Main/ arduinoBoardMega [DUE]: http://arduino.cc/en/Main/arduinoBoardDue [Leonardo]: http://arduino.cc/en/Main/arduinoBoardLeonardo [SoftwareSerial]: https://www.arduino.cc/en/Reference/softwareSerial

Images courtesy of pinout.xyz, components101.com, sparkfun.com

Metadata

Release files for pn532pi 1.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pn532pi 1.7
File Size Uploaded Provenance
pn532pi-1.7.tar.gz 51.9 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for pn532pi 1.7
File Interpreter ABI Platform
pn532pi-1.7-py3-none-any.whl Python 3 none any Details

Total release size: 113.7 kB

Release files / pn532pi-1.7.tar.gz

Download URL pn532pi-1.7.tar.gz
Size 51.9 kB
Tags Source
SHA-256 checksum
How to use checksums
f9866fe58c530b5e58bb7c994d9e2ff91499fa3e23834d69159938253387c414
BLAKE2b-256 checksum
How to use checksums
d73ae4c7a5136ff9d86123f2726a438369c0961174dc7b4a232d522c244ce6b2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.19

Release files / pn532pi-1.7-py3-none-any.whl

Download URL pn532pi-1.7-py3-none-any.whl
Size 61.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8fd37f6ce5ce70469accd3537b3d8211c5d3bfd8e8cd93c0d0ff30c2b24bede5
BLAKE2b-256 checksum
How to use checksums
e9501143a197709eb9cd832c6838586422ac3a0d82e722056d361cd598e35d49
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.19

Security for pn532pi 1.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page