M5StickC Plus MicroPython: Use GPIO 25 and 26 for I2C, 36 Floating



  • Hi, I would like to use the GPIO 25 and 26 pins in the header for I2C, so I am setting them up as follows in MicroPython:

    from machine import Pin, I2C
    i2c = I2C(1, scl=Pin(26), sda=Pin(25), freq=400000)

    However, the description says that "G36/G25 share the same port, when one of the pins is used, the other pin should be set as a floating input" and provides the following example

    For example, to use the G36 pin as the ADC input, Configuration the G25 pin as FLOATING
    setup()
    {
    M5.begin();
    pinMode(36, INPUT);
    gpio_pulldown_dis(GPIO_NUM_25);
    gpio_pullup_dis(GPIO_NUM_25);
    }

    It seems that I should set GPIO36 to Floating. How does one do this in MicroPython, and where could one find such settings in the documentation? I have looked for a couple of hours and can't find this anywhere.

    Jack
    PS How do you create a code window on this board?



  • Hello Jack

    you could try the following to make GPIO36 floating:

    p36 = Pin(36, Pin.IN, None)
    

    Please note: I do not own a M5StickC Plus so I've tried above code on a M5Stack Fire. It runs without error.

    That said, I don't think GPIO36 has internal pull-up or pull-down circuitry to begin with since the following code did not change the voltage reading at all:

    p36 = Pin(36, Pin.IN, Pin.PULL_UP)
    

    BTW: When I define a pull-up for let's say GPIO25 the voltage goes up to about 3.2 volts as I would expect.

    For reference: https://docs.micropython.org/en/latest/library/machine.Pin.html

    Cheers
    Felix



  • Excellent, thank you very much Felix. And nice informative site you have there!

    May I ask how you ensure that MPU6886 is off in MicroPython?



  • Hello Jack

    you are welcome and thank you.

    You'll need to check the MPU6886 datasheet

    There is a sleep mode bit (Bit 6) in register 107 (power management 1). When I read that register I get 0x01 which seems to be the default. To put MPU6886 into sleep mode I'd write 0x41 into that register like that:

    import i2c_bus
    i2c0 = i2c_bus.easyI2C(i2c_bus.PORTA, 0x68, freq=400000)
    i2c0.write_u8(107, 0x41)
    

    Thanks
    Felix