MicroPython port form M5StickC

  • I'm currently trying to get the LCD running with MicroPython (from https://github.com/m5stack/M5Stack_MicroPython) on the M5StickC. MicroPython is running but the LCD stays dark and I think the issue is the control of the PMIC AXP192 which according to the block diagram controls the chip enable of the LCD and the backlight LED.
    Is there a MicroPython port or module available which controls the AXP192? All examples I found for the M5Stack directly control the LCD without the AXP192.

  • @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.

  • 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

  • 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.

  • @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.

  • 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.

  • 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.

  • 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:

    hope this helps

  • 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

  • @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.

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