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

    AtomS3U USB otg.

    Atom
    atom s3
    1
    2
    90
    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.
    • K
      Krist
      last edited by

      Hello,

      I have the AtomS3U, and have a key module that I can attach to it.

      I have been playing around with UIFlow2 to get a bit a feel of this thing, an managed to do things like change the led colour when the key is pressed, making the led cycle colors etc...

      What I however would like to do is have the AtomS3U emulate a keyboard. It supports usb OTG, so that should be supported. I want to try something simple first: Press the button and output some character to the connected PC.

      I have not found information on how to do this with UIFlow2. Would this need me diving in to micropython or arduino?

      K 1 Reply Last reply Reply Quote 0
      • K
        Krist @Krist
        last edited by

        I tried the following code:

        import os, sys, io
        import M5
        from M5 import *
        from unit import KeyUnit
        from usb.device.keyboard import Keyboard 
        from usb.device.hid import KeyCode
        
        
        
        keyboard = None
        key_0 = None
        
        
        def key_0_wasClicked_event(state):
          global keyboard, key_0
          keyboard.set_keys(KeyCode.A, 0, 0, 0, 0, 0)
        
        
        def setup():
          global keyboard, key_0
        
          M5.begin()
          keyboard = Keyboard()
          key_0 = KeyUnit((1, 2))
          key_0.setCallback(type=key_0.CB_TYPE.WAS_CLICKED, cb=key_0_wasClicked_event)
        
        
        def loop():
          global keyboard, key_0
          M5.update()
          key_0.tick(None)
        
        
        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")
        

        And I got the following error:

        Traceback (most recent call last):
          File "main.py", line 5, in <module>
        ImportError: no module named 'usb'
        

        So the usb module is not present in the firmware.

        • Is that on purpose, or is this a bug?
        • Is there a way to add the library?
        1 Reply Last reply Reply Quote 0
        • First post
          Last post