Skip to content

Instantly share code, notes, and snippets.

@mm--
Created July 13, 2015 02:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mm--/472ddc436b60cdfac30b to your computer and use it in GitHub Desktop.
Save mm--/472ddc436b60cdfac30b to your computer and use it in GitHub Desktop.
Raspberry Pi RFID reading for Seeed Studio Mini 125Khz RFID module
# Raspberry Pi RFID reading for Seeed Studio Mini 125Khz RFID module
import serial, operator
rfid = serial.Serial("/dev/ttyAMA0")
rfid.baudrate = 9600
rfid.timeout = 2 # Need a timeout in case we read less than 5 bytes
def verify(data):
"""Check the validation bit (the last one) by XORing the first four bytes."""
ints = map(ord, list(data))
if (len(ints) != 5):
return False
return ints[-1] == reduce(operator.xor, ints[:-1])
def id(data):
"""Print out the hex string for some bytes. Don't include validation byte."""
return "".join("{:02x}".format(ord(c)) for c in list(data)[:-1])
while True:
data = rfid.read(5)
if verify(data):
print "Read ID: ", id(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment