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

    How to wake up the lopy with the accelerometer

    Scheduled Pinned Locked Moved Discussion
    23 Posts 7 Posters 574 Views 8 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.
    • C Offline
      CeylordZ
      last edited by

      But if I'm using a loop where I read the acceleration, I can't sleep the board, am I wrong ?

      And what is the "append" function ?

      1 Reply Last reply Reply Quote 0
      • J Offline
        jcaron @railmonitor
        last edited by

        @railmonitor The code you posted above is actually missing the actual "deep sleep" part...

        @CeylordZ If you want the actual acceleration value, I don't think you'll be able to use deep sleep with that. The accelerometer will wake up the LoPy, but by the time the LoPy has woken up and is ready to query the accelerometer, values will have changed. I don't think there's any way to tell the accelerometer to "keep" the value that caused the wake up, though you should check the chip's data sheet and application notes, there may be something in there.

        IIRC the accelerometer has a buffer used to deliver data to the LoPy, but even at the lowest data rate I don't think it's large enough to last for the wake up time.

        If you want the full data, you'll have to keep the LoPy awake, which will indeed use quite a bit of power.

        What is your actual use case?

        R C 2 Replies Last reply Reply Quote 0
        • R Offline
          railmonitor @jcaron
          last edited by

          @jcaron Correct, i am using machine.sleep() which is the lightsleep mode, because, as you state, wakeup from deepsleep is rather slow due to boot time etc.. and not feasible if you want to wake and take measurements immediately.

          @CeylordZ It's not really a loop in the traditional sense, you are just telling it to do your readings when there is activity on the accelerometer.

          J 1 Reply Last reply Reply Quote 0
          • C Offline
            CeylordZ @jcaron
            last edited by

            @jcaron It's problematic, My project would be to put the lopy-pytrack in a case and to let it sleep until it detect a high shock, at this moment it will send the data (with the intensity of the shock) in LoRa then it will go to sleep again until the next wake-up.
            But it will impossible to recharge the Lipo battery before 2-3 months so, it's necessary that the lopy consume as little as possible.

            @railmonitor how does the machine.sleep() works compared to the deepsleep ?
            I know that the deep sleep almost shut down the processor and restart the board when it's waking up but not the machine.sleep()

            R 1 Reply Last reply Reply Quote 0
            • R Offline
              railmonitor @CeylordZ
              last edited by

              @CeylordZ Have a look here:
              https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/system/sleep_modes.html

              1 Reply Last reply Reply Quote 0
              • J Offline
                jcaron @railmonitor
                last edited by

                @CeylordZ What kind of battery are you planning to use? To last 2 months with, say, a 2500 mAh battery, you need to draw an average of 1.75 mA or less. Light sleep supposedly gets you down to 3.5 mA, but:

                • it should be checked in actual conditions, with the accelerometer enabled in the right mode, etc.
                • you have to consider that whenever it wakes up and sends stuff over LoRa, it will draw a lot more, so this will raise your average. Depending on how frequently you wake up and how long you do, this could increase your average just a tiny bit or a a whole lot.
                • I'd be curious to see how light sleep and LoRa combine. Last time I looked into it (it was a while ago, though), as soon as LoRa is configured, it'll have a 1 kHz polling loop set up which will kill light sleep performance.

                So either you'll have to pack a larger battery (> 5000 mAh, probably more, which becomes quite a large thing), or light sleep won't do. But deep sleep probably won't let you get the value of the acceleration that triggered the wake up. Again, I recommend you check the accelerometer's data sheet and application notes, it might actually be possible with correct configuration of the chip.

                An alternative might be to use the ULP co-processor, but AFAIK using this on the Pycom modules is still work in progress.

                C 2 Replies Last reply Reply Quote 0
                • C Offline
                  CeylordZ @jcaron
                  last edited by

                  This post is deleted!
                  1 Reply Last reply Reply Quote 0
                  • C Offline
                    CeylordZ @jcaron
                    last edited by CeylordZ

                    @jcaron For now I received a 2000 mAh battery but it's only for testing I know it won't be enough for my application.
                    I will study the possibility to use the ULP co-processor, maybe it is the only way for me to achieve my project, I'll check the LIS2HH12's datasheet in details, maybe there is something interesting I didn't see.

                    Something I don't understand is the machine.sleep(), when I use it, the program stop working during the time of the sleep then it wake up and execute the rest of the program so I'm not able to let it do something during the machine.sleep.
                    Furthermore, with @railmonitor's code, interruptions works only with the button but not with the accelerometer, I don't know why...

                    And during the lightsleep, when I push the putton, the wake-up reason is (0,none)

                    J 1 Reply Last reply Reply Quote 0
                    • J Offline
                      jcaron @CeylordZ
                      last edited by

                      @CeylordZ I've never used light sleep, so I don't really know how it interacts with the rest (i.e. if machine.pin_sleep_wakeup actually affects getting out of light sleep or not).

                      BTW, going very very quickly through the pin_sleep_wakeup source and the Espressif docs, I believe the code from @railmonitor above has an issue: it seems to me that each call to pin_sleep_wakeup will "replace" all previous settings, so you need to have all pins in the array in the same call, and they should all use the same mode.

                      I did not actually check or test it, but that's my understanding from a quick glance through the code and docs.

                      As for the wakeup reason, another quick glance through the source also makes me think it is only initialised (in the firmware) during the boot process, so only after a deep sleep, not a light sleep. This one should be easily fixable in the firmware (adding another separate call I would think, there's probably a reason the value is stored rather than returned directly from the ESP-IDF in the current function).

                      J 1 Reply Last reply Reply Quote 2
                      • J Offline
                        johnmcdnz @jcaron
                        last edited by

                        @jcaron @CeylordZ
                        I think I agree with your analysis that the call to machine.pin_sleep_wakeup overwrites previous settings.
                        I'm experimenting also using the example code of the accelerometer.
                        As provided, the code reliably wakes on button press. But doesn't wake on movement.
                        If the line for setting up the wakeup for the button P13 is removed. the accellerometer does now wake up!

                        I'm continuing to work on this and if/when I get reliable code I'll post it.

                        F 1 Reply Last reply Reply Quote 0
                        • F Offline
                          Flavio Frattini @johnmcdnz
                          last edited by

                          @johnmcdnz Hi, have you achieved any progress with the accelerometer?

                          J 1 Reply Last reply Reply Quote 0
                          • J Offline
                            johnmcdnz @Flavio Frattini
                            last edited by

                            @Flavio-Frattini Yes I did (sorry for delay in replying)
                            as said before the code should only call machine.pin_sleep_wakeup once with the setup. Therefore it can either be used to wakeup with the button or the accellerometer, but can't use both.

                            #Enable interrupts from accelerometer (P13) and button (P14)  JMCD:  bug report, only use one of these lines, subsequent calls overwrite earlier setup
                            machine.pin_sleep_wakeup(['P13'], mode=machine.WAKEUP_ANY_HIGH, enable_pull = False)
                            
                            # enable activity and disable inactivity interrupts, using the default callback handler
                            py.setup_int_wake_up(True, False)
                            # set the acceleration threshold to 500mG (0.5G) and the min duration to 200ms
                            acc.enable_activity_interrupt(500, 200)
                            
                            
                            1 Reply Last reply Reply Quote 2
                            • B Offline
                              Bryan Hom
                              last edited by

                              @johnmcdnz

                              Any chance that you got further with this code and are willing to share?

                              1 Reply Last reply Reply Quote 1
                              • G Offline
                                Gijs
                                last edited by

                                The latest example is available here: https://docs.pycom.io/tutorials/expansionboards/sleep/, for use with the latest pycom libraries.

                                B 1 Reply Last reply Reply Quote 0
                                • B Offline
                                  Bryan Hom @Gijs
                                  last edited by

                                  @Gijs Hi thank you. i did see this earlier, but i could not find anything about recording that wake up value. I assume once the unit wakes up i could take a reading, but that reading that caused the wake up would be missed correct?

                                  1 Reply Last reply Reply Quote 0
                                  • G Offline
                                    Gijs
                                    last edited by

                                    Yes, as the reading is only caught on the interrupt, before the microcontroller wakes up, we cannot see the data

                                    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
                                    • 2
                                    • 1 / 2
                                    • First post
                                      Last post

                                    Pycom on Twitter

                                    Pycom