Hardware Reference
In-Depth Information
Figure 9-17
Screenshots of the Processing sketch to read
SonMicro firmware, showing the results of the
read firmware command (top) and the select tag
command (bottom).
with the Select Tag button. When there's no tag present,
you get a response from the reader saying that. When you
choose Seek Tag, however, you get an initial response that
the command's in progress. Then, when you bring a tag in
range, it reads automatically without you having to send
another command.
Writing to Mifare Tags
Now that you know a little about the SonMicro protocol,
it's time to get on with writing data to the tags. To do this,
you can use the Processing SonMicroReader library, which
you can download from https://github.com/tigoe/SonMi-
croReader-for-Processing. Download the library, unzip it,
copy the resulting folder to the libraries folder of your Pro-
cessing sketch folder, and restart Processing. In the File
Examples menu, you should see a new entry for SonMicro-
Reader under Contributed Libraries. The example called
SonMicroWriter0002.pde follows.
In addition to their tag IDs, which can't change, Mifare
tags have a small amount of RAM that you can read from
and write to. Mifare standard tags have 1 kilobyte, Mifare
classic tags have 4 kilobytes, and Mifare Ultralight tags
have 512 bits. The former two use encrypted communica-
tion for reading and writing, and you have to authenticate
a tag before you can read from or write to it. When you
authenticate, you gain access to one 16-byte block of
memory at a time.
This sketch has a graphical user interface with buttons for
many of the common commands, and text responses in
plain language as well as hexadecimal representations of
the reader's responses. When you're working with a device
that has a lot of functionality like this, sometimes it's
worthwhile to write a tool to work all of its functions—or at
least the most common ones.
The sequence for reading or writing to a block of memory
is always:
• Select Tag
• Authenticate
• Read Block (or write block)
When you run the sketch, you'll get the interface shown in
Figure 9-18. Click the Firmware Version button to get the
firmware version, just to make sure you've got good com-
munication with the reader. Then try reading a few tags
The code for this sketch follows.
 
Search WWH ::




Custom Search