npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pn532

v1.0.0

Published

Library to run the PN532 RFID Reader

Downloads

144

Readme

PN532

Driver for the PN532 NFC chip. Provides an event and promise-based API, and requires either:

This implementation does not require libnfc, and should work on both X86 (32-bit or 64-bit) and ARM (RPi / Beaglebone) systems

Tested on a Mac OSX 10.9 system using a UART/FTDI cable to an Adafruit breakout board and on a BeagleBone using UART. I2C support is currently a WIP at the moment.

API is subject to change until the 1.0.0 release

Install

npm install pn532

and npm install serialport or npm install i2c

Example

UART (using node-serialport)

var pn532 = require('pn532');
var SerialPort = require('serialport').SerialPort;

var serialPort = new SerialPort('/dev/tty.usbserial-AFWR836M', { baudrate: 115200 });
var rfid = new pn532.PN532(serialPort);

I2C (using node-i2c)

var pn532 = require('pn532');
var i2c = require('i2c');

var wire = new i2c(pn532.I2C_ADDRESS, {device: '/dev/i2c-1'});
var rfid = new pn532.PN532(wire);

Scan a tag

rfid.on('ready', function() {
    rfid.scanTag().then(function(tag) {
        console.log('tag:', tag.uid);
    });
});

Poll for a tag

rfid.on('ready', function() {
    console.log('Listening for a tag scan...');
    rfid.on('tag', function(tag) {
        console.log('tag:', tag.uid);
    });
});

Retrieve the firmware version

rfid.on('ready', function() {
    rfid.getFirmwareVersion().then(function(data) {
        console.log('firmware: ', data);
    });
});

Read and write tag data (using ndef library)

Tested using NTAG203 tags. Should support other NTAG and Mifare Ultralight tags. Mifare Classic tags are currently NOT supported, but could be in the future.

Read

rfid.on('ready', function() {
    rfid.on('tag', function(tag) {
        rfid.readNdefData().then(function(data) {
            var records = ndef.decodeMessage(Array.from(data));
            console.log(records);
        });
    });
});

Write

rfid.on('ready', function() {
    rfid.scanTag().then(function(tag) {
        var messages = [
            ndef.uriRecord('http://www.google.com'),
            ndef.textRecord('test')
        ];
        var data = ndef.encodeMessage(messages);

        rfid.writeNdefData(data).then(function(response) {
            console.log('Write successful');
        });
    });
});

Examples

Examples are available under the examples directory

Debug logging

PN532_LOGGING=debug node examples/card_scan.js

Note for using UART on a Raspberry Pi 3

If you are using this library on a Raspberry Pi 3, you will likely encounter an issue with the device sending or receiving data over UART due to some hardware and configuration changes with regards to the serial port.

TLDR workaround:

  1. Add core_freq=250 in the /boot/cmdline.txt
  2. Use /dev/ttyS0 instead of /dev/ttyAMA0

For details on why these changes are needed, see here and here

Links