RFID Utils Module

Constants

Module version

def rfid_utils.VER

Version string. Currently '1.0'

Green LED

def rfid_utils.GLED

An instance of pyb.Pin class controlling the green LED of the board.

Red LED

def rfid_utils.RLED

An instance of pyb.Pin class controlling the red LED of the board.

Output Pin

def rfid_utils.OUT

An instance of pyb.Pin class controlling the output (aka LOCKER) pin of the board.

Input Pin

def rfid_utils.IN

An instance of pyb.Pin class for the Input pin of the board. Use the value() method to query the current state.

CardFilter class

A class inherited from dict. Keeps track of the time passed since the entry has been added

Constructor

def __init__(self, lifetime)
  • lifetime - maximum lifetime of an entry (in seconds) after which is is marked for deletion.

Push an item

def append(key)

Perform periodic clean

def clean(self, now)

Removes all entries marked for deletion

  • now - the time of the cleaning operation. Typically you'd pass now=time()

Buzzer class

A helper class used to control the onboard buzzer.

Constructor

def __init__(self):

No parameters (the buzzer pin is hardcoded)

Switch the buzzer on/off

def on(self)
def off(self)

Synchronous Beep (on, then off)

def beeps(self, time_ms=50)

This function blocks the execution flow until completion

  • time_ms - beep duration in milliseconds

Asynchronous beep

async def beep(self, time_ms=50)

This functions allows other tasks to run while it is being executed.

RFID class

Constructor

def __init__(self, gain=rfid.G_33dB, key=None, typ=None, ul=None)

Initialize the MFRC522 hardware with the selected gain (default - 33dB). If the key and typ are provided, the Mifare Classic key and key type ('A' or 'B') are set. If ul is not None, the Ultralight/NTAG password is set.

  • key - bytes/bytearray object of size 6. Ex. (default): \xff\xff\xff\xff\xff\xff
  • typ - integer (rfid.KEY_A or rfid.KEY_B) or 'A' or 'B'.
  • ul - integer or bytes/bytearray object of size 4. Ex. (default): \xff\xff\xff\xff

Read tag data

def read(self, fmt='hU*', key=None, typ=None, ul=None)

This function (re)inits the hardware, scans for a tag and outputs its data according to the fmt.

  • fmt - output data format. Refer to the format description
  • key, typ, ul - optionally override the current Mifare Classic and Ultralight keys.

Write tag data

def write(self, block, data, key=None, typ=None, ul=None, uid=None)

A write to the last discovered tag is attempted. If uid is not None, tag's UID is compared prior to writing to prevent tag swapping.

  • block - tag memory block number (zero-based. Some blocks may be write-protected or have special meaning. be careful)
  • data - bytes/bytearray object of an appropriate size (16 bytes for the Classic tags, 4 bytes for the NTAG/Ultralight tags)
  • key, typ, ul - optionally override the current Mifare Classic and Ultralight keys.

Get / Set the Mifare Classic Value

def value(self, n, delta=None)

If delta==None, tries to read a value block number n from the current tag. In the read succeeds, the value is returned.

If delta is not None, the value of the block number n is incremented (if delta>0) or decremented (if delta<0) by abs(delta). The new value is then returned.

Return value: a tuple (value, address). value is a 32bit unsigned integer, address is an 8bit unsigned integer.

If uid is not None, tag's UID is compared prior to reading/writing to prevent tag swapping.