Grove RFID

I wish to obtain Card ID from the 10 ascii characters output by the grove in uart mode. In the wiki for the older rfid brick there is a note that the card id is contained in the last 4 bytes. Can someone give me an algorithm or some Arduino code to get the id from those 4 bytes.

I assume that you are using the Grove 125 KHz RFID reader, Model SEN11425P.

The module is extremely poorly documented, so don’t feel bad.

In “UART mode” (default) the device transmits ASCII characters, so get out an ASCII chart. Run it via SoftwareSerial at 9600 bps. Be careful if you are using a Mega board, because they have restrictions on the RX pins that SoftwareSerial can use. 10…13, 50…53 are okay.

The ASCII byte sequence from the device is :

1/STX, 2/Prefix, 8/TagNumber, 2/Checksum, 1/ETX.

STX and ETX are ASCII control codes. STX = 02, ETX = 03.

Prefix, TagNumber, and Checksum are each a sequence of characters. They are, unbelievably, the ASCII characters which each display a hex digit. So you must convert them to four-bit integer values (formally called ‘nibbles’, haha) and then pack them into an integer in order to use them.

The Prefix is just two digits – they are not the Tag number, but they aid in uniqueness. The Tag number is what you need – it will be written on the tag or the card. The check digits are marginally useful – I use them, but they waste code.

/***

• convert() - converts ASCII hex characters to 4-bit integer nibbles.
• Returns -1 if fail.
*/

char convert(uint8_t i) {

if (i >= ‘0’ && i <= ‘9’) return (i - ‘0’); // convert 0-9
if (i >= ‘A’ && i <= ‘F’) return (i - ‘A’ + 10); // convert A-F
return -1; // out of range

}

Assemble all the converted digits (say, all the Tag number nibbles) into an integer. Use a ‘uint32_t’ (that is to say, an unsigned long) variable.

uint32_t container = 0;

container = converted_nibble1;
container = (container << 4) | converted_nibble2;
container = (container << 4) | converted_nibble3; …

You may also verify the checksum by doing an XOR tally of every converted nibble except the STX and ETX. It should tally to equal zero.

– I congratulate the vendors for failing to document any of this in any place that I have seen. Just wait until you want to extend their antenna range. Hahah

kt