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:

RFIDUnit

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:

example.png

rfid_cores3_example.m5f2

class RFIDUnit

Constructors

class RFIDUnit(i2c, address)

Initialize the RFIDUnit with I2C communication and an optional address.

Parameters:
  • i2c – The I2C interface instance.

  • address (int) – The I2C address of the RFIDUnit. Default is 0x28.

UIFLOW2:

init.png

Methods

RFIDUnit.is_new_card_present()

Check if a new RFID card is present.

UIFLOW2:

is_new_card_present.png

RFIDUnit.read_card_uid()

Read the UID of the RFID card if available.

UIFLOW2:

read_card_uid.png

RFIDUnit.read(block_addr)

Read a specific block from the RFID card.

Parameters:

block_addr – The block address to read data from.

UIFLOW2:

read.png

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:

write.png

RFIDUnit.close()

Halt the PICC and stop the encrypted communication session.

UIFLOW2:

close.png

RFIDUnit.wakeup_all()

Wake up all RFID cards within range.

RFIDUnit.picc_select_card()

Select the currently active RFID card.