<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Variable Corruption]]></title><description><![CDATA[<p dir="auto">Hello all, fairly new to M5, but have done embedded stuff for a while. I built this using UIFlow2, but also pasting the code below for those who prefer to see it in code.</p>
<p dir="auto"><img src="/assets/uploads/files/1738215176732-screenshot-2025-01-30-at-12.32.17-am.png" alt="Screenshot 2025-01-30 at 12.32.17 AM.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">I have 3 RFID readers hanging off a PAHub. I'm getting the RFID UIDs off the readers and storing them in a variable in the Loop. All good so far. I write them to variables RFIDZERO, RFIDONE and RFIDTWO (I was using other names, but thought it might have been getting confused with the other variable names).</p>
<p dir="auto">Inside the do loops, RFIDZERO and RFIDONE get set to their correct values from the RFID tags. Immediately outside the do loop, I print them again and now, RFIDONE is equal to RFIDZERO's value. No other assignment operators or operation has taken place. WTF?</p>
<pre><code class="language-import">import M5
from M5 import *
from module import Module4In8Out
from hardware import I2C
from hardware import Pin
from unit import PAHUBUnit
from unit import RFIDUnit



module_4in8out_0 = None
i2c0 = None
file_0 = None
pahub_0 = None
rfid_0 = None
rfid_1 = None
rfid_2 = None


RFIDZERO = None
WritingRFIDs = None
RFIDONE = None
RFIDTWO = None


def btnA_wasClicked_event(state):
  global module_4in8out_0, i2c0, file_0, pahub_0, rfid_0, rfid_1, rfid_2, RFIDZERO, WritingRFIDs, RFIDONE, RFIDTWO
  WritingRFIDs = True


def setup():
  global module_4in8out_0, i2c0, file_0, pahub_0, rfid_0, rfid_1, rfid_2, RFIDZERO, WritingRFIDs, RFIDONE, RFIDTWO

  M5.begin()
  Widgets.fillScreen(0x222222)

  BtnA.setCallback(type=BtnA.CB_TYPE.WAS_CLICKED, cb=btnA_wasClicked_event)

  module_4in8out_0 = Module4In8Out(address=0x45)
  i2c0 = I2C(0, scl=Pin(33), sda=Pin(32), freq=100000)
  pahub_0 = PAHUBUnit(i2c=i2c0, channel=0)
  rfid_2 = RFIDUnit(PAHUBUnit(i2c=i2c0, channel=2))
  rfid_1 = RFIDUnit(PAHUBUnit(i2c=i2c0, channel=1))
  rfid_0 = RFIDUnit(PAHUBUnit(i2c=i2c0, channel=0))
  WritingRFIDs = False


def loop():
  global module_4in8out_0, i2c0, file_0, pahub_0, rfid_0, rfid_1, rfid_2, RFIDZERO, WritingRFIDs, RFIDONE, RFIDTWO
  M5.update()
  if not WritingRFIDs:
    if rfid_0.is_new_card_present():
      RFIDZERO = rfid_0.read_card_uid()
      print((str('RFID_0: ') + str(RFIDZERO)))
      rfid_0.close()
    if rfid_1.is_new_card_present():
      RFIDONE = rfid_1.read_card_uid()
      print((str('RFID_1: ') + str(RFIDONE)))
      rfid_1.close()
    if rfid_2.is_new_card_present():
      RFIDTWO = rfid_2.read_card_uid()
      print((str('RFID_2: ') + str(RFIDTWO)))
      rfid_2.close()
    print((str('RFID_0: ') + str(RFIDZERO)))
    print((str('RFID_1: ') + str(RFIDONE)))
    print((str('RFID_2: ') + str(RFIDTWO)))
  else:
    file_0 = open('/flash/rfidtags.txt', 'w')
    file_0.write(RFIDZERO)
    file_0.write('\r\n')
    file_0.write(RFIDONE)
    file_0.close()
    WritingRFIDs = False
    print('Wrote the file')


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")
</code></pre>
]]></description><link>https://community.m5stack.com/topic/7250/variable-corruption</link><generator>RSS for Node</generator><lastBuildDate>Sun, 17 May 2026 16:54:21 GMT</lastBuildDate><atom:link href="https://community.m5stack.com/topic/7250.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 30 Jan 2025 05:33:22 GMT</pubDate><ttl>60</ttl></channel></rss>