How to power M5Core2 from module?

  • How can I power my M5 Core2 from Servo2 module?

    @felmue wrote in "Core2 portable CO₂ sensor" that one could run "M5.Axp.SetBusPowerMode(1);" but how do I do this in UIFlow or Micropython?

  • Hello @Ove

    what M5.Axp.SetBusPowerMode(1) is doing can be done in Python like this:

    import i2c_bus
    data = None
    i2c0 = i2c_bus.easyI2C((21, 22), 0x34, freq=400000)
    data = i2c0.read_u8(0x10)
    data = (data & (~ (0x01 << 2)))
    i2c0.write_mem_data(0x10, data, i2c_bus.UINT8LE)
    data = i2c0.read_u8(0x90)
    data = data | 0x07
    i2c0.write_mem_data(0x90, data, i2c_bus.UINT8LE)

    however with UIFlow that doesn't work as the initial UIFlow code disables powering from external 5 volts during its regular boot process. That means when powering M5Core2 from external 5 volts only, it start to boot but then cuts itself of its 5 volts power and shuts down again. So unless there is a way to prevent the regular UIFlow boot process from doing that I am afraid that is a non starter.

    (You can still test above code with UIFlow: power M5Core2 via USB, execute above code, then apply external 5 volts and then remove USB. M5Core2 should stay powered on. If you do the same steps but without running above code M5Core2 will shutdown when you unplug USB.)

    If using MicroPython is any better in that regard I don't know. Sorry.


  • Thanks for the code @felmue!

    I have updated my Servo2 custom block with a new "Servo2 enable external power" block... and it can be found here:

  • Hello @Ove

    while I am not using UIFlow or MicroPython for my projects myself I am sure your custom blocks will make many people happy. Nicely done!


  • It didn't work for me as well using PLC-M12 module, but I fixed it!

    I found the code change of SetBusPowerMode() @felmue wrote, which did not work for my new core2 modules.
    Dug into the datasheet and found GPIO0 connected to VBUSENABLE must be 0V.
    In the code below the GPIO0 is set to open drain output(=pull down only) and set to Low=0V.

    I've changed the AXP192.cpp file directly in C:\Users\user\OneDrive\Documents\Arduino\libraries\M5Core2\src
    To make it work. Good luck.

    // Select source for BUS_5V
    // 0 : use internal boost
    // 1 : powered externally
    void AXP192::SetBusPowerMode(uint8_t state)
        uint8_t data;
        if (state == 0)
            // Set GPIO to 3.3V (LDO OUTPUT mode)
            data = Read8bit(0x91);
            Write1Byte(0x91, (data & 0x0F) | 0xF0);
            // Set GPIO0 to LDO OUTPUT, pullup N_VBUSEN to disable VBUS supply from BUS_5V
            data = Read8bit(0x90);
            Write1Byte(0x90, (data & 0xF8) | 0x02);
            // Set EXTEN to enable 5v boost
            data = Read8bit(0x10);
            Write1Byte(0x10, data | 0x04);
            // Set EXTEN to disable 5v boost
            data = Read8bit(0x10);
            Write1Byte(0x10, data & ~0x04);		
            // Set GPIO0 to low, enabling VBUS supply from BUS_5V
    	// GPIO0 open drain output
            data = Read8bit(0x90);
    	Write1Byte(0x90, (data & 0xF8));
    	// set GPIO0 to 0

  • Hello @Elektron

    good find, thank you for sharing.

    It is interesting that in your case the 10k pull-down resistor already in place on N_VBUSEN wasn't strong enough (with GPIO0 set to float) and you had to configure GPIO0 to pull that line low actively. Makes me wonder if something has changed electrically inside (newer) M5Core2?

    Happy Stacking!