M5Dial RFID not working in UIFlow 2.0
-
I was making a simple program that should be able to pair to an NFC/RFID card using its UID and then be able to compare the saved UID against another scanned card's UID.
This is the Python code output from UIFlow:
import os, sys, io import M5 from M5 import * from hardware import * import time mode = None status = None rfid = None savedcard = None # Describe this function... def pair(): global savedcard, mode, status, rfid Speaker.tone(3500, 50) Widgets.fillScreen(0xff6600) mode.setText(str('Setup Mode')) status.setText(str('Scan tag to pair')) while not (rfid.is_new_card_present()): continue savedcard = rfid.read_card_uid() status.setText(str(str((rfid.read_card_uid())))) time.sleep(1) Speaker.tone(3500, 50) reset() # Describe this function... def active(): global savedcard, mode, status, rfid Widgets.fillScreen(0x666666) if savedcard == None: mode.setText(str('Active Mode')) status.setText(str('No tag paired')) time.sleep(1) pair() else: mode.setText(str('Active Mode')) status.setText(str('Waiting for tag')) while not (rfid.is_new_card_present()): pass if (rfid.read_card_uid()) == savedcard: Widgets.fillScreen(0x33cc00) status.setText(str('Access granted')) Speaker.tone(3500, 50) time.sleep(1) else: Widgets.fillScreen(0xcc0000) status.setText(str('Access denied')) for count in range(3): Speaker.tone(3500, 50) time.sleep_ms(60) time.sleep(1) reset() # Describe this function... def reset(): global savedcard, mode, status, rfid Widgets.fillScreen(0x000000) mode.setText(str('Idle')) status.setText(str('Click to wake')) def btnA_wasClicked_event(state): global mode, status, rfid, savedcard active() def btnA_wasHold_event(state): global mode, status, rfid, savedcard pair() def setup(): global mode, status, rfid, savedcard rfid = RFID() M5.begin() mode = Widgets.Label("[mode]", 36, 87, 1.0, 0xffffff, 0x000000, Widgets.FONTS.DejaVu18) status = Widgets.Label("[status]", 35, 122, 1.0, 0xffffff, 0x000000, Widgets.FONTS.DejaVu18) BtnA.setCallback(type=BtnA.CB_TYPE.WAS_CLICKED, cb=btnA_wasClicked_event) BtnA.setCallback(type=BtnA.CB_TYPE.WAS_HOLD, cb=btnA_wasHold_event) reset() Speaker.setVolumePercentage(1) def loop(): global mode, status, rfid, savedcard M5.update() if __name__ == '__main__': try: setup() while True: loop() except (Exception, KeyboardInterrupt) as e: try: from utility import print_error_msg print_error_msg(e) except ImportError: print("please update to latest firmware")
When I hold the button to enter Setup Mode and scan a tag, the output of the UID read always comes out as "None" meaning nothing's there. I don't know why this is happening, so this is why I'm sending this as a bug report.
-
Hello @LittleBit670
I think reading the UUID twice in a short time could be the issue. Try changing below line:
# status.setText(str(str((rfid.read_card_uid())))) status.setText(str(savedcard))
Thanks
Felix