Hi,
for a prototyping project I'm looking for a developer that can help us.
It is an university project, improving the hygiene in the health care sector.
I need the ESP32 to wake up from the deep sleep mode if the hall sensor detects a measurement over a certain threshold. My understanding ist, that the ULP can read the current value of the hall sensor over the ADC.
As I don't have much experience in Assembler and the examples using the ULP are quite vague any help is very much appreciated.
Best regards,
Simon
Wake Up - ADC - Hall Sensor
Re: Wake Up - ADC - Hall Sensor
Hi,
maybe it will help, I have written it today (works also in Arduino IDE):
Best regards,
Marek
maybe it will help, I have written it today (works also in Arduino IDE):
Code: Select all
#include "esp32/ulp.h"
#include "soc/rtc_cntl_reg.h"
#include "driver/rtc_io.h"
#include "driver/adc.h"
void ulp_adc_wake_up(unsigned int low_adc_treshold, unsigned int high_adc_treshold)
{
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 size = sizeof(program)/sizeof(ulp_insn_t);
ulp_process_macros_and_load(0, program, &size);
ulp_run(0);
esp_sleep_enable_ulp_wakeup();
esp_deep_sleep_start();
}
Marek
-
- Posts: 2
- Joined: Tue May 28, 2019 10:18 pm
Re: Wake Up - ADC - Hall Sensor
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
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
Re: Wake Up - ADC - Hall Sensor
Hello Marek,
your code does not compile for me on Arduino, any advice what could be wrong? Here is error message:
Best regards, Jan
your code does not compile for me on Arduino, any advice what could be wrong? Here is error message:
Code: Select all
/tmp/arduino_build_150223/core/core.a(main.cpp.o):(.literal._Z8loopTaskPv+0x8): undefined reference to `setup()'
/tmp/arduino_build_150223/core/core.a(main.cpp.o):(.literal._Z8loopTaskPv+0xc): undefined reference to `loop()'
/tmp/arduino_build_150223/core/core.a(main.cpp.o): In function `loopTask(void*)':
/home/janbenes/.arduino15/packages/esp32/hardware/esp32/1.0.5/cores/esp32/main.cpp:32: undefined reference to `setup()'
/home/janbenes/.arduino15/packages/esp32/hardware/esp32/1.0.5/cores/esp32/main.cpp:35: undefined reference to `loop()'
collect2: error: ld returned 1 exit status
exit status 1
Error compiling for board ESP32 Dev Module.
brandobur wrote: ↑Wed Jul 11, 2018 12:45 pmHi,
maybe it will help, I have written it today (works also in Arduino IDE):
Best regards,Code: Select all
#include "esp32/ulp.h" #include "soc/rtc_cntl_reg.h" #include "driver/rtc_io.h" #include "driver/adc.h" void ulp_adc_wake_up(unsigned int low_adc_treshold, unsigned int high_adc_treshold) { 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 size = sizeof(program)/sizeof(ulp_insn_t); ulp_process_macros_and_load(0, program, &size); ulp_run(0); esp_sleep_enable_ulp_wakeup(); esp_deep_sleep_start(); }
Marek
Re: Wake Up - ADC - Hall Sensor
Hi!
Dear Brandobur!
I tried this example in Arduino.
in setup () I call ulp_adc_wake_up (unsigned int low_adc_treshold, unsigned int high_adc_treshold) with different parameters, but it always wakes up the processor without a magnet.
The arduino hallread() return integer value, i look 80-100 without magnet, with magnet one pole 560, other pole -440 negative value
You use unsigned integer, I tried (1, 4200000000) and vice versa, and many other values.
What can be the usable range?
Thanks
Dear Brandobur!
I tried this example in Arduino.
in setup () I call ulp_adc_wake_up (unsigned int low_adc_treshold, unsigned int high_adc_treshold) with different parameters, but it always wakes up the processor without a magnet.
The arduino hallread() return integer value, i look 80-100 without magnet, with magnet one pole 560, other pole -440 negative value
You use unsigned integer, I tried (1, 4200000000) and vice versa, and many other values.
What can be the usable range?
Thanks
Re: Wake Up - ADC - Hall Sensor
Excellent project, I think it would work for all the ultra-low power application. I will try the code in my project in the future.
Re: Wake Up - ADC - Hall Sensor
Hi Marek,brandobur wrote: ↑Wed Jul 11, 2018 12:45 pmHi,
maybe it will help, I have written it today (works also in Arduino IDE):
Best regards,Code: Select all
#include "esp32/ulp.h" #include "soc/rtc_cntl_reg.h" #include "driver/rtc_io.h" #include "driver/adc.h" void ulp_adc_wake_up(unsigned int low_adc_treshold, unsigned int high_adc_treshold) { 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 size = sizeof(program)/sizeof(ulp_insn_t); ulp_process_macros_and_load(0, program, &size); ulp_run(0); esp_sleep_enable_ulp_wakeup(); esp_deep_sleep_start(); }
Marek
Thanks for your code.
Can you please tell me how I must run this?
What has to be in the setup() function for example, and what has to be in de main loop?
Do I have to call ulp_adc_wake_up(0, 3500); only once or (very fast) in a loop?
I want to read ADC values from an IR-sensor, so I want to check the ADC-value as much as possible in order to detect things properly.
Thanks for thinking with me
Best regards,
Atmoz
Re: Wake Up - ADC - Hall Sensor
Does anyone here on this forum how I should run this code?
The only thing I want is to read ADC in ULP and if a specific value is reached --> wake up the main processor.
Any help is appreciated
Thanks in advance!
Atmoz
The only thing I want is to read ADC in ULP and if a specific value is reached --> wake up the main processor.
Any help is appreciated
Thanks in advance!
Atmoz
Who is online
Users browsing this forum: daniel_3in and 102 guests