RFID Unit
RFIDUnit is a hardware module designed for RFID card reading and writing operations. It extends the MFRC522 driver, supporting card detection, reading, writing, and advanced features like selecting and waking up RFID cards.
Support the following products:
Micropython Example:
1# SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD 2# 3# SPDX-License-Identifier: MIT 4 5import os, sys, io 6import M5 7from M5 import * 8from hardware import * 9from unit import RFIDUnit 10import time 11 12 13title0 = None 14i2c0 = None 15rfid_0 = None 16 17 18def setup(): 19 global title0, i2c0, rfid_0 20 21 M5.begin() 22 Widgets.fillScreen(0x222222) 23 title0 = Widgets.Title( 24 "RFIDUnit CoreS3 Example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18 25 ) 26 27 i2c0 = I2C(0, scl=Pin(1), sda=Pin(2), freq=100000) 28 rfid_0 = RFIDUnit(i2c0) 29 30 31def loop(): 32 global title0, i2c0, rfid_0 33 print(rfid_0.is_new_card_present()) 34 print(rfid_0.read_card_uid()) 35 print(rfid_0.read(1)) 36 time.sleep_ms(100) 37 38 39if __name__ == "__main__": 40 try: 41 setup() 42 while True: 43 loop() 44 except (Exception, KeyboardInterrupt) as e: 45 try: 46 from utility import print_error_msg 47 48 print_error_msg(e) 49 except ImportError: 50 print("please update to latest firmware")
UIFLOW2 Example:
class RFIDUnit
Constructors
Methods
- RFIDUnit.is_new_card_present()
Check if a new RFID card is present.
UIFLOW2:
- RFIDUnit.read_card_uid()
Read the UID of the RFID card if available.
UIFLOW2:
- RFIDUnit.read(block_addr)
Read a specific block from the RFID card.
- Parameters:
block_addr – The block address to read data from.
UIFLOW2:
- RFIDUnit.write(block_addr, buffer)
Write data to a specific block on the RFID card.
- Parameters:
block_addr – The block address to write data to.
buffer – The data buffer to write to the block.
UIFLOW2:
- RFIDUnit.close()
Halt the PICC and stop the encrypted communication session.
UIFLOW2:
- RFIDUnit.wakeup_all()
Wake up all RFID cards within range.
- RFIDUnit.picc_select_card()
Select the currently active RFID card.