Skip to content

Install RFID reader

Wout Slakhorst edited this page Mar 3, 2021 · 18 revisions

UART rfid reader

TODO: scanned HEX is 3A0019FFA874.. ignore 3A, then read 7 bytes!

Connecting pins

I used a rdm6300-rfid-reader-125khz. The VCC of the device is connected to pin 2 (5V) and the GND is connected to pin 9 (GND). RCV is connected to pin 10(BCM15) and TX to pin 8(BCM14) (uart).

Background info on https://www.raspberrypi.org/documentation/configuration/uart.md

Logical converter

A logical voltage converter has to be used to go from 5V to 3.3V. I used this one: https://www.tinytronics.nl/shop/nl/spanning-converters/level-converters/i2c-uart-bi-directionele-logic-level-converter-5v-3.3v-2-kanaals-met-voeding.

Connected as:

  • AVCC connected to 5V on PI

  • ASCL connected to TX on rfid board

  • ASDA connected to RX on rfid board

  • AGND connected to GND on PI

  • BVCC not connected

  • BSCL connected to RX pin on PI

  • BSDA connected to TX pin on PI

  • BGND connected to GND on PI

Configure Pi

UART first has to be enabled via by adding dtoverlay=uart2 to /boot/config.txt.

Testing

https://unix.stackexchange.com/questions/42376/reading-from-serial-from-linux-command-line

Using:

sudo cat /dev/ttyS0

This gives 3A0019EA2EE7 as output while the number should be 0001698350. It seems some bytes do not get printed. I wrote a small program under /serial-test/ which outputs the bytes as they are read:

02 33 41 30 30 31 39 45  41 32 45 45 37 03        |.3A0019EA2EE7.|

According to https://www.mschoeffler.de/2018/01/05/arduino-tutorial-how-to-use-the-rdm630-rdm6300-rfid-reader/ the first 02 is the head byte and simarly 03 is the tail byte. Bytes[1:10] are the data bytes and the remainder two are a checksum. So in the above example

33 41 30 30 31 39 45 41 32 45

is the data of the rfid card. The first two bytes are the version of the tag. The string sequence that corresponds to 30 30 31 39 45 41 32 45 is 0019EA2E which is the hexadecimal value for 1698350.

The checksum value is given by xOr'ing the 'stringified' hex values:

3A0019EA2E
# becomes
3A => 00111010
00 => 00000000
19 => 00011001
EA => 11101010
2E => 00101110
-----
E7 => 11100111

Prototype (old)

The prototype version used a usb reader that identified itself as HID device. Code can be found in the prototype branch.

The cheap RFID reader I got from China doesn't need any installation. It identifies itself as keyboard (HID device). In order to use it, you must find the vendor ID and device ID. When plugged into my Mac I could find it with the lsusb utility. For the raspberry I used the script from https://github.com/balag3/RFID_reader. (added as rfid.py in the repo)

In my case the vendor ID is: ffff and product ID is: 0035

If your vendor and product is different, the code must be altered (sorry, this could be a configuration of course)

Test device

To test the reader, just ssh into the Pi (or use screen and keyboard) and scan a RFID card, it'll output the card number on the screen followed by a newline.

Make HID device accessible

For the software to access a HID device, it must be added to /etc/udev/rules.d. Basically you'll be eavesdropping to keyboard input... There's an example file in this repo called 50-usb-rfid-reader.rules.

Mac curiosity

In the code you'll find that I write 3 bytes back to the device. For some reason when the reader was connected to my Mac it only read the right code the first time after that only garbage comes out. I figured out something somewhere was off (like a single bit or so) so I tried to write stuff back to reset things. Turned out that worked.

Clone this wiki locally