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

    MicroPython port form M5StickC

    M5 Stick/StickC
    3
    11
    22.6k
    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.
    • ajb2k3A
      ajb2k3 @ForestRupicolous
      last edited by

      @forestrupicolous If you use UIFlow firmware 1.4.3 then the screen works fine however it is built on a slightly older version of Micropython.

      UIFlow, so easy an adult can learn it!
      If I don't know it, be patient!
      I've ether not learned it or am too drunk to remember it!
      Author of the WIP UIFlow Handbook!
      M5Black, Go, Stick, Core2, and so much more it cant be fit in here!

      F 1 Reply Last reply Reply Quote 0
      • lukasmaximusL
        lukasmaximus
        last edited by

        I believe @ForestRupicolous is trying to use standard non uiflow micropython firmware. I think you are right in assuming that the axp12 also needs to engage the screen to turn it on. I was talking with John Maloney yesterday who is adding M5Stick support to microblocks (http://microblocks.fun/) and he came across the same issue when implementing support. Although microblocks is not using micropython perhaps he can shed some light on this, I'll check and get back to you

        1 Reply Last reply Reply Quote 0
        • F
          ForestRupicolous
          last edited by ForestRupicolous

          Thank you both for your answers. @lukasmaximus is right I would prefer using the standard micropython firmware. As I wasn't able to find an available python module I took a look at the M5StickC Arduino code (https://github.com/m5stack/M5StickC/edit/master/src/AXP192.cpp) and transferred the parts I needed to python. The available datasheet is just in Chinese but together with the code I got the display enabled.

          Here is my prototype code to enable the display and backlight. Please be aware that I haven't included everything from the cpp file so some functionality is missing:

          from machine import I2C
          i2c = I2C(freq=400000, sda=21, scl=22) #Enable I2C
          i2c.scan()  #Check for devices
              [52, 81, 104] #52 is the adress of AXP192
          
          i2c.writeto_mem(52, 0x28, b'\xcc') #Set TFT and TFT_LED to 3.0V
          i2c.readfrom_mem(52, 0x12, 1) #Read Byte 12
            #returns  b'\x13' = 0b10011 -> DCDC enabled but LDO3/2 disabled
          i2c.writeto_mem(52, 0x12, b'\x1f') # enable LDO3/2 (TFT and TFT_LED)
          
          # other code parts:
          i2c.writeto_mem(52, 0x12, b'\x13') #disable LDO3/2 (TFT and TFT_LED)
          i2c.writeto_mem(52, 0x28, b'\x9c') #Dimm display by reducing the voltage
          

          One important thing is that the register 0x12 is also responsible for powering the ESP32. Thats the reason why just setting the LDO3/2 bits alone isn't enough.

          1 Reply Last reply Reply Quote 0
          • F
            ForestRupicolous @ajb2k3
            last edited by

            @ajb2k3 said in MicroPython port form M5StickC:

            @forestrupicolous If you use UIFlow firmware 1.4.3 then the screen works fine however it is built on a slightly older version of Micropython.

            Hi @ajb2k3, is the source code available somewhere? I wasn't able to find the code for the M5StickC anywhere on github. The only UIFlow code I was able to find (https://github.com/m5stack/UIFlow-Code) has gotten it's last commit in June and I think is missing the M5StickC libraries.

            1 Reply Last reply Reply Quote 1
            • lukasmaximusL
              lukasmaximus
              last edited by

              This project may help in setting up standard micropython on m5stick though its for m5stack https://www.hackster.io/andreas-motzek/execute-logo-on-m5stack-esp32-basic-with-micropython-3713fd the modules used to be transferable from the flash using ampy in older firmware versions but now they are frozen in bytecode and so unextractable.

              1 Reply Last reply Reply Quote 0
              • F
                ForestRupicolous
                last edited by

                Thank you for the link. I got micropython running on the M5StickC but I'm missing some libraries (e.g. AXP, or buttons). When UIFLow is working on top of micropyton I hoped it means that the libraries are available somewhere and can be used/ examined.
                I'm currently working on porting the parts I need from the Arduino M5StickC lib.

                1 Reply Last reply Reply Quote 0
                • lukasmaximusL
                  lukasmaximus
                  last edited by

                  for AXP i'm not so sure if there is a standard micropython library available but buttons are simple. The M5stickC buttons are on gpios 37 = A 39 = B the standard way to implement buttons in micropython is:

                  from machine import Pin
                  btna = Pin(37, Pin.IN)
                  btnb = Pin(39, Pin.IN)
                  
                  #for a simple test we can use the button to turn on the led on pin 10
                  
                  ledpin = Pin(10, Pin.OUT)
                  
                  while True:
                         if btna.value() == 1:
                               ledpin.value(1)
                         else:
                               ledpin.value(0)
                  
                  

                  hope this helps

                  F 1 Reply Last reply Reply Quote 1
                  • lukasmaximusL
                    lukasmaximus
                    last edited by

                    After a little digging (I am currently trying to go fully standard micropython also) I turned up this https://github.com/m5stack/M5StickC/issues/82 a user has ported an axp192 library to micropython https://github.com/karfas/M5StickC-uPy I have not tested yet, but perhaps it will help us

                    1 Reply Last reply Reply Quote 1
                    • F
                      ForestRupicolous @lukasmaximus
                      last edited by

                      @lukasmaximus said in MicroPython port form M5StickC:

                      from machine import Pin
                      btna = Pin(37, Pin.IN)

                      Perfekt, thanks a lot! Thats exactly the piece of code which I needed now.
                      For the link: Thats also very helpful. I didn't took the time to port the complete AXP192 library and just added the commands I needed. I will use his full port. Additionally I have to check his port because of some LCD issues I have.

                      1 Reply Last reply Reply Quote 0
                      • F
                        ForestRupicolous
                        last edited by

                        I now found the documentation about the pins (https://docs.micropython.org/en/latest/esp8266/tutorial/pins.html) and was able to trigger a callback when pressing the big M5 button (btna):

                        #Define Callback:
                        def on_wasPressed(p):
                        print("Button was pressed: ", p)
                        B_M5 = Pin(37, Pin.IN, handler=on_wasPressed, trigger=Pin.IRQ_FALLING, debounce= 500)
                        
                        
                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post