Required Hardware

Before getting started, let's review what you'll need.

  • Raspberry Pi 3 (Recommended) or Pi 3 Model B+ (Supported).
  • MATRIX Creator - Buy the MATRIX Creator.
  • Micro-USB power adapter for Raspberry Pi
  • Micro-SD Card (Minimum 8 GB)
  • Micro-USB Cable
  • A PersonalComputer to SSH into your Raspberry Pi
  • Internet connection (Ethernet or WiFi)
  • NFC tag

Let's Get Started

If you are starting with a fresh install of Raspbian on your Raspberry Pi, first install the MATRIX initialization packages, and MATRIX HAL. Then, we install the NFC library from NXP and the MATRIX abstraction layer.

  

1. Initial Raspberry Pi Setup

Run the following commands inside your Raspberry Pi terminal to install the required packages.

Add the MATRIX repository and key.

curl https://apt.matrix.one/doc/apt-key.gpg | sudo apt-key add -echo "deb https://apt.matrix.one/raspbian $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/matrixlabs.list 

Update your repository and packages.

sudo apt update sudo apt upgrade 

Install the MATRIX init and HAL packages.

sudo apt install matrixio-creator-init libmatrixio-creator-hal libmatrixio-creator-hal-dev 

Reboot your Raspberry Pi.

sudo reboot 

2. Downloading the NXP Library

Due to NXP's terms & conditions, we cannot directly distribute the library to our users.

You can download the NFC Reader Library for PN512 by creating an account on the NXP website and downloading the zip file here.

 

Click the download button.

 

Click the 4.04.05 NFC Reader Library for PN512.

 

Then click SW297940.zip to download NFC Reader Library v4.040.05 R2 for PNEV512B including all software examples.

 

3. Compiling and Installing MATRIX HAL NFC

Before starting, ensure you have access to the terminal of your Raspberry Pi via an SSH-session or connect a screen, mouse, and keyboard. Once you've opened the terminal, insert and run the following commands.

Install the tools needed to build MATRIX HAL NFC

sudo apt-get install cmake g++ git 

Clone the MATRIX HAL NFC repository.

git clone https://github.com/matrix-io/matrix-hal-nfc.git && cd matrix-hal-nfc 

Now move the SW297940.zip file you downloaded into the matrix-hal-nfc folder. If you don't know how to transfer files into your Raspberry Pi, follow this simple guide on using an FTP client.

Once complete, you can install the NXP library into /usr/local/include/matrix_nfc/nxp_nfc with the following command. Please ensure that you have have placed SW297940.zip inside matrix-hal-nfc.

./install_nxp.sh 

Now build and install MATRIX HAL NFC with the following command.

./build.sh 

4. NFC Examples & Compile Instructions

After building is complete, a few compiled examples will be in the build/examples folder.

 

You can compile your own programs with the following command. Be sure to change YOUR_OUTPUT and YOUR_INPUT accordingly.

g++ -o YOUR_OUTPUT YOUR_INPUT -std=c++11 -DNXPBUILD__PH_RASPBERRY_PI -I/usr/local/include/matrix_nfc/nxp_nfc/NxpNfcRdLib/types -I/usr/local/include/matrix_nfc/nxp_nfc/NxpNfcRdLib/intfs -lmatrix_hal_nfc -lmatrix_creator_hal 

 

Helpful Information

MATRIX HAL NFC header files are installed in /usr/local/include/matrix_nfc.

 

The compiled MATRIX HAL NFC library file is installed in /usr/local/lib/libmatrix_hal_nfc.so.