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-spi

v1.0.4

Published

PN532 SPI

Downloads

4

Readme

pn532-spi-js

This is a 1:1 ES2016 reimplementation of Adafruit's PN532 Python module, allowing interaction with the PN532 NFC board over software SPI.

It's tested only on a Raspberry Pi 3b using the wiring diagram here.

Installation

npm install pn532-spi

Usage

The simplest example is setting up an instance of the PN532 class, printing the board's firmware version, and polling for a UID.

Note: This needs to either run as root or with the appropriate capabilities set on the node binary.

// index.js

import PN532 from 'pn532-spi'

let bytesToHex = function(arr) {
  return arr.reduce(function(a, b) {
    let result = b.toString(16)
    if (result.length == 1) result = '0' + result
    return a + result
  }, '0x')
}

let pn532 = new PN532({
  clock:  22, // SCLK (GPIO 25)
  mosi:   16, // MOSI (GPIO 23)
  miso:   18, // MISO (GPIO 24)
  client: 12, // SSEL (GPIO 18)
  // Enable to get debug logging for frames
  // debug: true
})

// Will throw an error if PN532 is unresponsive or misconfigured
pn532.begin()

let version = pn532.getFirmwareVersion()
console.log('PN532 Firmware version: ', version[1] + '.' + version[2])

// Configure PN532 for Mifare cards
pn532.samConfiguration()

// Poll until we get a response and print the UID
for(;;) {
  console.log('Waiting for scan...')
  let uid = pn532.readPassiveTarget()
  if (uid == null) continue

  console.log('Found UID: ', bytesToHex(uid))
}

Sample output:

$ babel-node ./index.js
PN532 Firmware version: 1.6
Waiting for scan...
Waiting for scan...
Waiting for scan...
Waiting for scan...
Found UID: 0x7C7B7B7B7B7B7B

More thorough examples can be found in the Python library.

Known Issues

  • Hardware SPI currently not supported (though probably trivial to add)