RFID 125KHz - Libelium

murmurgarbanzobeansElectronics - Devices

Nov 27, 2013 (4 years and 1 month ago)

171 views

RFID 125KHz
Networking Guide
-2-
v4.1

Index
Document version: v4.1 - 04/2013
© Libelium Comunicaciones Distribuidas S.L.
INDEX
1. Introduction .........................................................................................................................................3
2. Hardware ..............................................................................................................................................5
3. Dual Radio with the Expansion Board ...............................................................................................7
3.1. Expansion Radio Board ..............................................................................................................................................................7
3.2. Setting ON ......................................................................................................................................................................................8
3.3. Setting OFF .....................................................................................................................................................................................8
4. RFID cards and tags .............................................................................................................................9
5. Usage ..................................................................................................................................................11
6. Security with RFID at 125 KHz ..........................................................................................................13
7. RFID: 13.56 MHz or 125 KHz? ............................................................................................................14
8. Libelium’s API .....................................................................................................................................15
8.1. Switching the module on .......................................................................................................................................................16
8.2. Switching the module off ......................................................................................................................................................16
8.3. Reading the serial number of an EM4100/02 card........................................................................................................16
8.4. Requesting to read a T5557 card .........................................................................................................................................16
8.5. Requesting to read a T5557 card with password...........................................................................................................17
8.6. Getting data from a T5557 card ...........................................................................................................................................17
8.7. Printing the content of a T5557 card .................................................................................................................................17
8.8. Writing data in a block of a T5557 card .............................................................................................................................17
8.9. Writing data with password in a block of a T5557 card ...............................................................................................18
8.10. Writing data in a block of a T5557 card and checking it ...........................................................................................19
8.11. Writing data with password in a block of a T5557 card and checking it ............................................................19
9. Time of execution of the functions ...................................................................................................20
10. Code examples and extended information ...................................................................................21
11. Documentation changelog .............................................................................................................23
-3-
v4.1
Introduction
1. Introduction
RFID (Radio Frequency Identification) is a technology that uses electromagnetic fields to identify objects in a contactless way; it
is also called proximity identification. There are 2 elements in RFID communications: the RFID module (or reader/writer device)
and an RFID card (or tag). The RFID module acts as the master and the card acts as the slave; this means the module queries the
card and sends instructions to it. In a normal RFID communication, the RFID module is fixed and the user takes his card near it
when he needs to start the interaction.
Figure 1: Waspmote with RFID at 125 KHz module on socket 0 and WiFi module on socket 1
An RFID card can be understood as a remote storage unit where we can read and write information without contact. Most of the
RFID tags are passive, which implies that the RFID module must create an electromagnetic field in order to power the tag. The
RFID card’s antenna (in fact it is an inductive coupler) gets the power from this field. Also, an RFID card has a very basic micro-
controller which manages the communications and memory access.
Many RFID standards have been released by the industry. Most of them have as operating frequency 125 KHz or 13.56 MHz.
Libelium has integrated one module for each frequency. Besides, the module for 13.56 MHz is compliant with the Near Field
Communication (NFC) technology; for more information read chapter “RFID: 13.56 MHz or 125 KHz?”. In the present document we
will be explaining the RFID module which works at 125 KHz, and any reference to RFID must be understood as RFID for 125 KHz.
In particular, Libelium has created a module which is compliant with two 125 KHz RFID protocols, among others: EM4100/
EM4102 and T5557. These 2 protocols are very popular and accepted in many applications.
Waspmote communicates with the RFID module through one of its 2 UARTs. Basically, Waspmote sends commands or instruction
packets to the RFID module and then waits for the response packets from the module.
There is just one way to interact with an EM4100/02 card: reading its serial number, 4-byte long (anf the check byte). Note the
card does not stores any password and the data (the serial data) cannot be protected.
Regarding a T5557 card, there are 2 possible operations because this protocol performs writing too:
1. the module reads the card’s internal memory (from 4 to 28 bytes each time (from 1 to 7 blocks, depending on configuration))
2. the module writes in the card’s internal memory (4 bytes each time (1 block))
The API developed by Libelium allows an easy management of all the possible actions with the cards, becasue the API permits
the Waspmote user to perform a higher level programming.
-4-
v4.1
Introduction
Among the RFID applications, the most common are:
• access control/security
• events ticketing
• public transport
• equipment and personnel tracking
• logistics
• real-time inventories
• marketing information (kiosks)
Figure 2: Some RFID applications
-5-
v4.1
Hardware
2. Hardware
Libelium’s RFID module integrates an SM125 RFID-reader/writer integrated circuit.
Figure 3: RFID module for 125 KHz and antenna
Features:
• Compatibility: Reader/writer mode supporting ISO cadrs - T5557 / EM4102
• Distance: 5cm
• Max capacity: 20B
• Tags available: cards, keyrings
Among several 125 KHz RFID standards; Libelium’s module is compliant with EM4100/02 and T5557, which are very successful
international standards in RFID technology. This technologies operate at the 125 KHz LF frequency band, so it can be deployed
anywhere without authorization or license.
The SM125 implements the RF, analog and digital tasks in transmission and reception, while Waspmote’s role is to control these
operations. The RFID module is connected to Waspmote through one of its 2 UART interfaces ([1] XBee socket or [2] GPRS socket,
enabled by the Expansion Board). Waspmote sends command frames to the module and receives response frames.
A command frame has the following structure:
• header (1 byte): It indicates the beginning of a new frame. It is always 0xFF.
• reserved (1 byte): Always 0x01.
• length (1 byte): It indicates the length of the payload data (command + data bytes).
• command (1 byte): It indicates which command the module must perform.
• data (N bytes): It contains the parameters needed for the selected command.
• checksum (1 byte): It is the addition of all the bytes in the frame, with the exception of the header.
And a response frame has an equivalent structure:
• header (1 byte): It indicates the beginning of a new frame. It is always 0xFF.
• reserved (1 byte): Always 0x01.
• length (1 byte): It indicates the length of the payload data (command + response bytes).
• command (1 byte): It indicates which command (previously sent by Waspmote) is being replied by the module.
• response (N bytes): It contains the reponse bytes from the module.
• checksum (1 byte): It is the addition of all the bytes in the frame, with the exception of the header.
-6-
v4.1
Hardware
For both types of card, there are different mechanisms (checksum, parity, bit encoding, ACK, etc) to ensure the data integrity.
Besides, the T5557 standard offers the possibility of using a password to access data.
Regardless the type of card, the module replies with a standard response when a command was successfully executed:
0xFF 0x01 0x01 0x99 0x9B.
This response can be seen as an ACK, confirming that the module received the command and executed it. After this ACK,
and depending on the command, another reply can be sent by the module. Note that maybe the whole operation was not
completed even if the ACK is received, it just means the module received and executed the command internally. For example,
data could not be written in the card if it was not present; the user should check the writting was successful by reading the block
manually.
The RFID antenna is 43x20x5 mm and is made of thin wire, so it must be handled with care.
-7-
v4.1
Dual Radio with the Expansion Board
3. Dual Radio with the Expansion Board
Before starting to use a module, it needs to be initialized. During this process, configuration parameters are sent to the module.
USB and SD card are also initialized.
3.1. Expansion Radio Board
The RFID module can use the Expansion Radio Board. The new Expansion Board allows connecting two radios at the same
time in the Waspmote sensor platform. This means a lot of different combinations are now possible using any of the 10 radios
available for Waspmote: 802.15.4, ZigBee, 868 MHz, 900 MHz, Bluetooth, RFID, RFID/NFC, Wifi, GPRS and 3G/GPRS.
Some of the possible combinations are:
• ZigBee - Bluetooth
• ZigBee - RFID
• RFID/NFC - Wifi
• ZigBee – 3G/GPRS
• Wifi - RFID
• Wifi - 3G/GPRS
• Wifi – Bluetooth
• etc.
Remark: the GPRS module and 3G/GPRS module do not need the Expansion Board to be connected to Waspmote. It can be plugged
directly in the GPRS socket.
Next image shows the sockets available along with the UART assigned. On one hand, SOCKET0 allows to plug any kind of radio
module through the UART0. On the other hand, SOCKET1 permits to connect a radio module through the UART1.
Figure 4: Waspmote with XBee radio on socket 0 and Bluetooth module on socket 1
This API provides a function in order to initialize the RFID module module called RFID125.ON(socket). This function
supports a new parameter which permits to select the socket. It is possible to choose between socket0 or socket1.
-8-
v4.1
Dual Radio with the Expansion Board
An example of use the initialization function is the following:
• Selecting socket0: RFID125.ON(SOCKET0);
• Selecting socket1: RFID125.ON(SOCKET1);
The rest of functions are used the same way as they are used with older API versions. In order to understand them we recommend
to read this guide.
WARNING:
• Avoid to use DIGITAL7 pin when working with Expansion Board. This pin is used for setting the XBee into sleep.
• Avoid to use DIGITAL6 pin when working with Expansion Board. This pin is used as power supply for the Expansion Board
Incompatibility with Sensor Boards:
• Gases Board: Incompatible with SOCKET4 and NO
2
/O
3
sensor.
• Agriculture Board: Incompatible with Sensirion and the atmospheric pressure sensor.
• Smart Metering Board: Incompatible with SOCKET11 and SOCKET13
• Smart Cities Board: Incompatible with microphone and the CLK of the interruption shift register.
• Events Board: Incompatible with interruption shift register.
3.2. Setting ON
With the function ON() module is powered and the UART is opened to communicate with the module. It also enters in command
mode and sets some default configurations.
// switches ON the RFID/NFC module using expansion board
RFID125.ON(SOCKET1);
3.3. Setting OFF
The RFID API function OFF() exits from the radio RFID command-mode securely, closes the UART and switches the module off.
RFID125.OFF();
-9-
v4.1
RFID cards and tags
4. RFID cards and tags
Libelium offers EM4100/02 cards and tags and T5557 cards and tags. An RFID card has a thin form factor (81x54x1 mm), like a
driving license or identification card, and can be kept in the user’s wallet. However, an RFID tag is smaller and thicker (around
20x20x5 mm) but can be kept in the user’s keyring.
It is important to note that a card always has a longer range than a tag because its antenna has more surface.
Figure 5: RFID cards
Figure 6: RFID tags
The EM4100/EM4102 cards are read-only, they cannot be written. They just store a serial number of 4 bytes and the check byte.
The protocol involved is pretty simple, and was created by EM Microelectronic. The EM4100/02 cards have a header composed
of 9 “1’s”. After this, the RFID module takes care of the Manchester bit modulation.
On the other hand, the T5557 cards can be read and written. The card is divided into 8 blocks, where each block stores 4 bytes.
Among these 8 blocks, there are 5 blocks available for the user to store data, while 2 blocks are used for configuration issues and
1 block for storing the password. Blocks can be protected with a password of 4 bytes. Libelium does not advice to change the
password in this type of cards unless the user has solid experience.
-10-
v4.1
RFID cards and tags
Regarding a T5557 card, the memory structure of a card is as follows:
• block 0x00: Configuration block. When the card is powered by the field, the first thing the card does is to configure itself
with the info contained in block 0x00 (enconding protocol, max read blocks, data rate, password mode, protective lock).
This block should not be written with arbitrary values; otherwise the tag may not be accessed again.
• block 0x01: This block is used for Byte Track method. The 4 bytes programmed in this block are a known pattern that should
be traced by the module in order to synchronize the incoming data stream. Its content typically is 0x52 0x58 0x8B 0x45.
• block 0x02: Data block, available for the user.
• block 0x03: Data block, available for the user.
• block 0x04: Data block, available for the user.
• block 0x05: Data block, available for the user.
• block 0x06: Data block, available for the user.
• block 0x07: Password block (or data block like blocks 0x02-0x06 if password mode is not enabled). If password is enabled,
access to the tag requires the password that matches block 0x07 content. Bear in mind that once password is enabled then
it is impossible to access the tag again unless we provide the correct 4-byte password.
It is not advised to write block 0x00, 0x01 or 0x07 if you are not an advanced user. You could leave your card unaccessible.
To sum up, the total storage capacity is 20 bytes, or 24 bytes if the Password Mode is not enabled and we use the block 0x07.
-11-
v4.1
Usage
5. Usage
The maximum operational range is about 6 cm from the antenna. A card beyond this distance will not be detected, or the
communications with it will be full of errors. Card writing distance can be a little shorter.
Notice the antenna can also operate with cards at 90º from its surface, but the range is around 40%.
Besides, the minimum range are a few mm. A card which is closer than this to the RFID module’s antenna could not be detected.
Optimal results are obtained when the card is placed parallel to the surface of the antenna, still and at a distance of 1 cm.
As shown in the examples, it is good to use “if’s” to control which functions are executed. For example, if the getCard() function
was not successful, it does not make sense to execute one writeBlock() after that. Note there are functions should deliver ‘0’
when executed correctly.
When any of the functions does not deliver a successful execution, it is advised to end the loop and start the RFID process from
the beginning.
A typical read or write process can take more than one second. Make sure the card remains within the field until the whole
process is completed.
Figure 7: Typical RFID operation
Some kind of indicator is strongly advised to let the user know that data exchange was successful. Waspmote can control a LED
(built-in or external) or a buzzer for this goal.
After a successful operation, it is advised to execute a short delay (e.g. 2 seconds) to let the user take his card away. This way we
avoid to execute the same operation more than one time.
The RFID antenna should be located in an accessible and comfortable place for the user.
The RFID antenna, the RFID module, the battery or Waspmote are not waterproof, so an enclosure is mandatory when the
system is going to work outdoors. The antenna should be fixed really close to the wall of the enclosure. Metallic enclosures are
not advised.
-12-
v4.1
Usage
In general, avoid placing the RFID antenna near metallic objects, since the communication range could decrese.
It can be a good idea to place the antenna near the top of the enclosure, in parallel with the ground. This way the user can just
let the card lie still on top of the case for a while. Wherever the antenna is, do not forget to indicate in your enclosure where it is.
Use the Waspmote’s Expansion Board to enable another communication module to transmit certain (or all) RFID operations to
another device or to a data center.
Use a micro SD card to store certain (or all) RFID operations. This can be a security back up.
Add one Meshlium device to your ecosystem for advanced features such as Linux OS tools, local MySQL data base storing
system, WiFi and Ethernet connectivity, remote web server or higher computing speed.
-13-
v4.1
Security with RFID at 125 KHz
6. Security with RFID at 125 KHz
EM4100/02 cards have an serial number with a length of 4 bytes, so there are 4,200 millions of different serial numbers.
On the other hand, the password of a T5557 card has a length of 4 bytes. That means there are 4,200 different possible passwords.
Libelium does not advice to use the Password Mode unless the user knows what to do. 13.56 MHz RFID module permorms an
easier and more secure password mabagement.
Remember read/write access can also be permitted without any password if the Password Mode remains disabled. Kindly notice
that T5557 cards do not have a serial number, but the user could use the data blocks in the card to write the serial number he likes.
These numbers, along with the data integrity mechanisms, demonstrate that 125 KHz RFID is a pretty secure technology.
FAQs
Q: Can I change the serial number in a given card?
A: In a T5557 card, there is not a serial number, and all the memory has read and write access. The user can write his own
invented serial number in one block if he likes.
In an EM4100/02 card, there is a serial number and it cannot be changed since the memory has read-only access. There are
security reasons to do so: if an EM4100/02 card could be written, it would be possible to duplicate or forge cards.
Q: Can I consider an EM4100/02 card’s 4-byte serial number card as unique or not?
A: No, but there is just one possibility among thousands of millions that you find another card like yours.
Q: Can I order or select a specific serial number for my EM4100/02 card?
A: No, the cards’ serial numbers are set in a random way.
Q: I do not know/remember the password for a T5557 card, can I read or write this card?
A: No, if the Password Mode is enabled then it is not possible to access a T5557 card’s block unless we have provided the
password before. All cards are provided with the Password Mode disabled. If the user enables the Password Mode, he must
remember the content of the block 0x07 in that moment, because this will be the password for all the blocks.
Q: Are the EM4100/02 or T5557 standards 100% secure systems?
A: No. Any security system has bugs that can be hacked. The 13.56 MHz RFID technology is probably a better choice if security
is an important issue. Waspmote’s 13.56 MHz RFID module performs advanced security methods, like encrypted wireless
communications between the card and the module, three-pass authentication or improved data integrity systems.
Q: Does Libelium recommend its RFID module for electronic money exchange?
A: No. The RFID module by Libelium is not intended for payment applications but for control of usage.
Q: Should I change the password to the cards?
A: EM4100/02 cards do not have password and the serial number cannot be protected.
Regarding T5557 cards, yes, you should change the password if it is possible that someone is interested in reading or
changing the stored information but remember what said above. Setting a new password is a delicate process and will
ensure only the authorized agents can read or write the data. Avoid sharing or losing this information.
We advise to set a random password. As a tip, it would be an even more secure system if each card has its own password.
-14-
v4.1
RFID: 13.56 MHz or 125 KHz?
7. RFID: 13.56 MHz or 125 KHz?
Libelium has developed 2 different RFID modules: 13.56 MHz and 125 KHz. They are not compatible because they comply with
different standards. As a result their working frequencies are very different, and the communication protocols are not the same.
So:
• 13.56 MHz RFID cards cannot work with the 125 KHz RFID module
• 125 KHz RFID cards cannot work with the 13.56 MHz RFID module
Everything said here about 13.56 MHz RFID technology is also applicable to the NFC technology.
The decision to adopt one system or the other depends on several points. First of all, if you are purchasing Libelium’s RFID
solution to fit an existing system you will want to to keep the compatibility.
Both frequency bands are suitable to be used in any country. 125 KHz (LF) is unregulated and 13.56 MHz (HF) is an ISM band.
In general, the industry has used the 125 KHz RFID technology in projects that identify and track objects (like in a supply chain),
while the 13.56 MHz RFID technology is used in applications that identify objects or people and store information.
A 125 KHz RFID card, T5557 type, has a memory of just 20 bytes, while a 13.56 MHz RFID Mifare® card, 1k type, has up to 752
available bytes. This seems a great difference, but bear in mind 20 bytes are enough to store information such a long ID code.
Regarding maximum ranges, a 125 KHz RFID card has a longer read range (about 6 cm) than a 13.56 MHz RFID card (3 cm).
However, when the operation includes writing, the range of a 125 KHz RFID card is smaller (1 cm).
The 13.56 MHz RFID module and its cards implement more secure communications, which includes advanced methods for safer
authentication, counterfeiting prevention, encryption and data integrity. Besides, a 13.56 MHz RFID key is longer and safer than
a 125 KHz RFID password. Therefore, 13.56 MHz RFID is the best option if security is important.
As said before, it is not advised to place the RFID system near metallic objects; however the 125 KHz RFID technology seems to
be the most adaptive to a metal environment. However, in industrial environments, the 125 KHz RFID communications could be
affected by the noise generated by motors, while the 13.56 MHz technology would not.
The 13.56 MHz RFID module has faster data rates in read or write operations.
-15-
v4.1
Libelium’s API
8. Libelium’s API
It is mandatory to include the RFID library when using this module. The following line must be introduced at the beginning of
the code:
#include <WaspRFID125.h>
Waspmote’s API RFID files:
• RFID125.cpp
• RFID125.h
APIs functions
Function Brief description
OFF()
switches the module off
ON(socket)
switches the module on in one of the 2 UARTs
reset()
resets the module via software
goToSleep(secs)
go to sleep mode for 'secs' seconds
readSerialNumber(secs,
snB0, snB1, snB2, snB3)

