Accelerometer wake_up



  • Hi, @seb

    First, thanks to @catalin for helping me about the sleep loop.

    This is the issue right now :

    I can run a simple program but I can't use pycom.rgbled().
    It says : "OSError: the requested operation is not possible"
    And sometimes I get : "An error occurred: Not enough memory available on the board.
    Upload failed. Please reboot your device manually."

    But I tried all the reboot and reset but It doesnt work.
    So I used the command to Reset the Filesystems but still the same errors appears.

    I updated firmware just in case but no result.
    The led is flashing blue every 4 seconds.



  • Got it.
    Thanks @seb and @jcaron for all your help !



  • @thomasp As explained earlier, when you go to to deep sleep, the USB connection goes as well, and you are disconnected. Depending on what tool you use to connect, you may get an explicit notification of the disconnection, or it can be quite silent. It is also not necessarily immediate.

    When you wake up the device, your computer needs to detect the USB device is back and you need to reconnect to it. Even if the tool you use reconnects automatically, it will be too late to show the output.

    Use the LED as an indicator, or store your logs to a variable or array, and check that once you reconnect.



  • This is the code I'm currently running :

    import pycoproc
    from pysense import Pysense
    from LIS2HH12 import LIS2HH12
    import pycom
    import time
    
    py = Pysense()
    li = LIS2HH12()
    pycom.heartbeat(False)
    
    print("Hello")
    reason = py.get_wake_reason()
    print("Wakeup reason1: " + str(reason))
    #print("Wakeup reason2: " + str(reason) + "; Aproximate sleep remaining: " + str(py.get_sleep_remaining()) + " sec")
    time.sleep(0.5)
    
    py.setup_int_pin_wake_up(False)
    py.setup_int_wake_up(True, True)
    li.enable_activity_interrupt(2000, 1)
    
    if reason == pycoproc.WAKE_REASON_ACCELEROMETER:
        pycom.rgbled(0x200000)
        print("Wakeup reason2: " + str(reason))
    else:
        pycom.rgbled(0x002000)  # timer wake-up
        print("Wakeup reason3: " + str(reason))
    
    time.sleep(1)
    
    print("Good Night")
    pycom.rgbled(0x202020)
    time.sleep(1)
    
    py.setup_sleep(10)
    py.go_to_sleep()
    print("Good Morning")
    

    And this is what I get from the console :

    0_1519400572764_c190990e-ef77-4205-9a3a-8ccdfcdaa13d-image.png

    So It keeps running correctly, when I shake it I get the red led.
    But the console is not actualised. I mean I don't get new wakeup reason.
    And the Good Morning is not printed.



  • Where is this print statement? If it is after the go_to_sleep, it will never run. If it is before are you sure you actually have the serial port open? When the pytrack/pysense go to sleep they de-initialise the USB connection, this means you will have to reconnect before you see any text in the serial terminal (unless your terminal is set to automatically reconnect), pymakr can take quite a while to realise and reconnect sometimes. In regards to ctrl+c, you cannot use this when the device is in sleep mode because the pytrack usb is disabled and the pycom module is powered off so it will not receive this. If you need to stop the script from running I recommend connecting a wire between P12 and 3v3 (be careful not to short circuit 3v3 to the metal casing on the module, this is connected to GND), hold this connection until the device wakes and it should "safe boot", which means it won't run boot.py or main.py



  • After some reset and deleting unused librairies from the flash, I have now the led flashing correctly.
    But still nothing is printed.
    And I can't stop the program with ctrl+c.



  • Hi @seb,

    The current version of my firmware is 1.15.0.b1. Is this correct ?

    When I run print("Wakeup reason: " + str(reason) + "; Aproximate sleep remaining: " + str(py.get_sleep_remaining()) + " sec") in the console, nothing happens and I can't stop it anymore.



  • I never get the wake up from the accelerometer. As I said, even with li.enable_activity_interrupt(2000, 200), I can't catch it.



  • And when you run the code I posted, does it never wake up from shaking?



  • Yes it shows up as a COM port and yes I updated the Pysense firmware successfully.



  • If you're pysense board shows up as a COM port, the version shouldn't matter too much. Have you managed to successfully update the Pysense firmware?



  • Nope, but it says upgraded successfully



  • If you click upgrade, does it change to version 10?



  • @seb

    So I restarted from the beginning and after all updates I have this :

    0_1518704358159_1c6f3358-9a74-4a40-9fb8-eec6e2477817-image.png

    My driver usbser is v1.0 and not v10.0 as indicated on the documentation.

    Is the problem coming from there ? If so, I don't know what to do beacause I run Win10 and erverything is updated.



  • Hi,

    I just tested this again, have you run the exact code I posted previously? this works successfully in my case. Please make sure your pysense and pycom development module both have upto date firmware, and that you are using the latest pysense library from:
    https://github.com/pycom/pycom-libraries/tree/master/pysense
    you will also need pycoproc.py from:
    https://github.com/pycom/pycom-libraries/blob/master/lib/pycoproc/pycoproc.py



  • Hi @seb,

    Are you still working on it ? I need some help to understand where the problem comes from.



  • Hi @seb,

    This worked for you ? I only get timer as a weak reason. Or I should say I don't know if it's the timer but the test on "else" everytime.

    When I shake the board nothing happens. Even with li.enable_activity_interrupt(2000, 1)
    And by the way nothing is printed. Should I had something to the code or everything should work with that ? Should I add a While loop to see if it works properly ?

    setup_sleep() is only here to setup right ?
    So if I run :

    pycom.rgbled(0x00FFFF) 
    py.setup_sleep(20)
    pycom.rgbled(0xFFFFFF) 
    

    I should get the white light. But I don't. It stops at py.setup_sleep(20)



  • @thomasp said in Accelerometer wake_up:

    from pysense import Pysense
    from LIS2HH12 import LIS2HH12
    import pycom
    import time

    py = Pysense()
    li = LIS2HH12
    pycom.heartbeat(False)

    print("Wakeup reason: " + str(py.get_wake_reason()) + "; Aproximate sleep remaining: " + str(py.get_sleep_remaining()) + " sec")
    time.sleep(0.5)

    py.setup_int_pin_wake_up(False)

    py.setup_int_wake_up(True, True)

    li.enable_activity_interrupt(2000, 200)

    if li.activity():
    pycom.rgbled(0x0F0000)
    time.sleep(0.5)
    else:
    pycom.rgbled(0x000F00) # timer wake-up
    time.sleep(0.5)
    time.sleep(0.1)

    go to sleep for 10 sec maximum if no accelerometer interrupt happens

    py.setup_sleep(10)
    py.go_to_sleep()
    pycom.rgbled(0x1f0f00)
    time.sleep(1)

    Hi,
    When you put the Pysense into sleep mode, it powers down the on-board PIC microcontroller that is acting as the USB serial adapter. This means it will not show up on your PC as a usb device while sleeping. You can stop your module from executing your main.py and boot.py files by connecting P12 to 3.3v. This might be tricking with a pysense, you will have to carefully hold a wire in place making sure you don't short circuit 3.3v to gnd

    I have fixed a few bugs in the code you posted above and got it all working:

    import pycoproc
    from pysense import Pysense
    from LIS2HH12 import LIS2HH12
    import pycom
    import time
    
    py = Pysense()
    li = LIS2HH12()
    pycom.heartbeat(False)
    
    reason = py.get_wake_reason()
    print("Wakeup reason: " + str(reason) + "; Aproximate sleep remaining: " + str(py.get_sleep_remaining()) + " sec")
    time.sleep(0.5)
    
    py.setup_int_pin_wake_up(False)
    
    py.setup_int_wake_up(True, True)
    
    li.enable_activity_interrupt(2000, 200)
    
    if reason == pycoproc.WAKE_REASON_ACCELEROMETER:
        pycom.rgbled(0xFF0000)
    else:
        pycom.rgbled(0x00FF00)  # timer wake-up
    time.sleep(2)
    
    # go to sleep for 5 minutes maximum if no accelerometer interrupt happens
    py.setup_sleep(20)
    py.go_to_sleep()
    


  • @seb

    I tried your code and it was working great. But I'm still not able to upload.

    Then I tried this code :

    from pysense import Pysense
    from LIS2HH12 import LIS2HH12
    import pycom
    import time
    
    py = Pysense()
    li = LIS2HH12
    pycom.heartbeat(False)
    
    print("Wakeup reason: " + str(py.get_wake_reason()) + "; Aproximate sleep remaining: " + str(py.get_sleep_remaining()) + " sec")
    time.sleep(0.5)
    
    py.setup_int_pin_wake_up(False)
    
    py.setup_int_wake_up(True, True)
    
    li.enable_activity_interrupt(2000, 200)
    
    if li.activity():
        pycom.rgbled(0x0F0000)
        time.sleep(0.5)
    else:
        pycom.rgbled(0x000F00)  # timer wake-up
        time.sleep(0.5)
    time.sleep(0.1)
    
    # go to sleep for 10 sec maximum if no accelerometer interrupt happens
    py.setup_sleep(10)
    py.go_to_sleep()
    pycom.rgbled(0x1f0f00)
    time.sleep(1)
    

    I added a lot of timers to see what is going on.
    The led never switched on and I can't stop the script beaucause It seems like the module is in sleep mode or lost in a loop and I can't communicate with it anymore.
    Nothing is printed.

    All the librairies are included.
    If I disconnect the board the blue light is flashing again every 4 seconds.



  • Hi,

    Could you please post the complete source code for the code you are running?

    If you are seeing that OSError, it means you have not disabled the LED heartbeat (the blue flash every 4 seconds that lets you know the device is running). Try the following code:

    import pycom
    import time
    
    pycom.heartbeat(False)
    
    while True:
      pycom.rgbled(0x0000ff)
      time.sleep(0.2)
      pycom.rgbled(0x00ff00)
      time.sleep(0.2)
      pycom.rgbled(0xff0000)
      time.sleep(0.2)
    

 

Hello World?

Pylife on Kickstarter - November 2018








Back Us On Kickstarter >

Pycom on Twitter