Git Product home page Git Product logo

mfultralight-ndef's Introduction

Notes on Using PN532 on RPI and NDEF

The first section of this document describes how to use the PN532 RFID NFC module with Raspberry Pi. In the second section the basic steps required for preparing a Mifare Ultralight card for storing NDEF records are provided.

Setting up PN532 on RPI

This section briefly covers the setup of the PN532 RFID NFC module with Raspberry Pi. The module is connected to the Raspberry Pi via I2C and controlled via libnfc.

Connect PN532 module

⚠️ In case the used PN532 module offers multiple interfaces ensure that it is configured (check for jumpers/switches) for I2C.

Connect the I2C pins to the following physical pins on the Raspberry Pi.

  • GND -> 6
  • VCC -> 4
  • SDA -> 3
  • SCL -> 5

Note on Raspberry Pi pin numbering:

---------------------------
| 2 4 6 8                 | Header
| 1 3 5 7 ...             |
---------------------------
|                         | Remaining board
|                         |
|     Raspberry Pi        |
|                         |
|--------------------------

Setup Raspberry Pi

Enable I2C Interface

Use the Raspberry Pi configuration tool called raspi-config to enable the I2C interface.

sudo raspi-config nonint do_i2c 0

Optional, check if the PN532 module is available on the I2C bus. Use i2cdetect from the i2c-tools package to scan the I2C bus for devices.

sudo apt update
sudo apt install i2c-tools

i2cdetect -y 1 #scan bus 1 for devices

Example output (device found at addr 24)

     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:                         -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- 24 -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

In case the module ist not found use i2cdetect -l to list available I2C buses and scan them for devices by changing the bus number passed to i2cdetect(see man page).

Install and configure libnfc

Install latest version of libnfc from repo.

sudo apt update
sudo apt install libnfc6 libnfc-bin libnfc-examples

Add config for the PN532 module to libnfc (assumes that module is connected to bus 1, if not change /dev/i2c-1 accordingly).

sudo mkdir -p /etc/nfc/devices.d
printf 'name = "pn532"\nconnstring = "pn532_i2c:/dev/i2c-1"\n' | sudo tee /etc/nfc/devices.d/pn532.conf

Poll NFC tag to check if libnfc is fuctional.

nfc-poll

Store NDEF data on Mifare Ultralight cards

This section briefly outlines the steps required to prepare a blank Mifare Ultralight card as a NFC Forum Type 2 Tag for storing NDEF records and shows how to store a URL in a NDEF record.

Prepare Mifare Ultralight for NDEF

Blank Mifare Ultralight cards ship with an empty one time programmable (OTP) area located in block/page 3. The NFC Forum Type 2 Tag Operation Specification puts the Capability Container (CC) used for managing information on the tag at this block. To initialize the card the CC must be written.

Mifare Ultralight layout

SonMicro Elektronik MIFARE ULTRALIGHT User Manual Mifare Ultralight Memory Layout

NFC Forum Type 2 Tag layout

NFC Forum Type 2 Tag Operation Specification Type2 Tag Memory Layout

⚠️ You only have one shot - As the name suggest the OTP can only be written once. Therefore, extrem care should be taken when writting the CC. Otherwise you may end up with a broken card.

One easy way to manually add the CC is to modify the dump of a blank Mifare Ultralight card. For this the card is first dumped with nfc-mfultralight.

nfc-mfultralight r blank.mfd

Subsequently, the dump editable is converted into a hexdump with xxd in order to make it editable with a standard texteditor.

xxd -c 4 blank.mfd > blank.hex

A dump of an empty card is shown below, the OTP area is located in row XXX.


mfultralight-ndef's People

Contributors

aheinzel avatar

Watchers

 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.