GTK4 NFC Reader App for the Raspberry Pi

by NFCRenCS in Circuits > Raspberry Pi

67 Views, 0 Favorites, 0 Comments

GTK4 NFC Reader App for the Raspberry Pi

rpi5-ptx205r.jpg

The RUL SDK for the PTX205R NFC reader comes with an example console application, which demonstrates reading NFC tags and NDEF messages of NFC Forum tag-types 2, 3, 4, 5 using RF-technologies A, B, F and V. The SDK also includes a reference SPI Hardware Abstraction Layer (HAL) and Operating System Abstraction Layer (OSAL) implementation for the Raspberry pi 5. This project aims to demonstrate how easy it is to integrate the SDK into a GTK4 GUI application running on the Raspberry.

When the application is launched, the PTX205R is initialized in a separate thread and when ready, NFC discovery can be started by clicking the START button. The discovery process runs in its own thread and whenever a tag is activated, the protocol, RF-technology, UID is displayed. In case the tag is NDEF-formatted and contains a message, it is also displayed as an UTF-8 encoded string, without any special parsing. There is also a menu with an About and a Preferences window and keyboard-shortcuts to reset discovery, quit the application and open the Preferences window.

Supplies

Hardware

  1. Raspberry Pi 5 with SPI enabled
  2. PTX205R EB

Software

  1. Raspbian OS
  2. GTK4 dev package: libgtk-4-dev
  3. Cmake
  4. Project source code

NFC Tag(s)

  1. Type 2, 3, 4 or 5
  2. RF-technology A, B, F or V

Prepare the PTX205R Evaluation Board

ptx205r-eb-mcu-off.jpg

On the PTX205R EB solder the jumpers for:

  1. MCU OFF
  2. PMOD_VDD TO VDD_IO

Also solder a PMOD connector, if it's not already there.

Prepare the Raspberry Pi 5

Enable SPI

Turn on Preferences -> Control Center -> Interfaces -> SPI.

Or using the command line:

sudo raspi-config nonint do_spi 0
sudo reboot

Install Required Packages

sudo apt update
sudo apt install -y cmake libgtk-4-dev

Connect the Board to the Raspberry

ptx205r-pmod.jpg

Connect the PTX205R EB PMOD to the Raspberry Pi 5 SPI pins:

  1. MOSI: GPIO 10
  2. MISO: GPIO 9
  3. SCK: GPIO 11
  4. NSS: GPIO 7
  5. IRQ: GPIO 19
  6. SEN: GPIO 21
  7. GND: GND

Plug in the PTX205R EB's USB-C port for power.

Clone the Repository

Build and Run

app-launched.jpg

The app is designed to be run from the PROJECTS/PTX2xxR/NFC_FORUM_BASIC_DISCOVERY/BUILD directory, where it can find the SDK's shared object file, the UI files and the compiled settings file. All commands below shall be run from there.

Make sure the linker will find the SDK shared library, this needs to be run at least once:

export LD_LIBRARY_PATH=$(pwd):$LD_LIBRARY_PATH

Configure cmake:

cmake .. -DPTX_BUILD_LIN=ON -DPTX_ENABLE_SPI=ON -DPTX_UTILITY_PRINTING=Console -DPTX_LOGGING=File

Build:

cmake --build .

Run:

./NFC_FORUM_BASIC_DISCOVERY

If everything is configured and connected properly, the application is ready for reading NFC tags.

Reading NFC Tags

app-reading.jpg
app-menu.jpg
app-prefs.jpg

Click START and the app will display information about discovered tags, one at a time. Multiple tags in the field are supported by the RUL SDK and the PTX205R, but it's not implemented in this application. If a card contains an NDEF record, it will be displayed as a UTF-8 encoded string, without any special parsing. Click STOP to stop the discovery.

There's a menu for opening the About and Preferences window and actions to reset discovery and quit the application. The preferences window contains a setting to turn dark mode on or off. Resetting will reset the discovery loop and clear the screen. Closing or quitting the application will terminate any ongoing discovery.

Final Words

This application demonstrates how easy it is to integrate the RUL SDK and the PTX205R into a working NFC reader application, using GTK4 and the Raspberry Pi. It serves as an example and it can be a starting point or an inspiration for much more complex and feature rich projects.