Use accelerometer to put module to sleep.

  • I think this may just be my not correctly understanding the inactivity function of the accelerometer on pytrack/pysense, but I can't find an explanation anywhere.

    I have a tracking app in development that determines the gps coordinates of my caravan using a GPy/Pytrack combination, and sends the data to via Cat great.

    The unit is powered by a battery, which is recharged by a small solar panel incorporated in the case, so power is not really an issue but I want to stop sending data when the caravan is stopped for a predetermined period of time, say 10 minutes. I'd like to use the accelerometer to determine when the caravan is stopped and then use the go_to_sleep function to power down.

    Any assistance appreciated.

  • What happens after you call py.go_to_sleep(), is the Pytrack coprocessor cuts off the supply power to the microcontroller. This is the lowest power sleep state available. On the accelerometer wake, the coprocossor switches the power back on, meaning the Gpy will boot up as if it was just plugged in (starting with and continuing in If you have a pytrack 1, you do not have to use the workaround provided in the link I posted.

    The suggestion to wait 10 minutes is because sometimes you have to wait for traffic lights and such, where you do not want to turn off the tracker. I would take the inactivity interrupt (which follows the activity interrupt, when the movement is on the falling edge) from the accelerometer, and note down the time. Then, in the main loop check that time against the current time and see if the 10 minutes have passed. If so, go to sleep and make it wake on accelerometer. You'll have to set the sensitivity just correct that it does not wake up on small movements of entering and exiting the caravan, but that it does trigger on driving it on the road I presume.

  • @Gijs thanks for the response. I can get the Pytrack (1 not 2) to wake on activity, that's simple...I still don't understand the code sequence to have it wait for 10 minutes for inactivity before going to sleep, unless that is simply a loop.

    The Pytrack is still measuring gps coordinates during the 10 minute window.

  • Hi,
    Going to sleep on no movement could depend on some factors, like the wait time and acceleration duration. You could use an interrupt to detect activity, and then sleep if you did not notice any movement in 10 minutes? There's an example here: (sorry for the obscure location, we're still finalising the documentation)

    On the Pytrack 2 / Pysense 2 we do have an issue with waking up from the interrupt in the go_to_sleep function, as explained in the thread. The v16 firmware provides a software workaround there. To upload it to your Pytrack2, have a look at this page:


Log in to reply

Pycom on Twitter