sends to the module the command to read the serial number of an
EM4100/02 card. Waits for ‘secs’ seconds for a card to be read.
requestReadCard(modeRead, blocks)
sends to the module the command for reading a card's blocks
requestReadCardWithPass(modeRead, blocks,
pass0, pass1, pass2, pass3)
sends to the module the command for reading a card’s blocks with
password
getCard(mData)
reads the response of the module to a requestReadCard() command
printCard(matrix)
prints the content of a T5557 card via the serial port
writeBlock(block,
data0, data1, data2, data3)
sends to the module the command for writing data in one block of
one T5557 card
writeBlockWithPass(block,
data0, data1, data2, data3,
pass0, pass1, pass2, pass3)
sends to the module the command for writing data in one block of
one T5557 card which is protected with password
writeBlockAndCheck(block,
sends to the module the command for writing data in one block of
one T5557 card and checks that
writeBlockWithPassAndCheck(block,
data0, data1, data2, data3,
pass0, pass1, pass2, pass3)
sends to the module the command for writing data in one block of
one T5557 card which is protected with password and checks that
writeByte(data) writes a byte (hex) in ASCII via the serial port
blinkLED() blinks the LED to signal something
-16-
v4.1
Libelium’s API
8.1. Switching the module on
It switches the RFID module on.
Example of use
{
RFID125.ON(); // switches the module on
}
See example:
www.libelium.com/development/waspmote/examples/rfid125-01-reading-em4100-tags
8.2. Switching the module off
It switches the RFID module off.
Example of use
{
RFID125.OFF(); // switches the module off
}
See example:
www.libelium.com/development/waspmote/examples/rfid125-01-reading-em4100-tags
8.3. Reading the serial number of an EM4100/02 card
It sends to the module the command for reading a EM4100/02 card’s serial number. Then the function waits for a card during a
certain amount of seconds.
Example of use
{
state = RFID125.readSerialNumber(seconds, serNum0, serNum1, serNum2, serNum3);
}
See example:
www.libelium.com/development/waspmote/examples/rfid125-01-reading-em4100-tags
8.4. Requesting to read a T5557 card
It sends to the module the command for reading a T5557 card’s blocks.
Example of use
{
RFID125.requestReadCard(1, 7); // sends to the module the command to read the 7 blocks of a
// a T5557 type card, Byte Track mode
}
See example:
www.libelium.com/development/waspmote/examples/rfid125-02-reading-t5557-tags
-17-
v4.1
Libelium’s API
8.5. Requesting to read a T5557 card with password
It sends to the module the command for reading a card’s blocks when the card is protected with a 4-byte password.
Example of use
{
RFID125.requestReadCardWithPass(1, 7, 0x01, 0x02, 0x03, 0x04); // sends to the module the
// command to read the 7 blocks of a T5557 type card which is
// protected by the password 0x01 0x02 0x03 0x04
}
8.6. Getting data from a T5557 card
It receives and parses the content of a T5557 card. Remember the internal structure of a card in the chapter “RFID cards”. The
content of the card is stored into a 7x4 bidimensional matrix.
In fact, it gets the response to a requestReadCard() or a requestReadCardWithPass() command that the module
will send, so one of these 2 functions must have been executed before.
Example of use
{
state = RFID125.getCard(seconds, myMatrix); // receives the response to the requestRead-
Card() command.
// If a card was found and read, its content is stored in the
// variable myMatrix, and variable state will be ‘0’.
// If no card was found, variable state will be ‘1’.
}
See example:
www.libelium.com/development/waspmote/examples/rfid125-02-reading-t5557-tags
8.7. Printing the content of a T5557 card
It prints the content of a card via the serial port. Bear in mind a successful getCard() function must have been executed
before in order to get the card information.
Example of use
{
RFID.printCard(myMatrix); // prints the content of a T5557 card via the serial port
}
8.8. Writing data in a block of a T5557 card
It sends to the module the command for writing 4 bytes in one block of a T5557 card. The card must not be protected by
password.
The execution of this function does not ensure that the data was written, but that the module was configured to do so. The user
should manually check the successful write manually, or using the funtion writeBlockAndCheck().
It is not advised to write in blocks 0x00, 0x01, 0x07 unless you are an advanced user. You could leave your card unaccessible.
The data blocks, availble for the user, are from number 0x02 to 0x06, so there are 20 bytes of total capacity in each card. If the
Password Mode is not enabled, the user can write in the block number 0x07 like in any other data block.
-18-
v4.1
Libelium’s API
One execution is needed for each block we want to write.
Example of use
{
uint8_t block = 0x04; // stores the number of block to be written
uint8_t data0 = 0x13; // stores the data we want to write
uint8_t data1 = 0x12;
uint8_t data2 = 0x19;
uint8_t data3 = 0x83;
...
RFID125.writeBlock(block, data0, data1, data2, data3); // writes the code 13121983 (hex) in
the // block 0x04. The card must not be protected by
password.
}
See example:
www.libelium.com/development/waspmote/examples/rfid125-03-reading-and-writing-t5557-tags
8.9. Writing data with password in a block of a T5557 card
It sends to the module the command for writing 4 bytes in one block of a T5557 card. The card is supposed to be protected by
a 4-byte password.
The execution of this function does not ensure that the data was written, but that the module was configured to do so. The user
should manually check the successful write manually, or using the funtion writeBlockAndCheck().
It is not advised to write in blocks 0x00, 0x01, 0x07 unless you are an advanced user. You could leave your card unaccessible.
The data blocks, availble for the user, are from number 0x02 to 0x06, so there are 20 bytes of total capacity in each card. If the
Password Mode is not enabled, the user can write in the block number 0x07 like in any other data block.
One execution is needed for each block we want to write.
Example of use
{
uint8_t block = 0x04; // stores the number of block to be written
uint8_t data0 = 0x13; // stores the data we want to write
uint8_t data1 = 0x12;
uint8_t data2 = 0x19;
uint8_t data3 = 0x83;
uint8_t pass0 = 0xFA; // stores the password of the card
uint8_t pass1 = 0xBA;
uint8_t pass2 = 0xDA;
uint8_t pass3 = 0x11;
...
// writes the code 13121983 in the block number 0x04. The card is supposed to be protected
by
// the password FABADA11 (hex):
RFID125.writeBlockWithPass(block, data0, data1, data2, data3, pass0, pass1, pass2, pass3);
}
-19-
v4.1
Libelium’s API
8.10. Writing data in a block of a T5557 card and checking it
It sends to the module the command for writing 4 bytes in one block of a T5557 card. The card must not be protected by password.
Then the function reads that block and checks that the correct data was written. It is useful to do these 2 steps in just one.
So this function ensures that the data was written successfully, unlike the function writeBlock().
It is not advised to write in blocks 0x00, 0x01, 0x07 unless you are an advanced user. You could leave your card unaccessible.
The data blocks, availble for the user, are from number 0x02 to 0x06, so there are 20 bytes of total capacity in each card. If the
Password Mode is not enabled, the user can write in the block number 0x07 like in any other data block.
One execution is needed for each block we want to write.
Example of use
{
uint8_t block = 0x04; // stores the number of block to be written
uint8_t data0 = 0x13; // stores the data we want to write
uint8_t data1 = 0x12;
uint8_t data2 = 0x19;
uint8_t data3 = 0x83;
uint8_t state = 1; // stores the status of the executed command (0 = success)
...
// writes the code 13121983 (hex) in the block 0x04. The card must not be protected by
// password. If the check operation went well, returns ‘0’, and ‘1’ otherwise:
state = RFID125.writeBlockAndCheck(block, data0, data1, data2, data3);
}
8.11. Writing data with password in a block of a T5557 card and
checking it
It sends to the module the command for writing 4 bytes in one block of a T5557 card. The card is supposed to be protected by a
4-byte password. Then the function reads that block and checks that the correct data was written. It is useful to do these 2 steps
in just one.
So this function ensures that the data was written successfully, unlike the function writeBlockWithPass().
It is not advised to write in blocks 0x00, 0x01, 0x07 unless you are an advanced user. You could leave your card unaccessible.
The data blocks, availble for the user, are from number 0x02 to 0x06, so there are 20 bytes of total capacity in each card. If the
Password Mode is not enabled, the user can write in the block number 0x07 like in any other data block.
One execution is needed for each block we want to write.
Example of use
{
uint8_t block = 0x04; // stores the number of block to be written
uint8_t data0 = 0x13; // stores the data we want to write
uint8_t data1 = 0x12;
uint8_t data2 = 0x19;
uint8_t data3 = 0x83;
uint8_t pass0 = 0xFA; // stores the password of the card
uint8_t pass1 = 0xBA;
uint8_t pass2 = 0xDA;
uint8_t pass3 = 0x11;
...
// writes the code 13121983 in the block number 0x04. The card is supposed to be protected
// by the password FABADA11 (hex). If the check operation went well, returns ‘1’, and ‘0’
// otherwise:
state = RFID125.writeBlockWithPass(block, data0, data1, data2, data3, pass0, pass1,
pass2,pass3);
}
-20-
v4.1
Time of execution of the functions
9. Time of execution of the functions
The following is a list of the time it takes to execute the main functions:
• readSerialNumber(): 1500 ms
• requestReadCard(): 4 ms
• getCard(): 500 ms
• printCard(): 200 ms
• writeBlock(): 2000 ms
• writeBlockAndCheck(): 2500 ms
So a full read of a T5557 card could take around 700 ms and a standard write in a block, 2 seconds.
All the data blocks of a T5557 card can be read in about 10 seconds. This indicates that the maximum read rate is 2 bytes per
second.
-21-
v4.1
Code examples and extended information
10. Code examples and extended information
In the Waspmote Development section you can find complete examples:
http://www.libelium.com/development/waspmote/examples
Example:
/*
* ------ Read EM4100/02 tag --------
*
* Explanation: This sketch looks for EM4100/02 RFID cards. If a tag is
* detected, the module reads its serial number and prints it.
*
* Copyright (C) 2012 Libelium Comunicaciones Distribuidas S.L.
* http://www.libelium.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .

* Version: 0.1
* Design: David Gascon
* Implementation: Marcos Yarza, Javier Solobera
*/
#include <WaspRFID125.h>

// variables declaration:
uint8_t state = 0; // stores the status of the executed command
uint8_t seconds = 2; // seconds to wait for cards
uint8_t serNum0; // stores the 1st byte of the serial number
uint8_t serNum1; // stores the 2nd byte of the serial number
uint8_t serNum2; // stores the 3rd byte of the serial number
uint8_t serNum3; // stores the 4th byte of the serial number

WaspRFID125 testRFID125;


void setup()
{
USB.ON();
delay(200);
USB.println(“RFID @ 125 KHz module started”);
// switchs on the RFID @ 125 KHz module, and asigns the socket
RFID125.ON(SOCKET0);
delay(200);
}

-22-
v4.1
Code examples and extended information
void loop()
{
USB.println(“\n ** new loop ** “);

// search for EM4200 card:
state = RFID125.readSerialNumber(seconds, serNum0, serNum1, serNum2, serNum3);
RFID125.stopRead();
if (state == 1) // if a card was detected
{
USB.print(“\n an EM4100/02 card was found: “);
RFID125.printCardSerialNumber();
}
else
{
USB.println(“\n no card found”);
}
delay(3000);
}
-23-
v4.1
Documentation changelog
11. Documentation changelog
Added references to 3G/GPRS Board in section: Expansion Radio Board