
How do you feel about this article? Help us to provide better content for you.

Thank you! Your feedback has been received.

There was a problem submitting your feedback, please try again later.

What do you think of this article?
Parts list
Qty | Product | Part number | |
---|---|---|---|
1 | OKdo Raspberry Pi 4 B Starter Kit 4 GB | 202-0644 | |
1 | ADAFRUIT INDUSTRIES, Adafruit PN532 NFC/RFID Controller Shield | 905-4633 | |
1 | MIKROE-511, 10 piece Breadboard Jumper Wire Kit | 791-6450 | |
1 | Arduino, Uno Rev 3 | 715-4081 | |
1 | OKdo Raspberry Pi 4 B Starter Kit 4 GB | 202-0644 | |
1 | MIKROE-511, 10 piece Breadboard Jumper Wire Kit | 791-6450 | |
1 | Travel Speaker e.g.https://www.ebay.co.uk/i/174388957610) | ||
1 | RFiD tag 13.56MHz ISO14443-A standard | 882-8972 | |
In The Engineering Edge Podcast "The everyday tech students launched with NASA", I used my phone and the shortcuts app to scan NFC tags and make them speak.
However, for the bonus episode in between, I made my own system, using an NFC reader and an arduino, and then with a Raspberry Pi and Node-RED software.
Arduino System
Parts
- Adafruit PN532 RFID/NFC Shield RS Part Number (905-4633)
- Arduino Uno Rev 3 RS Part Number (715-4081)
- Arduino power cable
- NFC Tags (882-8972)
The instructions I followed were from Adafruit - and are available here. As I was using I2C, I had to comment out some lines in the code (as per instructions). Then, scanning the NFC tag gave the tag's 4 byte ID code etc. the monitor console.
This worked well - but I prefer to program using Node-RED. So I connected an NFC reader to my Pi ...
Image: Top: NFC Shield, Bottom: NFC Breakout Board
Pi System
Parts
- Raspberry Pi Starter Kit RS Part Number (202-0644)
- Adafruit NFC Breakout board https://www.adafruit.com/product/364
- NFC Tags (882-8972)
- Jumper Wires RS Part Number (791-6450)
Adafruit says "The Adafruit NFC Breakout board is much more appropriate with the Pi than the NFC Shield (905-4633) , since the breakout doesn't have 5V level shifting (which means you won't accidentally damage your Pi!), and you have easier access to the bus select pins, etc."
As I had an Adafruit NFC Breakout board, I used it!
1) Install the latest Raspberry Pi operating system on to your Pi
Details here: https://www.raspberrypi.org/software/ (For this project I am using a Raspberry Pi 4 and Raspbian Pi OS (32 bit) 2021-01-11). Follow the on-screen instructions to update and complete the set-up.
2) Install NFC software and connect breakout board
Free UART and other changes.
I used the Adafruit Tutorial: https://learn.adafruit.com/adafruit-nfc-rfid-on-raspberry-pi/overview - but some things have changed since the tutorial was written.
>Here's the edited version I ending up using:
From the command prompt enter the following command: sudo raspi-config
Select 3, Interface Options, P6 Serial Port, then:
Would you like a login shell to be accessible over Serial? Answer No
Would you like the serial port hardware to be enabled? Answer No
Select Finish and Reboot.
Then enter at the command prompt:
sudo nano /boot/config.txt
and remove the line
enable_uart=0
if it exists. And add at the end of the file
enable_uart=1
Save the file (CTRL+O then enter to save the file, and then CTRL+X to quit nano) and reboot.
Building libnfc
Again I used the Adafruit tutorial - here it is with my adaptions:
Step 1 at the command line:
cd /home/pi
mkdir libnfc
cd libnfc
wget https://github.com/nfc-tools/libnfc/releases/download/libnfc-1.7.0/libnfc-1.7.0.tar.bz2
git clone https://github.com/nfc-tools/libnfc.git
tar -xvjf libnfc-1.7.0.tar.
bz2
Step 2 at the command line: (Some of these directories may already be made)
cd libnfc
sudo mkdir /etc/nfc
sudo mkdir /etc/nfc/devices.d
sudo cp contrib/libnfc/pn532_uart_on_rpi.conf.sample /etc/nfc/devices.d/pn532_uart_on_rpi.conf
Then enter at the command prompt:
sudo nano /etc/nfc/devices.d/pn532_uart_on_rpi.conf
Image: The new version of /etc/nfc/devices.d/pn532_uart_on_rpi.conf
Add: allow_intrusive_scan = true" at the end
Replace: /dev/ttyACM0 with /dev/ttyS0
Save the file and reboot.
(With thanks to "topguy" on the Raspberry Pi forum for suggesting this solution back in 2012
https://www.raspberrypi.org/forums/viewtopic.php?t=173121)
THEN at the command line (these take a while)
sudo make clean
sudo make install all
Then shutdown the Pi, and wired it to the NFC Breakout board: https://learn.adafruit.com/adafruit-nfc-rfid-on-raspberry-pi/testing-it-out
Connecting the Parts
I followed the instructions from Adafruit here, but I didn't have a Pi Cobler, so I connected the Breakout Board directly to the Pi using jumper wires.
TXD is Pin 8 GPIO14) on the Pi, and RXD is Pin 10 (GPIO15).
Image: Pi and Breakout Board
TEST as per the Adafruit instructions:
cd examples
sudo ./nfc-poll
Place the NFC tag on board, it will give the UID (unique ID) of the card.
Image: Screenshot showing the UID
3) Install Node-RED
Note: DO NOT USE THE 'RECOMMENDED PROGRAMS' link on the Pi menu, instead go to the "Running on a Pi" section at https://nodered.org/docs/getting-started/raspberrypi and follow the instructions there - use the code:
bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)
And say "Yes" to installing the Pi Nodes.
Wait a long time
Once it is installed run the code:
sudo systemctl enable nodered.service
This will make Node-RED automatically start every time the Pi boots up.
You can then go to a browser and type in localhost:1880 to access Node-RED
3) Install e-speak on to the Pi (This is explained in more detail in the project "We have ways of making your Pi talk"
Change the audio settings to headphones -
sudo apt-get install espeak
Then select: 1 System Options, S2 Audio, Select Headphones, OK and Finish.
BE AWARE - The latest version of Raspbian means that espeak does not work in Node-RED IF you are also using an HDMI cable for a monitor etc. It has something to do with using sudo and Pulse - see https://raspberrypi.stackexchange.com/questions/40236/no-sound-when-using-sudo-in-raspbian
A work around is to set up the Pi using a monitor and then enable SSH, and then turn off the power, unplug the monitor, reboot and SSH in from another computer.
To access Node-RED from another computer: in a browser go to IPADDRESSOFPi:1880 where IPADDRESSOFPi is the IP address of the Pi.
Many thanks to @Ceejay and @jpwsutton for debugging help!
In a terminal, type
sudo apt-get install espeak
answer Y
Write the Node-RED flow
In the Node-RED flow page, click on the Menu (three horizontal lines at the top right)
Click Import
Click Clipboard
Paste the flow (the code listed below) into the grey box
Click Import
Click somewhere on the flow screen (white area in the middle) to drop the code. Click Deploy
It should look like this:
Edit the Switch node, and enter the UID of your NFC tags, and edit the set msg.payload boxes so it says what you want it to say.
No plutonium was used in this build.
Comments
Add a comment