This doesn’t seem to be too trivial then. Have you asked for help on Issues · espressif/arduino-esp32 · GitHub or esp32.com with the most minimal fully-contained code for reproduction? You might be running in some weird edge cases where, idk, the ADC peripheral’s clock isn’t started in one case, or the peripheral needs a reset, or something else…
I’ve got it fully working now
Unbelievable how much time this took…
But if I’m really honest: I couldn’t find that much info about this. So it was literally trial and error.
Maybe someone else has the same problem in the future; this is the solution:
if (EnableSleep){
digitalWrite(POWER, HIGH); //pcb power
digitalWrite(26, HIGH); //tcrt led power
gpio_hold_en(GPIO_NUM_13); //pcb power
gpio_hold_en(GPIO_NUM_26); //tcrt power
gpio_deep_sleep_hold_en();
esp_sleep_wakeup_cause_t wakeReason = esp_sleep_get_wakeup_cause(); // 0 = BOOT, 3 = Wake by Push Button, 6 = Wake by ADC
switch(wakeReason){
case 0 : Serial.println("Reason 0 (boot)"); init_ulp_program(wakeReason); break;
case 3 : Serial.println("Reason 3 (pushbutton)"); init_ulp_program(wakeReason); break;
case 6 : Serial.println("Reason 6 (ADC)"); ulp_ADC_reading &= UINT16_MAX; Serial.println("ulp_ADC_reading: " + String(ulp_ADC_reading)); init_ulp_program(wakeReason); break;
}
start_ulp_program();
ESP_ERROR_CHECK(esp_sleep_enable_ulp_wakeup());
esp_sleep_enable_ext1_wakeup(BUTTON_PIN_BITMASK,ESP_EXT1_WAKEUP_ALL_LOW); //wake with pushbutton (BUTTON_PIN_BITMASK is 0x4000)
Serial.println("Going into sleep...");
esp_deep_sleep_start();
}
static void init_ulp_program(int wakeReason)
{
if (wakeReason == 0){ //load ULP program only once (when booting)
esp_err_t err = ulp_load_binary(0, ulp_main_bin_start,
(ulp_main_bin_end - ulp_main_bin_start) / sizeof(uint32_t));
ESP_ERROR_CHECK(err);
}
ulp_low_threshold = 2000;
ulp_high_threshold = 4096;
adc1_config_channel_atten(ADC1_CHANNEL_4, ADC_ATTEN_DB_11);
adc1_config_width(ADC_WIDTH_BIT_12);
adc1_ulp_enable();
/* Set ULP wake up period to 20ms */
ulp_set_wakeup_period(0, 20000);
}
static void start_ulp_program()
{
esp_err_t err = ulp_run((&ulp_entry - RTC_SLOW_MEM) / sizeof(uint32_t));
ESP_ERROR_CHECK(err);
}
@5.3.0nlumig,
Wow, you have persevered through this. Good on you!
I learned for your work. Thak you for taking the time to cover what has worked for you.
Have you tried to get this working with an ESP32-S3? I got the pulse example working with ESP32 but not with ESP32-S3.
I’m sorry, I don’t have a ESP32-S3 here… (never worked with it!)
Good luck!
Hello, how can I contact you? I have encountered the same problem and I cannot assemble. I would like to wake up through buttons and external registers
Hi everyone,
I’m replying to this thread because I have a similar problem.
platformio.ini
[env:esp32-s3]
platform = espressif32
board = esp32-s3-devkitc-1
framework = arduino
lib_deps =
paulstoffregen/OneWire@^2.3.7
milesburton/DallasTemperature@^3.11.0
xreef/EByte LoRa E220 library@^1.0.3
adafruit/DHT sensor library@^1.4.4
adafruit/Adafruit Unified Sensor@^1.1.13
plerup/EspSoftwareSerial
https://github.com/likeablob/ulptool-pio
extra_scripts =
pre:/$PROJECT_LIBDEPS_DIR/$PIOENV/ulptool-pio/pre_extra_script_ulptool.py
post:/$PROJECT_LIBDEPS_DIR/$PIOENV/ulptool-pio/post_extra_script_ulptool.py
lib_ldf_mode = chain+
upload_speed = 921600
build_flags =
#-DACTIVATE_SOFTWARE_SERIAL
-DFREQUENCY_868
-DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG
monitor_speed = 115200
upload_port = COM19
monitor_port = COM19
test_port = COM19
my terminal:
Resolving esp32-s3 dependencies...
Already up-to-date.
Updating metadata for the vscode IDE...
UserSideException: Processing esp32-s3 (platform: espressif32; board: esp32-s3-devkitc-1; framework: arduino)
--------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
*** missing SConscript file 'C:\\C:\\Users\\fabio\\Documents\\PlatformIO\\Projects\\abiot\\abiot-node-2.0\\.pio\\libdeps\\esp32-s3\\ulptool-pio\\pre_extra_script_ulptool.py'
File "C:\Users\fabio\.platformio\penv\Lib\site-packages\platformio\builder\main.py", line 167, in <module>
========================== [FAILED] Took 0.53 seconds ==========================
What can I do to solve the problem?
Sorry for the necro, I know this is three months later, I just thought this may help someone.
I don’t yet use PlatformIO for my projects, but the error you are getting could be due to your platformio.ini script.
I assume that removing the / immediately at the start of the extra script (pre and post) would fix the problem.
See for comparison in an apparent working code above (note the lack of / at the start of the pre and post):
I’m probably wrong though as GitHub - likeablob/ulptool-pio: A thin wrapper of ulptool for PlatformIO page includes the / in their examples.