How to set the Pin mode for machine.deepsleep?



  • How to set the Pin mode for machine.deepsleep? (lopy4)

    I need P20 not to drain current, it's pulled up external (with resistor + led)

    I tried:
    machine.pin_sleep_wakeup(['P20'], mode=machine.WAKEUP_ALL_LOW, enable_pull=False)
    I don't need it to wake up but don't know how else to set the default pin mode for deepsleep, the problem is it wakes up or drains current with this command.

    Pycom MicroPython 1.20.1.r1 [v1.11-3138a13] on 2019-10-08; LoPy4 with ESP32
    Pybytes Version: 1.1.3

    One more thing it's plugged in the unknown extensionboard. (v3.1)





  • @robert-hh
    I did cut the connection of P20 to the expansion board but kept the connection of P20 to my board, and it work perfect now :)

    I will need to check if I lost some functionality of the expansion board.

    All wasted time, because pycom refuses to give the schematic of the expansion board...

    Thanks for doing some compare tests.



  • @KenM I use 1.20.1r1, but a homebrew extension board, with absolute no connection to P20 or P10, unless I wire some.



  • @robert-hh
    That good news and bad news
    You used this code above with the same firmware version like mine on a lopy4 on an extension board?



  • @KenM I made a test myself, using a 1k resistor between 3.3V and P20:

    • after boot: 78µA
    • When set to OUT, value=1: 5.2 µA
    • when set to OUT, value = 0: 3.2 mA
    • When set to IN: 0 µA

    In any IN/OUT/value setting: Current during deepsleep: 0 µA.
    I tested also P10. Same behavior.
    So there may be some other reason.



  • @robert-hh
    It's sinking to ground through the external led/diode from 3.3V so there is only one direction possible.



  • @KenM Cyn you tell which direction is the current flow of P20 is?



  • @robert-hh
    I can change the board to source it instead of drain it but I was hoping this could be fixed in software, my I2C pins with external pull-ups don't draw current.
    As test I tried to init P20 as part of the I2C but that didn't change the behavior of P20. (same for P19)



  • @KenM In that case you most probably have an problem in the circuitry. Do you have the choice to connect the LED to GND instead of 3.3v. I'm suspecting a current through the ESD protection diodes, when during deepsleep the I/O circuitry is switched off. Whether that works for you final set-up, is another story.



  • @robert-hh
    Changed the code to

    from machine import Pin
    RelayPin=Pin('P20', mode=Pin.IN)
    

    Didn't change it, well, P20 is always draining current now, not only in machine.sleep and machine.deepsleep.



  • @KenM My best experience with going to sleep is by setting pins, which drive external loads, to input mode before going to deep_sleep. Then it is guaranteed to be in high impedance state. Unless of course you need it to drive something, which of course then consumes power.



  • if you want some code, this is the main.py (boot.py is empty)

    from machine import I2C
    import time
    import machine
    
    #check for dual sensor
    i2cCH1 = I2C(0, I2C.MASTER, baudrate=100000, pins=('P9','P10')) 
    i2cCH2 = I2C(1, I2C.MASTER, baudrate=100000, pins=('P22','P21'))
    
    from machine import Pin
    RelayPin=Pin('P20', mode=Pin.OUT, pull=None)
    RelayPin.value(1)
    # RelayPin.hold(True)
    
    # machine.pin_sleep_wakeup(['P20'], mode=machine.WAKEUP_ALL_LOW, enable_pull=False)
    
    time.sleep_ms(2000)
    
    print('\nSeconds Power ON: ' + str(time.ticks_ms()/1000))
    
    if time.ticks_ms()/1000 < 120:  # stop loop after 2 min.
        print('start sleep' )
        time.sleep_ms(5000)  # current drop
        print('start machine sleep')
        machine.sleep(10000) # current drop lower
        print('start machine deepsleep')
        machine.deepsleep(12000) # current drop lowest
    

    P20 -- 180 ohm -- led -- 3.3V (but P20 is pulled low also if not connected to anything)



  • @rcolistete
    LoPy4 + Expansion Board v3.1, Yes
    With battery (otherwise it wouldn't go to deepsleep)
    No USB plugged in.



  • @KenM said in How to set the Pin mode for machine.deepsleep?:

    When I use 'Hold' P20 doesn't drain current in deepsleep() but the Lopy4 is then using 33mA, so that is not an acceptable deepsleep.

    You are using LoPy4 + Expansion Board v3.1, right ?

    How are you powering this kit ? With USB cable ? Or battery ?



  • @oligauc
    But I don't want to use that pin in deepsleep, I want P20 to do nothing, I only use P20 when the Lopy4 is awake but it is keeps pulling low when I activate deepsleep.



  • When I use 'Hold' P20 doesn't drain current in deepsleep() but the Lopy4 is then using 33mA, so that is not an acceptable deepsleep.

    from machine import Pin
    RelayPin=Pin('P20', mode=Pin.OUT, pull=None)
    RelayPin.value(1)
    RelayPin.hold(True)



  • @KenM When you put the device in deepsleep only the RTC IO pins can be used. Pin 20 is not an RTC IO. Please look at the lopy pinout diagram


Log in to reply
 

Pycom on Twitter