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

    Deepsleep hangs system

    Scheduled Pinned Locked Moved Discussion
    17 Posts 5 Posters 978 Views 6 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.
    • robert-hhR Offline
      robert-hh @Arno
      last edited by

      @Arno The code you post seems incomplete. At least the last line looks strange.

      M 1 Reply Last reply Reply Quote 1
      • C Offline
        crumble @Arno
        last edited by

        @Arno

        I noticed two problems with deepsleep over the PIC. i2c can fail or the board never goes to sleep, so it will not wake up. I assume it is as well a communication problem between ESP and PIC, but without an exception.

        The internal watchdog can get you out of both states. Deepsleep works best with latest firmware versions. Some report that other stuff may not work, so you have to try that for your own configuration.

        Please add beside the missing source part the the firmware versions of LoPy and PIC.

        1 Reply Last reply Reply Quote 0
        • A Offline
          Arno
          last edited by

          Hi My Lopy firmware version is 1.15.0.b1.
          the firmware version of the 3.1 board is:0.0.11 (the latest version
          I add the complete code of which most is commented out. In this shape the code just sets up OTAA connection not more.

          # main.py -- put your code here!!
          import machine
          from network import WLAN
          from network import LoRa
          from machine import Pin, Timer, UART, PWM, I2C
          from deepsleep import DeepSleep
          import deepsleep
          import struct
          import binascii
          import socket
          import pycom
          import time
          import _thread
          import utime
          import array
          
          # Turn off hearbeat LED
          pycom.heartbeat(False)
          ds = DeepSleep()
          
          """i2c = I2C(0, pins=(Pin.module.P21, Pin.module.P20)) # SCL=A8, SDA=C9
          print(i2c.scan())
          
          import at24c32n
          eeprom = at24c32n.AT24C32N(i2c)
          # 80 == 0x50 == AT24C32N EEPROM
          # 104 == 0x68 == DS1307
          
          import ds1307
          dst = ds1307.DS1307(i2c)
          print(dst.datetime())
          dst.halt(False) """
          
          
          
          
          
          off = 0x000000
          red = 0xff0000
          green = 0x00ff00
          blue = 0x0000ff
          pycom.rgbled(0xf0000f)
          
          
          # wake up the unit with P17 or P18
          ds.enable_pullups('P17')
          ds.enable_pullups('P18')
          # get the wake reason and the value of the pins during wake up
          pycom.rgbled(green)
          time.sleep(3.0)
          wake_s = ds.get_wake_status()
          # print(wake_s)
          # ds.enable_wake_on_raise('P10')
          # ds.enable_wake_on_fall('P17')
          # ds.enable_wake_on_fall('P18')
          
          # ds.go_to_sleep(10)  # go to sleep for 10 seconds
          # if wake_s["P10"] == 1 : sys.exit()
          
          # print("P17= ", wake_s["P17"],"  P18= ",wake_s["P18"])
          
          # print(ds.get_wake_status())
          
          
          
          
          
          
          timing1 = [[0,-1],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]]
          # define intermediate array to store time of entry, could be one dimensional
          timing2 = [[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]]
          
          
          """to be used with switch pulling to ground
          p_in_G30 = Pin(Pin.exp_board.G30, mode=Pin.IN, pull=Pin.PULL_UP)
          p_in_G31 = Pin(Pin.exp_board.G31, mode=Pin.IN, pull=Pin.PULL_UP)
          """
          #if wake_s['wake'] == deepsleep.PIN_WAKE:
              #retreive timing1 and 2 from EEPROM
          """ str1 = eeprom.read(0,245)
              str1 = str1.decode('ascii')
              l_str1 = str1.find("]]")+2
              timing1 = list(eval(str1[0:l_str1]))
          
              str2 = eeprom.read(250,500)
              str2 = str2.decode('ascii')
              l_str2 = str2.find("]]")+2
              timing2 = list(eval(str2[0:l_str2]))
              i1 = timing1[0][1]
          
              i2 = timing1[1][1]
              # here needs to be a while loop
              print(timing1)
              print(timing2)
              print("----------------------")
              # i1 = number of ows inside the box
              #timing1  contains the time stamp of the latest passage related to the number of ows inside the box
              # timing2 contains the reside time and number of passages for 1,2,3.. ows in box
              #timing2 is the array to be transmitted
          
               Not needed anymore as we set datetime to 0 at end of routing
              for i in range(0,len(timing2)):
                  timing1[i][0] = dst.datetime()[5]*60 + dst.datetime()[6]
              time1 = dst.datetime()[5]*60 + dst.datetime()[6]
          
          
          
              # while dst.datetime()[5]*60 + dst.datetime()[6] < 20:
              # while i2 < 6:
              time1 = dst.datetime()[5]*60 + dst.datetime()[6] """
          """    if wake_s["P17"] == 0: # so pin pulled to zero
                  #chrono.start()
                  i1 += 1
          
                  pycom.rgbled(blue)
          
          
              if wake_s["P18"] == 0: #so pin pulled to zero
                  #chrono.stop()
                  pycom.rgbled(red)
          
                  ds.go_to_sleep(10) """
          
          
          
          
          """
          elif wake_s['wake'] == deepsleep.TIMER_WAKE:
          
              print("time expired")
          
              pycom.rgbled(off) """
          
          """
              #   write to SD card
              f = open('/sd/test.txt', 'a')
              f.write(' '.join(str(s) for s in timing2) + '\n')
              f.close()
              f = open('/sd/test.txt', 'r')
              print('outcome is:')
              print(f.readall())
              f.close()
          
          
              b = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
              for i in range(0,len(timing2)-1,1):
                   eerste element opdelen in 2 bytes door //256 en % 256
                  b[i*3] = timing2[i][0] // 256
                  b[i*3+1] = timing2[i][0] % 256
                  b[i*3+2] = timing2[i][1]
          
              l_b = 0
              for i in range(0,len(b),1):
                  if b[i] != 0: l_b = i
          
              B1 = bytes(array.array('B',b[0:l_b+1])) """
          """
              B1 = hex(10)
              lora = LoRa(mode=LoRa.LORAWAN)
              lora.nvram_restore()
              s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
              s.setsockopt(socket.SOL_LORA, socket.SO_DR, 5)
              s.setblocking(True)
              if lora.has_joined:
                  print(lora.has_joined())
                  print(B1)
                  s.send(B1)
              else:
                  # Initialize LoRaWAN radio
                  lora = LoRa(mode=LoRa.LORAWAN)
                  print(binascii.hexlify(lora.mac()).upper().decode('utf-8'))
                  # Set network keys
                  dev_eui = binascii.unhexlify('00D85D973D86EE6F')
                  app_eui = binascii.unhexlify('70B3D57ED000A657')
                  app_key = binascii.unhexlify('4317A37691B9333FC62842FEBADE5F78')
          
                  # Join the network
                  lora.join(activation=LoRa.OTAA, auth=(dev_eui, app_eui, app_key), timeout=0)
                  while not lora.has_joined():
                      print('Not joined yet...')
                      pycom.rgbled(off)
                      time.sleep(1.0)
                      pycom.rgbled(red)
                      time.sleep(1.0)
          
                  print('Joined')
                  pycom.rgbled(blue)
                  print(app_eui)
                  s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
                  s.setsockopt(socket.SOL_LORA, socket.SO_DR, 5)
                  s.setblocking(True)
                  s.send(B1)
          
          
          
              lora.nvram_save()
              # go to sleep for 1800 second = 0.5 hour
              ds.go_to_sleep(28)
          
          
          else:  # deepsleep.POWER_ON_WAKE:
              print("Power ON reset")
          """
          lora = LoRa(mode=LoRa.LORAWAN)
          if not lora.has_joined():
              lora = LoRa(mode=LoRa.LORAWAN)
              print(binascii.hexlify(lora.mac()).upper().decode('utf-8'))
              # Set network keys
              dev_eui = binascii.unhexlify('00D85D973D86EE6F')
              app_eui = binascii.unhexlify('70B3D57ED000A657')
              app_key = binascii.unhexlify('4317A37691B9333FC62842FEBADE5F78')
          
              # Join the network
              lora.join(activation=LoRa.OTAA, auth=(dev_eui, app_eui, app_key), timeout=0)
              while not lora.has_joined():
                  print('Not joined yet...')
                  pycom.rgbled(off)
                  time.sleep(1.0)
                  pycom.rgbled(red)
                  time.sleep(1.0)
          
              print('Joined')
              pycom.rgbled(blue)
              print(app_eui)
              s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
              s.setsockopt(socket.SOL_LORA, socket.SO_DR, 5)
              s.setblocking(True)
              lora.nvram_save()
          
          
          C 1 Reply Last reply Reply Quote 0
          • C Offline
            crumble @Arno
            last edited by crumble

            @Arno

            Your LoPy firmware is quite old. pycom has unified the board access a few versions ago. They use now the class Pycoproc on all boards with a PIC. Deepsleep is now splitted into two functions. setup_sleep and go_to_sleep.

            A 1 Reply Last reply Reply Quote 0
            • A Offline
              Arno @crumble
              last edited by

              @crumble

              Thanks for the clarification. I will update the firmware on the Lopy and try again.
              Maybe you can also answer some related questions:

              1. If I look at the Pycoproc code it seems only for the pysense and pytrack boards. There is no reference to the expansion board. Will it still work and will it bring my combination (with deepsleep shield) into deepsleep / low power mode?
              2. Do I still need the deepsleep shield with the version 3.1 expansion board?
              3. Is it possible to extract the elapsed or remaining time when the wakeup is through a pin level change? This was not possible with the previous combination with the version 2 expansion board but would help me a lot...

              An update on the docs.pycom.io site would also help.....

              C 1 Reply Last reply Reply Quote 0
              • C Offline
                crumble @Arno
                last edited by crumble

                1. If I look at the Pycoproc code it seems only for the pysense and pytrack boards. There is no reference to the expansion board. Will it still work and will it bring my combination (with deepsleep shield) into deepsleep / low power mode?

                Shall work. They moved the common part into pycoproc when they planned additional boards with the PIC (pysense, expension 3.x).

                1. Do I still need the deepsleep shield with the version 3.1 expansion board?

                No. Maybe this is your current problem. On both is a PIC microcontroler which shall handle the deepsleep. Talking to both at the same time may issue a lot of problems.

                1 Reply Last reply Reply Quote 0
                • A Offline
                  Arno
                  last edited by

                  Hi
                  Thanks for the advise. It would be useful if it would bring me a bit further.
                  Updating the Fw to version 1.18.2.r6 did not help me much. I removed the deepsleep board and dowloaded and installed the pycoproc.py file. Now I get the (infamous) Exception: Board not detected: I2C bus error.... Searched the forum for a solution to no avail..
                  Working on it for 3 hours but still do not have a solution..

                  1 Reply Last reply Reply Quote 0
                  • M Offline
                    matthew4355 @robert-hh
                    last edited by matthew4355

                    @robert-hh Good piece of information posted here.

                    1 Reply Last reply Reply Quote 0
                    • A Offline
                      Arno
                      last edited by

                      According to the helpdesk pycoproc.py will not work for expansion boards so I am confused....
                      It would be very helpful if someone can direct me at an example where an expansion board 3.1 is used in combination with deep sleep

                      A 1 Reply Last reply Reply Quote 0
                      • A Offline
                        andreas @Arno
                        last edited by andreas

                        @Arno said in Deepsleep hangs system:

                        It would be very helpful if someone can direct me at an example where an expansion board 3.1 is used in combination with deep sleep

                        The DeepSleep class referenced above (maybe from pycoproc) is for controlling the complete shutdown on other boards and the deep sleep shield from the early days. At least, this is what I learned.

                        With or without expansion board, you might want to just invoke machine.deepsleep() these days. However, this will not completely cut the power supply to the device but rather activate the vanilla deep sleep mode of the ESP32 [1].

                        [1] https://docs.espressif.com/projects/esp-idf/en/v3.2/api-reference/system/sleep_modes.html

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

                          @andreas The initial poster use sa LoPy board, which has a bug with respect to machine.deepsleep(). The current consumption would not drop. For these board and other early boards Pycom supplies the deep sleep shield, which powers off the board. This function was then integrated into the expansion board 3.x.
                          So if you use expansion board 3.x, you must not use the deep sleep shield and its library. If you use expansion board 2.1, you have to use the deep sleep shield, at least if you want a low sleep current.

                          A 1 Reply Last reply Reply Quote 0
                          • A Offline
                            andreas @robert-hh
                            last edited by andreas

                            @robert-hh said in Deepsleep hangs system:

                            For these board and other early boards Pycom supplies the deep sleep shield, which powers off the board. This function was then integrated into the expansion board 3.x.

                            Thanks again for the thorough information on that topic and for closing the gaps in our knowledge about this. So, I am humbly asking how you would invoke this kind of deep sleep with the expansion board 3.x then?

                            I figure that if the functionality to achieve a complete power cut is available from the expansion board already, it might well be used by devices other than the LoPy to save even more power than the ESP32-based deep sleep mode invoked through machine.deepsleep().

                            Sorry if I am getting something wrong here but your answer made me curious.

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

                              @andreas To have a deep sleep which cuts teh power to the device there are two options:

                              • yyPy + Deepsleep shield + expansion board 2 (or something else)
                              • yyPx + one of the newer expansion boards (expansion board 3, pysense, pytrack, pyscan)

                              The old xxPy devices (WiPy2, LoPy1, SiPy) have a bug in the power regulator, causing the current being too high, when started with machine.deepsleep().
                              The deep sleep shield and the newer expansion board use different libraries and must not used together. You can imagine the deep sleep shield as the protoype to expansion board 3. It is one of the few devices where the schematics are available. According to that, It is connected to P10, P17 and P28.
                              So all of that does not help with the posters initial problem.

                              1 Reply Last reply Reply Quote 0
                              • A Offline
                                Arno
                                last edited by

                                @robert-hh Thanks for the update. Can you give a link to the libraries to use, the explanation on how to use and the schematics of the expansion boards? especially for the 3.1 expansion board?
                                It would be of great help to me and others.

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

                                  @Arno There are no schematics published for expansion board 3.x. As far as I understand it, the library to use should be this one: https://github.com/pycom/pycom-libraries/tree/master/lib/pycoproc
                                  I'm not fully sure, because I never got myself an expansion board 3.x. I have a model 2 in the drawer, and use my own base boards with a FT232 chip for desk testing.

                                  A 1 Reply Last reply Reply Quote 0
                                  • A Offline
                                    andreas @robert-hh
                                    last edited by andreas

                                    Thanks again for your explanations, @robert-hh!

                                    @robert-hh said in Deepsleep hangs system:

                                    I'm not fully sure, because I never got myself an expansion board 3.x.

                                    I never imagined pycoproc could also be used for the regular expansion board 3.x, I always though it was for controlling the PyTrack and PySense boards only.

                                    Now reading that the same hardware functionality available from the latter two as well as the early Deep Sleep Shield might also be available on the expansion board 3.x, we will be more than happy to investigate whether one can put the device into even lower/zero currents.

                                    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