Detecting and counting pulses while in deep sleep

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
tsmladenova
Posts: 1
Joined: Mon Aug 01, 2022 7:41 am

Detecting and counting pulses while in deep sleep

Post by tsmladenova » Mon Aug 01, 2022 7:48 am

Hello, I'm trying to count incoming pulses with ESP32 and micropython.
The idea is to measure current rainfall and rain quantity. I don't have the hardware for the rain measurement at the moment, but a colleague made some adjustments to simulate it - a button that could be pressed manually. At the moment I'm able to detect when the button is pressed and what I would want to do next is to detect if the button (and how many times) is being pressed while the device has been in deep sleep. I'm not sure if it is possible at all and I would be thankful for some pointers on where and how to search for such a thing.
Please, keep in mind, that the hardware part of this whole project is not my strength and I'm just programming the device and learning about it on the go.

User avatar
karfas
Posts: 193
Joined: Sat Jan 16, 2021 12:53 pm
Location: Vienna, Austria

Re: Detecting and counting pulses while in deep sleep

Post by karfas » Mon Aug 01, 2022 10:39 am

If you want to count while sleeping, you will need to use the ULP coprocessor.

See e.g. viewtopic.php?f=18&t=7440 for links about the ULP.
A few hours of debugging might save you from minutes of reading the documentation! :D
My repositories: https://github.com/karfas

Christian Walther
Posts: 169
Joined: Fri Aug 19, 2016 11:55 am

Re: Detecting and counting pulses while in deep sleep

Post by Christian Walther » Mon Aug 01, 2022 11:01 am

Also, if you want to wake up the main CPU from the ULP, you will need to use a nightly build of MicroPython, as that ability was added after the current 1.19.1 release.

Lobo-T
Posts: 36
Joined: Tue Nov 16, 2021 2:36 pm

Re: Detecting and counting pulses while in deep sleep

Post by Lobo-T » Mon Aug 01, 2022 12:13 pm

There is an example of using ULP to count pulses here:
https://github.com/espressif/esp-idf/tr ... lp_fsm/ulp

And it might be nice to know that there exists a Micropython ULP compiler:
https://github.com/micropython/micropython-esp32-ulp

KJM
Posts: 158
Joined: Sun Nov 18, 2018 10:53 pm
Location: Sydney AU

Re: Detecting and counting pulses while in deep sleep

Post by KJM » Tue Aug 02, 2022 6:25 am

https://gist.github.com/wnienhaus/56c53 ... a43ab7ddf8

Took me a while to figure out the ins & outs of running ulp code inside a .py but the gent behind the idea was very supportive, not a hint of the bruising side serve of opinion that you sometimes get when seeking guidance on some forums.

Post Reply