🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    M5Dial RFID not working in UIFlow 2.0

    Scheduled Pinned Locked Moved Bug Report
    2 Posts 2 Posters 2.2k Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • L Offline
      LittleBit670
      last edited by

      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.

      1 Reply Last reply Reply Quote 0
      • felmueF Offline
        felmue
        last edited by

        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

        GPIO translation table M5Stack / M5Core2
        Information about various M5Stack products.
        Code examples

        1 Reply Last reply Reply Quote 0

        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

        With your input, this post could be even better 💗

        Register Login
        • First post
          Last post