Skip to content

Commit d363b93

Browse files
committed
Added device driver file providing basic functionality for reading RFID tags using Priority 1 Design Micro RFID module
1 parent 24df48a commit d363b93

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

devices/uRFID.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from pyb import UART
2+
from time import sleep
3+
4+
class uRFID:
5+
# Class for using the Priority 1 Design Micro RFID module to read FDX-B tags.
6+
# http://www.priority1design.com.au/rfid_reader_modules.html
7+
8+
def __init__(self, port):
9+
self.uart = UART(port.UART)
10+
self.uart.init(baudrate=9600, bits=8, parity=None, stop=1, timeout=1)
11+
self.uart.write(b'ST2\r') # Put reader in FDX-B tag mode.
12+
sleep(0.01)
13+
self.uart.read() # Clear input buffer.
14+
15+
def read_tag(self):
16+
# Return the ID of the most recent tag read, if no tag has been read return None.
17+
read_bytes = self.uart.read()
18+
if not read_bytes:
19+
return
20+
try:
21+
ID = int(read_bytes[-13:-1])
22+
return ID
23+
except ValueError:
24+
return

0 commit comments

Comments
 (0)