A simple Arduino library for DFRobot's ID01 UHF RFID reader, which otherwise has no publicly available drivers.
The sample code provided on the wiki page for this product only covers two command sequences, and does not actually tell you how to read RFID tags. Furthermore, the manual is complete indecipherable garbage. I spent a few days parsing it and wrote a driver based off of it, but when I went to test it I found that absolutely nothing worked the way the manual said it would. The only thing I could do successfully was read tags in the module's default mode, however nowhere was the format of the output documented.
This Arduino library provides only the bare minimum functionality to read tags with the ID01 module. Without needing to send any commands to the module, it will always start up in "continuous read" mode, spitting out tag IDs that it has read. This lightweight library simply parses these tags and verifies their checksums, providing an easy-to-use API for obtaining tag IDs.
- The library, consisting of
RfidReader.cpp
andRfidReader.h
- A sample sketch,
dfrobot_rfid.ino
-
Copy the
.cpp
and.h
files to your sketch directory, or install them somewhere the Arduino IDE can find them. -
Add
#include RfidReader.h
to the preamble of your sketch. -
Instantiate an
RfidReader
object on theStream
corresponding to the UART where the RFID module is connected. This can be either aSoftwareSerial
orHardwareSerial
device. -
Call
begin
on the serial device if necessary; the default baud rate is 9600. -
Set up a 12-byte buffer to store tag ID's in.
-
Call the
RfidReader
object'sreadTagId
method, passing it your buffer as a parameter. The method returnstrue
if a read a tag; the tag will have been placed into your buffer. If it returnsfalse
, no tag has been read.
The provided sample sketch gives an example of this usage.
- The sample sketch uses
Serial1
as the connection to the RFID module. This assumes an Arduino Due or Mega (or some other Arduino with multiple hardware UARTs). - The
readTagId
function will consume all available input from the UART when it is called. As a result, it will return the most recent tag ID that has been seen since the last time it was called. - The library verifies checksums and frame formats internally, and keeps a fixed-size circular buffer. As a result, it should be robust to any acute serial errors.
For the sake of completeness, here is a description of the tag ID format used by the ID01:
- A tag is sent in a 17-byte frame.
- The frame begins with start sequence
0x00 0x00
. - The ID, 12 bytes, follows.
- After the ID, there is one more byte of
0x00
. - Next, a 1-byte checksum. The sum of all 16 bytes read so far, modulu
0xff
, should be0x00
. - Finally, a trailer byte
0xff
.
The content of this repository is released under the MIT License; see accompanying LICENSE
file for details.