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
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
- Raspberry Pi 5 with SPI enabled
- PTX205R EB
Software
- Raspbian OS
- GTK4 dev package: libgtk-4-dev
- Cmake
- Project source code
NFC Tag(s)
- Type 2, 3, 4 or 5
- RF-technology A, B, F or V
Prepare the PTX205R Evaluation Board
On the PTX205R EB solder the jumpers for:
- MCU OFF
- 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:
Install Required Packages
Connect the Board to the Raspberry
Connect the PTX205R EB PMOD to the Raspberry Pi 5 SPI pins:
- MOSI: GPIO 10
- MISO: GPIO 9
- SCK: GPIO 11
- NSS: GPIO 7
- IRQ: GPIO 19
- SEN: GPIO 21
- GND: GND
Plug in the PTX205R EB's USB-C port for power.
Clone the Repository
GitHub repository: renesas/ptx-rul-gtk: RUL SDK with GTK GUI
Build and Run
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:
Configure cmake:
Build:
Run:
If everything is configured and connected properly, the application is ready for reading NFC tags.
Reading NFC Tags
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.