GrovePi + Grove - 125KHz RFID Reader + Python

Perhaps use this to get rid of the trailing “x03”:

print(“RFID Info without first and last byte:{}:”.format(rng[1:-1]))

1 Like

Please post the info here for the next tortured soul that tries this feat you have succeeded with.

1 Like

Of course! :slight_smile:

GrovePi+ - Grove RFID (125kHz) Reader - Raspberry Pi 4 - Step by Step

  1. Setting up the Software (check this)

  2. Enable UART by editing the config.txt (The jumper on the reader has to be on the left side!)

sudo nano /boot/config.txt

Add this line at the end of the file

enable_uart=1
  1. Configure the serialport with raspi-config
sudo raspi-config
  • Interface Options
  • P6 Serial Port
  • Would you like a login shell to be accessible over serial? → No
  • Would you like the serial port hardware to be enabled? → Yes
  • Finish
  1. Create a Python-File to read the RFID-Tags in a while loop
sudo nano /home/pi/Dexter/GrovePi/Software/Python/rfid_read.py

Paste this code and save the file

#!/usr/bin/env python3

# FILE: rfid_read.py

# USAGE:  sudo python3 rfid_read.py 

# REFERENCES:  
#  Serial API: https://pyserial.readthedocs.io/en/latest/pyserial_api.html
#  Grove RFID Sensor: https://wiki.seeedstudio.com/Grove-125KHz_RFID_Reader/

import serial
import time

rpiser = serial.Serial("/dev/ttyS0", 9600, timeout=1)
rpiser.flush()

while True:
    print("active, waiting...")

    # wait until first byte is seen in the serial stream
    while rpiser.in_waiting == 0:        # note that in_waiting is a property in Python3
        time.sleep(0.005)        

    # Bytes coming in!  Wait until the 1s timeout to get them all
    time.sleep(1.0)
    bytes_available = rpiser.in_waiting    
    print("Tag Detected with {} bytes ready".format(bytes_available))
    rfid = rpiser.read(bytes_available)
    print("RFID Info:{}:".format(rfid))
    print("RFID Info without first and last byte:{}:".format(rfid[1:-1]))

Now let’s start the script

sudo python3 /home/pi/Dexter/GrovePi/Software/Python/rfid_read.py
  1. Your result should look like this
pi@raspberrypi:~/Dexter/GrovePi/Software/Python $ sudo python3 rfid_new2.py 
active, waiting...
Tag Detected with 14 bytes ready
RFID Info:b'\x02380040B539F4\x03':
RFID Info without first and last byte:b'380040B539F4':
active, waiting...

I’m very thankfull for the help of @cyclicalobsessive !!
I hope this will help in future!

2 Likes

For those of you who have never dealt with Wiegand access control cards, a Wiegand card is a plastic card, about the same size as a credit card, that has two rows of metal pins across the bottom of the card. One row is the “bit” row and the other row is the “clock” row. The presence of a metal pin in the bit row indicates a “1” and the absence of a pin indicates a “0”

A Wiegand reader has four wires: +5, ground, data, and clock - which are driven low when an associated pin is read within the card.

Here are two interesting articles, one on the interface itself and the other on the Wiegand effect.

 

I used to work with the “original” swipe-type Wiegand cards in the middle 90’s when I was working for a big access control system manufacturer on Long Island.

The readers had a distinctive shape and were potted with what can only be described as kryptonite (:wink:) because it required an atomic blast to remove it. (And yes, I tried.)

2 Likes

Interesting factoid:

Back when I was working with access control systems I was told that the Wiegand interface had two signal lines:

  1. A “1” bit line
  2. A “0” bit line

And depending on which row on the card had a wire, either the “1” or “0” line would toggle.

Today while I was researching this, I found a site that claimed that a Wiegand card had one row of wires for data and the second row was a “clock” row, with all bit positions occupied to generate a coherent clock for the data.

“Hmmm. . .” I thought. “That’s not the way I remember it, but who knows, that that was a long time ago. And who knows, I could be loosing my grip.”

Turns out that when I read the physical interface part of the Wikipedia article on Wiegand, they mentioned two things:

  1. The canonical version of the Wiegand interface and card design had two data rows, one for the “1” bit and the other for the “0” bit, (like I remembered), and the two data lines were the “1” and “0” data bit lines.

— AND —

  1. Because of the physical data limits of a Wiegand card, (only a limited number of bits could be programmed into the card before data integrity issues raised their ugly head), other formats were created to try to overcome this limitation.

Maybe I’m not loosing my mind after all?
:wink:

1 Like