Coder Social home page Coder Social logo

dparcerisa / nxppy Goto Github PK

View Code? Open in Web Editor NEW

This project forked from svvitale/nxppy

0.0 2.0 0.0 4.2 MB

Python wrapper for interfacing with the NXP EXPLORE-NFC shield for Raspberry Pi

License: MIT License

C 70.31% Shell 8.87% Python 20.81%

nxppy's Introduction

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 Reader Library and provides a thin layer for detecting a Mifare RFID tag, reading its UID (unique identifier), and reading/writing data from/to the user area.

This was based very heavily on NXP's card_polling 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. All files in this repository are distributed under the MIT license.

Compatibility

Tested with both Python 2.7 (as installed on Raspberry Pi) and with a manually compiled version of Python 3.4.

Requirements

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

Installation

nxppy is available from pypi. First, install pip if you don't have it already:

wget https://bootstrap.pypa.io/get-pip.py
sudo python get-pip.py

Then simply run:

sudo pip install nxppy

Installation will take some time as it automatically pulls down and builds NeardAL, WiringPi, and the NXP Reader Library from souce.

Source

To install from source, use distutils:

sudo apt-get install python-setuptools
sudo python setup.py build install

Usage

Currently, the module supports only Mifare cards:

import nxppy

mifare = nxppy.Mifare()

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

# Read 16 bytes starting from block 10 
# (each block is 4 bytes, so technically this reads blocks 10-13)
block10bytes = mifare.read_block(10)

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

Polling example, equivalent to NXP's card_polling example:

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!

nxppy's People

Contributors

svvitale avatar tomaszkoperski avatar

Watchers

David Parcerisa avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.