How to wake up the lopy with the accelerometer



  • @railmonitor And is it possible to store the data from the accelerator when it wake up ? Or I have to keep it awake if I want to measure the acceleration ?

    I want to know how strong is the acceleration when it wake up the board (2g, 4g or 8g for example...).



  • @railmonitor that's what I looked for, thank you !



  • Yes, that is definitly possible. Have a look a the following code, it is written for FiPy with Pysense board, so there might be some differences regarding libraries / pins but should work when corrected:

    from pysense import Pysense
    from LIS2HH12 import LIS2HH12
    import pycom
    import time
    import machine
    
    py = Pysense()                  #Create Pysense object
    acc = LIS2HH12()                #Create accelerometer object
    
    if pycom.heartbeat() == True:   #turn off blinking LED
        pycom.heartbeat(False)
    
    wakeup_reason = machine.wake_reason()
    
    #Enable interrupts from accelerometer (P13) and button (P14)
    machine.pin_sleep_wakeup(['P13'], mode=machine.WAKEUP_ANY_HIGH, enable_pull = False)
    machine.pin_sleep_wakeup(['P14'], mode=machine.WAKEUP_ALL_LOW, enable_pull = False)
    
    # set the acceleration threshold to 2000mG (2G) and the min duration to 200ms
    acc.enable_activity_interrupt(2000, 160)
    
    if(wakeup_reason == machine.PIN_WAKE):
        pycom.rgbled(0xffff00)  #yellow
        time.sleep(2)
    
    print("Turning on Red LED for 2 sec")
    pycom.rgbled(0xff0000)      #red
    time.sleep(2)
    
    print("Enter lightsleep mode for 5 sec")
    machine.sleep(5000)         #Value in ms
    
    print("Pysense Wakeup reason is " + str(wakeup_reason))
    
    if acc.activity():
        pycom.rgbled(0x800080)  #purple
    else:
        pycom.rgbled(0x0000ff)  #blue
    

Log in to reply
 

Pycom on Twitter