Created
July 13, 2015 02:29
-
-
Save mm--/472ddc436b60cdfac30b to your computer and use it in GitHub Desktop.
Raspberry Pi RFID reading for Seeed Studio Mini 125Khz RFID module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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