Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    How to set the Pin mode for machine.deepsleep?

    Scheduled Pinned Locked Moved LoPy
    18 Posts 5 Posters 1.2k Views 5 Watching
    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.
    • K Offline
      KenM
      last edited by KenM

      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)

      O 1 Reply Last reply Reply Quote 0
      • O Offline
        oligauc @KenM
        last edited by

        @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

        K 1 Reply Last reply Reply Quote 0
        • K Offline
          KenM
          last edited by KenM

          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)

          rcolisteteR 1 Reply Last reply Reply Quote 0
          • K Offline
            KenM @oligauc
            last edited by KenM

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

            1 Reply Last reply Reply Quote 0
            • rcolisteteR Offline
              rcolistete @KenM
              last edited by

              @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 ?

              My "MicroPython Samples". My "MicroPython Firmwares" with many options (double precision, ulab, etc).

              K 1 Reply Last reply Reply Quote 0
              • K Offline
                KenM @rcolistete
                last edited by

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

                1 Reply Last reply Reply Quote 0
                • K Offline
                  KenM
                  last edited by KenM

                  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)

                  robert-hhR 1 Reply Last reply Reply Quote 0
                  • robert-hhR Offline
                    robert-hh @KenM
                    last edited by

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

                    K 1 Reply Last reply Reply Quote 0
                    • K Offline
                      KenM @robert-hh
                      last edited by KenM

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

                      robert-hhR 1 Reply Last reply Reply Quote 0
                      • robert-hhR Offline
                        robert-hh @KenM
                        last edited by

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

                        K 1 Reply Last reply Reply Quote 0
                        • K Offline
                          KenM @robert-hh
                          last edited by KenM

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

                          robert-hhR 1 Reply Last reply Reply Quote 0
                          • robert-hhR Offline
                            robert-hh @KenM
                            last edited by

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

                            K 1 Reply Last reply Reply Quote 0
                            • K Offline
                              KenM @robert-hh
                              last edited by

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

                              robert-hhR 1 Reply Last reply Reply Quote 0
                              • robert-hhR Offline
                                robert-hh @KenM
                                last edited by robert-hh

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

                                K 1 Reply Last reply Reply Quote 0
                                • K Offline
                                  KenM @robert-hh
                                  last edited by

                                  @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?

                                  robert-hhR 1 Reply Last reply Reply Quote 0
                                  • robert-hhR Offline
                                    robert-hh @KenM
                                    last edited by

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

                                    K 1 Reply Last reply Reply Quote 0
                                    • K Offline
                                      KenM @robert-hh
                                      last edited by

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

                                      J 1 Reply Last reply Reply Quote 0
                                      • J Offline
                                        jcaron @KenM
                                        last edited by

                                        @KenM Welcome to the pin cutters club (https://forum.pycom.io/topic/1673/pysense-pinout-wake-on-pin/19) :-/

                                        1 Reply Last reply Reply Quote 0

                                        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                                        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                                        With your input, this post could be even better 💗

                                        Register Login
                                        • 1 / 1
                                        • First post
                                          Last post

                                        Pycom on Twitter

                                        Pycom