Step One: Prepare for and Download libnfc
Before you can do anything, you will need to get the libnfc library. Make sure you have internet access on your Pi, through Ethernet or WiFi.
If using the full/GUI Raspberry Pi OS, open a terminal window for typing commands.
cd sudo apt-get install git autoconf libtool libusb-dev git clone https://github.com/nfc-tools/libnfc
This will create a new directory “libnfc” in your home directory. Answer “Y” when prompted on the apt-get installation.
Step Two: Set Up libnfc For the Pi
Before libnfc can be built, it needs to be configured for the target system and based on some parameters specific the NFC device you have connected.
libnfc requires a configuration file in a specific location. We’ll start by creating the required folder, then (unrelated) change to the libnfc directory for subsequent steps.
sudo mkdir -p /etc/nfc/devices.d cd libnfc
Next step varies by target system. This refers to the machine where the NFC reader will be connected…occasionally one might set up the OS on one machine, then move the card to a different Pi for use. Follow one or other, not both! If you upgrade or downgrade the Raspberry Pi to a different model later, you might need to recompile everything, depending on which Pi models.
For Recent Raspberry Pi Models
This step works for Raspberry Pi 400, Pi 4, and Pi 3 models B and B+. It almost certainly works on Compute Module 4 and Pi Zero 2W, but did not have hardware on-hand to confirm (worst case, if later tests fail, you can “make clean” and re-try the alternate instructions below).
Enter this command to install the libnfc serial configuration file for these Pi models:
sudo cp contrib/libnfc/pn532_uart_on_rpi_3.conf.sample /etc/nfc/devices.d/pn532_uart_on_rpi_3.conf
This should be entered as one continuous long line…it might appear wrapped to two lines in your browser, but enter it as one with a space character in-between. Or use the “Copy Code” button.
For Earlier Pi Models
This step works for Raspberry Pi 2, Pi 1, and initial Pi Zero models (not Pi Zero 2W). This may work on the wireless Pi Zero W models, but did not have hardware on-hand to confirm (worst case, if later tests fail, you can “make clean” and try the alternate instructions above).
Enter this command to install the libnfc serial configuration file for these systems:
sudo cp contrib/libnfc/pn532_uart_on_rpi.conf.sample /etc/nfc/devices.d/pn532_uart_on_rpi.conf
This should be entered as one continuous long line…it might appear wrapped to two lines in your browser, but enter it as one with a space character in-between. Or use the “Copy Code” button.
Step Three: Configure the Library
The next step is to configure the project itself using the 'configure' tool, as follows:
autoreconf -vis ./configure --with-drivers=pn532_uart --sysconfdir=/etc --prefix=/usr
This may take a minute or two to complete, that’s normal. The output will resemble the following:
Step Four: Build and Install!
Once configured, the following commands then build and install the library:
make sudo make install all
This may take a few minutes to complete. Some compiler warning messages might be generated along the way…these can be safely ignored.
Once the process is complete, you’re ready to test on actual hardware…
Text editor powered by tinymce.