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

    Cannot write to RFID tag

    Units
    1
    1
    25
    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.
    • R
      Rusticus42
      last edited by Rusticus42

      Hi!

      I experimenting with the RFID 2 unit. Therfore I have connected the RFID Unit to a M5DinMeter.
      I am using UIFlow 2, but I am able to understand the python code as well.

      So far I am able to check if a RFID tag is present on the unit. If so I read the UID.
      Now I want to write some specific values to an adress of the RFID tag, but it fails.

      The return value of the UIFlow Block "write buffer" is always 0.
      I am not shure if I understand the adressing correctly.
      So far I just used the value 1 for adress, expecting to "point" to the first writeable Byte Array.

      I am pretty sure that my code is not very nice, but maybe someone is able to identy the problem.

      Thanks!

      ==============================================================
      import os, sys, io
      import M5
      from M5 import *
      from hardware import I2C
      from hardware import Pin
      from unit import RFIDUnit

      label0 = None
      label1 = None
      label2 = None
      label3 = None
      i2c0 = None
      rfid_0 = None

      int_RfNewCard = None
      ByteARR_UID = None
      ByteArr_RfidGet = None
      i = None
      Byte_UidPart = None
      Str_UID = None
      ByteArr_Buffer = None
      int_RfWriteResult = None

      def setup():
      global label0, label1, label2, label3, i2c0, rfid_0, int_RfNewCard, ByteARR_UID, ByteArr_RfidGet, Byte_UidPart, i, Str_UID, ByteArr_Buffer, int_RfWriteResult

      M5.begin()
      Widgets.fillScreen(0x000000)
      label0 = Widgets.Label("label0", 5, 5, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu18)
      label1 = Widgets.Label("label1", 5, 32, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu18)
      label2 = Widgets.Label("label2", 6, 59, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu18)
      label3 = Widgets.Label("label3", 7, 90, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu18)

      i2c0 = I2C(0, scl=Pin(15), sda=Pin(13), freq=100000)
      rfid_0 = RFIDUnit(i2c0)
      M5.Lcd.setRotation(1)
      Widgets.setRotation(1)
      label0.setVisible(False)
      label1.setVisible(False)
      label2.setVisible(False)
      label3.setVisible(False)

      def loop():
      global label0, label1, label2, label3, i2c0, rfid_0, int_RfNewCard, ByteARR_UID, ByteArr_RfidGet, Byte_UidPart, i, Str_UID, ByteArr_Buffer, int_RfWriteResult
      M5.update()
      int_RfNewCard = rfid_0.is_new_card_present()
      if int_RfNewCard:
      ByteARR_UID = rfid_0.read_card_uid()
      ByteArr_RfidGet = rfid_0.read(2)
      for i in range(1, 5):
      Byte_UidPart = ByteARR_UID[int(i - 1)]
      if i == 1:
      Str_UID = f'{Byte_UidPart:0X}'
      else:
      Str_UID = (str(Str_UID) + str('-'))
      Str_UID = (str(Str_UID) + str((f'{Byte_UidPart:0X}')))
      rfid_0.close()
      if BtnA.wasClicked():
      print('Button')
      if rfid_0.is_new_card_present():
      print(rfid_0.is_new_card_present())
      print(ByteARR_UID)
      print(ByteArr_RfidGet)
      print(Str_UID)
      ByteArr_Buffer = bytearray(16)
      ByteArr_Buffer[0] = 127
      ByteArr_Buffer[1] = 128
      print(ByteArr_Buffer)
      int_RfWriteResult = rfid_0.write(1, ByteArr_Buffer)
      print(int_RfWriteResult)
      rfid_0.close()

      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")

      1 Reply Last reply Reply Quote 0
      • First post
        Last post