Lopy + PyTrack DeepSleep wake then lock until power removed

  • Hi there,
    Today I experienced serious issue with lopy and pytrack (all latest firmware). Mainly I think because I2C com between PIC and Lopy is broken and PIC totally out of control.

    I isolated the bug reducing my code to minimal so here what I'm doing in real code

    • I need to deepsleep for 1 hour but awake on move (accel wake up)
    • On wake up (deep sleep or accel) send Lora GPS pos
    • if accel wake up, then deep sleep for 2 min but in this interval no accel wake is authorized (debounce and avoid Lora send continuously when moving)
    • if wake up was 1H time out deep sleep again for 1H with accel wake authorized

    Now here my code (removed all GPS / Lora Stuff just light RGB led when waked correctly and see where it locks)


    file rgb.py

    import pycom
    __version__ = '1.0.0'
    class RGBLED:
    	def __init__(self, brightness):
    		self.brightness = brightness
    		self.saturation = 100
    	def hsv_to_rgb(self,h,s,v):
    		if s == 0.0:
    		    return v, v, v
    		i = int(h*6.0)
    		f = (h*6.0) - i
    		p = v*(1.0 - s)
    		q = v*(1.0 - s*f)
    		t = v*(1.0 - s*(1.0-f))
    		i = i%6
    		if i == 0:
    		    return v, t, p
    		if i == 1:
    		    return q, v, p
    		if i == 2:
    		    return p, v, t
    		if i == 3:
    		    return p, q, v
    		if i == 4:
    		    return t, p, v
    		if i == 5:
    		    return v, p, q
    	def hsv(self,h,s,v):
    		r, g, b = self.hsv_to_rgb(h/360.0, s/100.0, v/100.0)
    		pycom.rgbled(int(r*255)<<16 | int(g*255)<<8 | int(b*255)) 
    	def hl(self,h,v):
    	def h(self,h):
    		self.hsv(h,self.saturation, self.brightness)
    	def off(self):

    file boot.py

    # boot.py -- run on boot-up
    import os
    import machine
    import pycom
    import time
    from network import Bluetooth
    from machine import UART
    from rgb import RGBLED
    from pytrack import Pytrack
    uart = UART(0, 115200)
    print("\r\nStarting ")
    # Wait for terminal to connect
    led = RGBLED(33)
        # Initialize PyTrack
        py = Pytrack()
    except Exception as e:
        print("Exception on Pytrack()")
    rst = machine.reset_cause()
    wake = py.get_wake_reason() 
    print("Waked by ", end='')
    # display the wake reason code
    if wake == 1:
    elif wake == 2:
    elif wake == 4:
    elif wake == 8:
        print("Interrupt Pin")
        print("No Wake")

    file main.py

    import machine
    import math
    import network
    import os
    import time
    import utime
    import pycom
    import array
    from machine import RTC
    from machine import Timer
    from LIS2HH12 import LIS2HH12
    # Initialize accel
    acc = LIS2HH12()
    while True:
            bat = py.read_battery_voltage() * 100
            print("Battery:{:.1f}V ".format(bat/100))
            # Wait for terminal to connect
            print("Wait for sync ", end='')
            for x in range(0, 5):
                print("#", end='')
            print(" OK!", flush=True)
            # check if we was waked by accelerometer activity
            if wake == 1:
                print("Device is moving")
                # No accel wake for 2 minutes
                duration = 120
                acc_wake = False
                print("Device is idle")
                # enable accel wake for next hour
                duration = 3600
                acc_wake = True
            # disable wakeup source from INT pin
            # enable or disable wakeup source accel
            py.setup_int_wake_up(acc_wake, acc_wake)
            # enable the accel activity interrupts
            # set the accelereation threshold 
            if acc_wake == True:
                acc.enable_activity_interrupt(1500, 200)
                print("Accelerometer wake enabled 1.5G" )
                print("Accelerometer wake disabled")
            # We Done
            print("Deep Sleep mode for {:d}s, bye ...".format(duration) )
            # enable wakeup source from INT pin
        except Exception as e:

    So upload all, and then in the best case

    • start normally (magenta + green then deep sleep for 1H)
    • move the board to wake
    • start normally (magenta + green then deep sleep for 2min )
    • move the board, don't wake (that is expected, cool)
    • push the button on pytrack shield, this is waking the board
    • led stays magenta locking on PyTrack() init
    • no way to get out (reset lopy does nothing, button on pytrack does nothing)

    if you're unlucky maybe you won't go so far and and got led blinking magenta after 1st wake (mainly reset loop)

    So It's a bug or my code is wrong ?

    PS : I just tried today on a Lopy4 and PySense (modified some code of course), same behaviour.

    Thanks for any help, spent too much hours on this issue.

  • Hi @johncaipa,

    We don't have a solution for this yet, we'll update this post when we found the cause of the issue.

  • @daniel can you help me with an answer to this Pytrack problem that does not work correctly? We have not had an answer from @dan Thanks.

  • Hi @dan any news about the solution/workaround of this issue?

  • @dan thanks, I hope the team find the solution.

  • Hi @Charly86 and @johncaipa,
    I was able to reproduce the issue and we're looking into it. At the moment, we don't have a solution/workaround yet, but we'll keep you updated.

  • @jcaron ok thanks.. could you verify the @Charly86 's code ?, seems a problem with the Pytrack, since it seems to be stuck in a cycle when moving the device the first time, even if the device is not moving afterwards.
    Someone from the pycom team that can help us with this issue? @catalin

  • @johncaipa For the color, you need to specify saturation = 0 to get white, not just the hue (which is actually irrelevant in that case).

  • @charly86 Hi, I am trying to make a similar application, but using a Sipy, I have tested your code and I can corroborate there is an error, but I have not been able to identify the problem.
    At the beginning it starts well (magenta + green then deep sleep), after moving the board to wake it up, it wakes up as it should be and goes into deep sleep (magenta + green then deep sleep for 2min ), then when it wakes up it starts to work incorrectly as it goes into a Timer wake up and a second later a Accelerometer wakes up and so every 2 minutes. with my code, something similar happened to me.
    As I told you at the beginning, I could not identify what the problem was.
    Tell me if you managed to find a solution, and I'll help you verify

    ps: the white color on the led does not work properly, results in a red color ;)

  • @catalin thanks for reporting, I've just tried with latest stable 1.18.0 (flashed my Lopy 2 min ago), copy/paste code above and synced with pymakr, then after update board is reset and restarting

      1. Led magenta, then green then deep sleep)
      1. move the board to wake, Led Magenta, then green then deep sleep (for 2min )
      1. push the button on pytrack shield to wake, led stays blinking magenta locking on PyTrack() init
      1. pressed Lopy Reset, led stays blinking magenta locking on PyTrack() init
      1. only solution to recover, power off then power on the whole (Lopy + PyTrack)

    So the issue is still there (to be honest I'm not surprised because I suspect this to be an issue on pytrack firmware not on Lopy One) , what's the firmware on your pytrack, I saw on another post you tried another new one? Mine is 0.0.8

    Here are the files link https://forum.pycom.io/assets/uploads/files/1528329448441-pytracker-bug.zip.pdf
    wget it then remove .pdf extension

  • hi @Charly86,

    I've redone this test, on the latest stable, on Lopy (sysname='LoPy', nodename='LoPy', release='1.18.0', version='v1.8.6-849-046b350 o n 2018-06-01', machine='LoPy with ESP32', lorawan='1.0.2') and I couldn't block the PIC.

Log in to reply

Pycom on Twitter