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

    EXT.IO Unit ERROR problem

    Units
    ext.io import unit
    3
    4
    8.2k
    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.
    • S
      samjami
      last edited by

      I have spent several hours trying to use an Extend IO Unit with M5Stack Fire (and also tried an M5Stack Grey) but when running any simple UIFlow code including the 'EXT.IO Unit' I get the error below. It looks like there is a bug in the 'import unit' library or am I missing something!
      Can someone please point me in the right direction?

      Python code:
      from m5stack import *
      from m5ui import *
      from uiflow import *
      import unit

      setScreenColor(0x222222)
      ext_io0 = unit.get(unit.EXT_IO, unit.PORTA)

      Error on M5Stack display:
      ERROR
      local variable referenced before assignment

      Details:
      File "<string>", line 7, in <module>
      File "unit.py", line 97, in get
      File "<string>", line 1, in <module>
      File "units/_ext_io.py", line 20 in init
      File "units/_ext_io.py", line 25 in _available

      B 1 Reply Last reply Reply Quote 0
      • m5stackM
        m5stack
        last edited by

        thank you feedback. we will fix this bug as soon as possible

        1 Reply Last reply Reply Quote 0
        • B
          berkninan @samjami
          last edited by

          @samjami said in EXT.IO Unit ERROR problem:

          ERROR
          local variable referenced before assignment

          @samjami said in EXT.IO Unit ERROR problem:

          I have spent several hours trying to use an Extend IO Unit with M5Stack Fire (and also tried an M5Stack Grey) but when running any simple UIFlow code including the 'EXT.IO Unit' I get the error below. It looks like there is a bug in the 'import unit' library or am I missing something!
          Can someone please point me in the right direction?

          Python code:
          from m5stack import *
          from m5ui import *
          from uiflow import *
          import unit

          setScreenColor(0x222222)
          ext_io0 = unit.get(unit.EXT_IO, unit.PORTA)

          Error on M5Stack display:
          ERROR
          local variable referenced before assignment

          Details:
          File "<string>", line 7, in <module>
          File "unit.py", line 97, in get
          File "<string>", line 1, in <module>
          File "units/_ext_io.py", line 20 in init
          File "units/_ext_io.py", line 25 in _available

          The Unboundlocalerror: local variable referenced before assignment is raised when you try to use a variable before it has been assigned in the local context. Python doesn't have variable declarations , so it has to figure out the scope of variables itself. It does so by a simple rule: If there is an assignment to a variable inside a function, that variable is considered local . To solve this problem, you can explicitly say it's a global by putting global declaration in your function. The global statement does not have to be at the beginning of the function definition, but that is where it is usually placed. Wherever it is placed, the global declaration makes a variable to global variable everywhere in the function.

          1 Reply Last reply Reply Quote 0
          • m5stackM
            m5stack
            last edited by m5stack

            this bug has been fixed.

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