Wakeup from deepsleep with hall sensor

axoulc
Posts: 1
Joined: Tue Jul 17, 2018 9:29 am

Wakeup from deepsleep with hall sensor

Postby axoulc » Tue Jul 17, 2018 9:44 am

Hi, I would like to wakeup ESP from deepsleep with the hall sensor. I find a sample of code (macro) to program ULP.
It doesn't work for me and I tried a lot of value for high_adc_treshold (low_adc_treshold is set to 0).

Code: Select all

#include "esp32/ulp.h"
#include "soc/rtc_cntl_reg.h"
#include "driver/rtc_io.h"
#include "driver/adc.h"

....

adc1_config_channel_atten(ADC1_CHANNEL_0, ADC_ATTEN_DB_11);
adc1_config_width(ADC_WIDTH_BIT_10);
adc1_ulp_enable();
rtc_gpio_init(GPIO_NUM_36);
const ulp_insn_t program[] = {
                I_DELAY(32000),    // Wait until ESP32 goes to deep sleep
                M_LABEL(1),        // LABEL 1
                I_MOVI(R0, 0),       // Set reg. R0 to initial 0
                I_MOVI(R2, 0),       // Set reg. R2 to initial 0
                M_LABEL(2),        // LABEL 2
                I_ADDI(R0, R0, 1),   // Increment cycle counter (reg. R0)
                I_ADC(R1, 0, 0),     // Read ADC value to reg. R1
                I_ADDR(R2, R2, R1),   // Add ADC value from reg R1 to reg. R2
                M_BL(2, 4),        // If cycle counter is less than 4, go to LABEL 2
                I_RSHI(R0, R2, 2), // Divide accumulated ADC value in reg. R2 by 4 and save it to reg. R0
                M_BGE(3, high_adc_treshold), // If average ADC value from reg. R0 is higher or equal than high_adc_treshold, go to LABEL 3
                M_BL(3, low_adc_treshold), // If average ADC value from reg. R0 is lower than low_adc_treshold, go to LABEL 3
                M_BX(1),           // Go to LABEL 1
                M_LABEL(3),        // LABEL 3
                I_WAKE(),          // Wake up ESP32
                I_END(),           // Stop ULP program timer
                I_HALT()           // Halt the coprocessor
};
size_t load_addr = 0;
size_t size = sizeof(program)/sizeof(ulp_insn_t);
ulp_process_macros_and_load(load_addr, program, &size);
ulp_run(load_addr);

esp_sleep_enable_timer_wakeup((sec-diff)*1000000);
esp_sleep_enable_ulp_wakeup();
esp_deep_sleep_start();
If someone can help me ;)
axoulc

gabriel-milan
Posts: 2
Joined: Tue May 28, 2019 10:18 pm

Re: Wakeup from deepsleep with hall sensor

Postby gabriel-milan » Tue May 28, 2019 10:21 pm

Hey!

I was having a similar issue and realized there's few material on the internet for that.
I've written a very simple code for waking up ESP32 according to a threshold on hall sensor readings, hope it helps!

Link for the code: https://github.com/gabriel-milan/esp32_ulp_hall_wakeup

Who is online

Users browsing this forum: MicroController and 109 guests