This is only a preview of the September 2018 issue of Silicon Chip. You can view 53 of the 112 pages in the full issue, including the advertisments. For full access, purchase the issue for $10.00 or subscribe for access to the latest issues. Items relevant to "Dipole guitar/PA speaker without a box!":
Items relevant to "Digital white noise generator":
Items relevant to "Steam loco or diesel engine sound effects module":
Items relevant to "Super sound effects module – Part 2":
Items relevant to "El Cheapo modules Part 19 – Arduino NFC Shield":
Articles in this series:
Purchase a printed copy of this issue for $10.00. |
Using Cheap Asian Electronic Modules Part 19: by Jim Rowe
Arduino FC Shield
This low-cost NFC (Near-Field
Communication) shield for Arduino
uses the same technology as RFID
and contactless payments (payWave/
PayPass). It allows just about any Arduino board to read data from
NFC/RFID tags or cards or write data to certain devices. You can also
exchange data with other NFC devices, including many smartphones.
T
his shield, plus an Arduino module, could be used as the basis for
a number of useful devices, for example, to unlock a door using an access
card, to monitor the passage of stock
or other items on a conveyor belt, to
transmit business card information to
customers’ smartphones and so on.
But before we explain how it works,
we will explain how RFID and NFC
work.
NFC or Near-Field Communication
is a set of protocols that enable two
electronic devices to exchange data
by bringing them within about 40mm
of each other.
Communication is by electromagnetic induction, ie, coupling signals
between loop antennas in each device.
In effect, when the two antennas are
brought within 40mm of each other
they form an air-cored RF transformer.
NFC involves low-power RF signals
with a carrier frequency of 13.56MHz,
in one of the globally available and
unlicensed ISM (industrial, scientific
and medical) bands.
One of the devices involved in NFC
communication can be passive, ie,
with no onboard power source. This
is typically the case with RFID (radio-frequency identification) tags and
smart cards.
86
Silicon Chip
In this situation, the device that is
powered powers the circuitry in the
passive device via the energy of the
13.56MHz RF carrier. The passive
device then “replies” by modulating
the carrier, with the modulated signal
picked up by the active device.
RFID technology was developed
in 1983 by Charles Walton. Sony and
Philips agreed to establish a compatible specification and this was approved as an ISO/IEC standard in 2000
(ISO/IEC 14443). The passive tags and
cards used for RFID typically store between 96 and 8192 bytes of data, which
can be read (and in some cases, written) using the RFID protocol.
Nokia, Philips and Sony established
the NFC Forum in 2004. It is a nonprofit industry association which promotes the implementation and standardisation of NFC technology to ensure interoperability between devices
and services.
NFC provides the same functions as
RFID but also allows for communications when both devices are powered.
In this case, power is not transferred
using the carrier and the two devices
can exchange data in an ad-hoc peerto-peer fashion.
The standard defining NFC is ISO/
IEC 18092. This technology is now
Australia’s electronics magazine
found in all manner of smartphones
and other portable devices.
Sony’s FeliCa RFID system includes
dynamic encryption for increased security. It was considered as part of the
ISO/IEC 14443 RFID standard but in
the end, was not included. However,
some of the principles used by FeliCa
ended up being used as part of the later
NFC standard.
Three different data exchange rates
are in current use by NFC devices:
106kb/s, 212kb/s and 424kb/s. If an
active device transfers data at 106kb/s,
it uses modified Miller coding with
100% modulation. Miller coding is a
type of Modified Frequency Modulation known as “delay encoding”. This
is similar to NRZ (non-return-to-zero)
encoding but with less power radiated
at lower frequencies.
For the higher data rates, Manchester coding is used, with a modulation
ratio of 10%. Manchester encoding is
another method of turning a bitstream
into a symmetrical AC signal and is
also used for transmitting digital audio data (S/PDIF).
Elecrow’s NFC shield
The Elecrow ACS53201S NFC
shield measures 69 x 53mm (including
the loop antenna) and it plugs directly
siliconchip.com.au
Fig.1: simplified block diagram for the PN532 controller IC. The chip is
based around four sections: an NXP 80C51 micro (an old design!), NFC
communications block, serial block and power/clock/reset controller.
into an Arduino Uno or Mega 2560, or
one of the many compatible modules.
It derives its power from the Arduino
and even comes with a passive keyring
NFC tag for testing (see lead photo).
At the heart of the shield is the NXP/
Philips PN532 NFC controller IC. The
internals of this IC are summarised in
the simplified block diagram, Fig.1.
It’s based around an NXP 80C51 microcontroller (upper right), which includes 1KB of RAM (working memory) and 40KB of ROM (for storing the
firmware).
The other main sections are the contactless interface unit or CIU (at lower
right) which handles the actual NFC
communication, and the host interface
section at lower left which handles
communication with the host computer or controller (in this case, the
Atmel micro on the Arduino board).
The host interface section can be
configured to communicate via SPI (serial peripheral interface), I2C (inter-IC
serial communication) or a high-speed
UART (HSU; ie, serial) connection. But
note that the PN532 chip used in the
Elecrow NFC shield has been configured for SPI only.
Fig.2 shows the full circuit of the
Elecrow NFC shield, plus a block diagram of an Arduino host at upper left.
siliconchip.com.au
The PN532 device, IC1, connects to
the NFC loop antenna at top right via
the TX1, TX2 and RX pins and a network of passive components. These
include inductors L1, L2 and various
capacitors and a few resistors. These
are used for impedance matching, to
make the antenna resonant at the required frequency and to filter out unwanted signals.
IC1 uses 27.12MHz crystal X1 to
generate its internal master clock and
divides this by a factor of two to pro-
duce the NFC carrier frequency of
13.56MHz.
Although IC1 can operate from supply voltages of 2.7-5.5V, in the Elecrow
shield it is powered from a 3.3V regulated supply. This is derived from the
Arduino’s 5V supply via REG1, an
MIC5205-3.3 LDO (low dropout) regulator. This is separate from the 3.3V
rail from the Arduino since IC1 can
draw up to 200mA when transmitting,
which could overload the regulator on
the Arduino.
This means that level translation
is necessary on the SPI signal lines
between IC1 and the Arduino. That’s
provided by IC2, a 74LV4T125 quad
buffer translator. Three of IC2’s buffers
are used to translate the logic levels of
the MOSI, SCK and MISO signal lines,
with the fourth buffer unused. IC2 is
also powered from the +3.3V supply
from REG1.
The only other components on the
board are a number of bypass and filter capacitors for IC1, IC2 and REG1,
a pull-up resistor on pin 38 of IC1 to
enable it and a capacitor and resistor
connected to the Vmid pin of IC1 (pin
9), which is used to DC bias its RX pin
(pin 10) to half supply.
Note that Jaycar sell a similar NFC
Shield, made by “linksprite” (Cat
XC4542). While not identical to the
Elecrow shield, it is compatible and
we have tested it successfully with the
same software.
Arduino software
Luckily Elecrow has made the software side of things quite easy by making available an Arduino library written specifically for communicating
with the PN532 via the SPI port. The
library can be downloaded from
the Elecrow website
The NFC shield easily
slots into an Arduino Mega or
Uno, as shown in Fig.2.
Australia’s electronics magazine
September 2018 87
Fig.2: complete circuit diagram for the Elecrow ACS53201S
near-field communication (NFC) shield, and wiring
diagram for the shield with an Arduino, or similar, board.
Screen 1: using the readMiFareMemory.ino sketch reads
and then prints the data from the RFID card and keytag.
88
Silicon Chip
Screen 2: the readAllMemoryBlocks.ino sketch reads the
card’s memory after writing 16 bytes into it (to block 8).
Australia’s electronics magazine
siliconchip.com.au
Fig.3: wiring diagram for a
Micromite to the Elecrow NFC
shield. We’ve converted the
Arduino NFC library into a
BASIC library so that you can
use it with the Micromite. The
library can be downloaded
from the Silicon Chip website.
S53201S NFC shield would
be to modify one of the example sketches. Or if you’re doing something fairly complex
(eg, which involves both reading and writing data), you
may need to incorporate
bits and pieces of the example sketches into your own
sketch.
If you want to fully understand how to use the PN532_
SPI library functions, it is
simply a matter of studying
the example sketches to see
how they operate.
Using it with a Micromite
in a zip file called PN532_SPI.zip (see
Links panel).
This can be made available for use
in the Arduino IDE by clicking on the
Sketch menu and then on the Include
Library → Add .ZIP Library menu option. Select the ZIP file that you have
downloaded and it will be added to
the IDE’s library list.
The library comes with six example
sketches, named:
writeMifareMemory
readMifareTargetID
readMifareMemory
readAllMemoryBlocks
PtoPTarget
PtoPInitiator
siliconchip.com.au
“Mifare” is another way of referring
to passive NFC tags and cards. The
“PtoP” part of the last two sketch titles is short for “peer to peer” and indicates that these sketches are used
for NFC communication between two
active devices.
I tried opening and running the first
four of these example sketches with
the Elecrow NFC shield connected to
both an Arduino Uno and a Mega 2560.
In each case, I tested it with both the
keyring tag that came with the shield
and also with an NFC card that came
with another NFC/RFID reader.
In each case, it worked exactly as
expected and I was able to read data
from and write data to both passive
devices with no problems.
You can get an idea of how the example sketches work from the adjacent screen grabs. Both grabs are of
the Arduino IDE’s Serial Monitor.
Screen 1 shows the output when
reading the card first and then
the keyring tab, using the readMifareMemory sketch.
Screen 2 shows the results
when using the readAllMemoryBlocks sketch to interrogate the card after using the
writeMifareMemory sketch to
write 16 bytes into the card’s
memory (to block 8).
The easiest way to build your own
application using the Elecrow ACAustralia’s electronics magazine
What if you want to use the shield
with another MCU, like a Micromite?
Since it has a standard SPI port, it’s
quite easy to make the required connections, as shown in Fig.3.
The software is a bit more tricky
though since there was no Micromite
library available to interface with the
PN532 IC. So, we have translated the
Arduino library into a Micromite BASIC file and have made this available
for download from our website (free
for subscribers).
We have also translated some of
the example programs. The download
package includes several BASIC files
which all start with an identical set
of library functions but have different
sample code snippets at the bottom.
Having wired up the shield as
shown in Fig.3, it’s simply necessary
to upload one of these programs to
the Micromite and run it. You should
see similar output on the Micromite
serial console as shown in the screen
grabs above.
Extra links
NFC Forum: https://nfc-forum.org/
PN532 data sheet: siliconchip.com.
au/link/aakl
PN532 user manual: siliconchip.
com.au/link/aakm
How to use the PN532: siliconchip.
com.au/link/aakn
Elecrow shield library: siliconchip.
SC
com.au/link/aako
September 2018 89
|