Skip to main content

A python extension for interfacing with the NXP PN512 NFC Reader. Targeted specifically for Raspberry Pi and the EXPLORE-NFC module

Project description

nxppy

nxppy is a very simple Python wrapper for interfacing with the excellent NXP EXPLORE-NFC shield for the Raspberry Pi. It takes NXP’s NFC Reader Library and provides a thin layer for detecting a Mifare NFC tag, reading its UID (unique identifier), and reading/writing data from/to the user area.

License

All files in this repository are distributed under the MIT license.

External components

This work was based very heavily on NXP’s MifareClassic example code. The example code was only reorganized to be more conducive as an interface. NXP still retains full copyright and ownership of the example code and the NFC Reader Library. The license conditions that need to be accepted in order to use this project in conjunction with the NFC Reader Library can be found in the document NXP_NFC_Reader_Library_licencefile.pdf

Compatibility

Tested with both Python 2.7 and 3.4 as installed on Raspian Jessie.

Requirements

The EXPLORE-NFC card relies on SPI being enabled. Please enable SPI using raspi-config prior to installing nxppy.

Installation

nxppy is available from PyPI. To install, simply run:

sudo pip install nxppy

Installation will take some time as it automatically pulls down the NXP NFC Reader Library from souce.

Usage

Currently, the module supports ISO14443-3A/4A cards only:

import nxppy

mifare = nxppy.Mifare()

# Select the first available tag and return the UID
uid = mifare.select()

# Read a single block of 4 bytes from block 10
block10bytes = mifare.read_block(10)

# Write a single block of 4 bytes
mifare.write_block(10, 'abcd')

Example polling for tags:

import nxppy
import time

mifare = nxppy.Mifare()

# Print card UIDs as they are detected
while True:
    try:
        uid = mifare.select()
        print(uid)
    except nxppy.SelectError:
        # SelectError is raised if no card is in the field.
        pass

    time.sleep(1)

Feedback

I welcome your feedback and pull requests! This project started as a necessity for my own Raspberry Pi development, but I’m hoping others will find it useful as a way to quickly bootstrap NFC-based projects. Enjoy!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nxppy-1.4.0.tar.gz (8.3 kB view details)

Uploaded Source

File details

Details for the file nxppy-1.4.0.tar.gz.

File metadata

  • Download URL: nxppy-1.4.0.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for nxppy-1.4.0.tar.gz
Algorithm Hash digest
SHA256 bd7fd3547191f9cdb46e9171adb6d55952abb88d9d3ac8857862f8232139bdc0
MD5 e4cbf974df7e12515569ed8ff5c69e54
BLAKE2b-256 541f3935069e74563a973f7375f8f9876493c8b801ec2f959e20ea7e8f1498ed

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page