pi-rfid-jukebox/tag-reader.py
Annika Backstrom e5c4923609 tag-reader: update to pi-rc522 2.1
This version of pi-rc522 gives us a wait_for_tag() method,
greatly reducing CPU usage.
2017-04-08 01:55:34 +00:00

30 lines
528 B
Python

from pirc522 import RFID
import RPi.GPIO as GPIO
import sys
import signal
GPIO.setwarnings(False)
rdr = RFID()
def sigint_handler(signal, frame):
rdr.cleanup()
sys.exit(0)
signal.signal(signal.SIGINT, sigint_handler)
signal.signal(signal.SIGTERM, sigint_handler)
while True:
rdr.wait_for_tag()
(error, tag_type) = rdr.request()
if not error:
(error, uid) = rdr.anticoll()
if not error:
tag_id = ''.join(hex(x)[2:].zfill(2) for x in uid)
print(tag_id)
sys.stdout.flush()
rdr.cleanup()