Seeed-Studio / RFID_Library

125Khz RFID library for Arduino
MIT License
60 stars 29 forks source link

Library does not interpret the data correctly? #10

Open ploetner opened 6 years ago

ploetner commented 6 years ago

This library does not seem to work with the latest Seed-Studio Grove RFID readers - those seem to transmit 10 ASCII characters, but the one in this library seems to only support 4 or 5, unless I'm misunderstanding. I could not get the validation to ever validate the checksum, until I did some pretty massive modifications to get it to store 14 characters total (start byte 0x02, 10 ASCII characters, 2 checksum characters, end byte 0x03), rather than just 5, and did all sorts of HEX to ASCII conversion and vice versa. I also had to strip out extra characters before and after the 0x02 start and 0x03 end bytes - don't know what causes these but maybe power up or power down of the unit.

dbvcode commented 3 years ago

@ploetner what did you do? I recently bought Mini 125Khz RFID Module(https://www.seeedstudio.com/Mini-125Khz-RFID-Module-Pre-Soldered-Antenna-35mm-Reading-Distanc-p-1722.html) And this one does not work as it's bigger brother.

tcorbat commented 3 years ago

I encountered the same problem as @ploetner. I think the library expects the sensor to send the number of the RFID tag encoded in 32 bits plus a checksum. However, my reader (I think it is this one [1]) sends the number encoded in ASCII values. The data is transmitted as follows:

The start and end tag are transmitted as the ascii values 2 (0000 0010) and 3 (0000 0011). The other characters are hex values encoded in ascii ('0'-'9'/'A'-'F'). As far as I know, the decimal value of the tag number is transmitted as hex number encoded in ascii values. My tag with the number 0004987985 is read and transmitted via UART as follows:

2   -> STX
30  -> 0
34  -> 4
30  -> 0
30  -> 0
34  -> 4
43  -> C
31  -> 1
43  -> C
35  -> 5
31  -> 1
30  -> 0
35  -> 5
3   -> ETX

0004987985 in hex is 004C1C51, which corresponds to the eight characters in the middle. The checksum is calculated by xor-ing the the five pairs of characters from the version number and tag number:

04 -> 0000 0100
00 -> 0000 0000 (XOR)
4C -> 0100 1010 (XOR)
1C -> 0001 1010 (XOR)
51 -> 0101 0001 (XOR)
------------------
05 -> 0000 0101

I guess the format transmitted by the reader changed, as the library seems to be doing about the same, but for a different input format.

[1] https://www.seeedstudio.com/Grove-125KHz-RFID-Reader.html [2] https://www.priority1design.com.au/em4100_protocol.html