Okay, with the help of a friend I got it working now
No Idea WHY exactly this is, but here is the corresponding platform.ini code:
platform = espressif32@~3.5.0 ; There is a newer version, 5.1.1, but it somehow doesn't boot. Might need to change SPIFFS or partition tables. //platform = espressif32@~3.5.0
board = esp32dev
framework = arduino
upload_speed = 921600 ; The upload baud rate
monitor_speed = 115200 ; The serial (monitor) baud rate
board_build.flash_mode = qio
board_build.partitions = min_spiffs.csv
board_build.filesystem = spiffs
lib_deps =
https://github.com/powelllens/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
With this, the code compiles and works!
BUT: now comes the thing that also didn’t work when I was still programming in the Arduino-IDE
I use the code below to put the ESP32 in sleep and wake on 2 things:
- if a button is pushed
- if the ADC measures a value that is below ulp_low_threshold (in my case 2000)
if (EnableSleep){
esp_sleep_wakeup_cause_t wakeReason = esp_sleep_get_wakeup_cause(); // 0 = BOOT, 3 = Wake by Push Button, 6 = Wake by ADC
if (wakeReason != ESP_SLEEP_WAKEUP_ULP){
Serial.println(String(wakeReason));
} else {
ulp_ADC_reading &= UINT16_MAX;
Serial.println("ulp_ADC_reading: " + String(ulp_ADC_reading));
Serial.println(String(wakeReason));
}
if (wakeReason == 0 || wakeReason == 6){
init_ulp_program(wakeReason);
}
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)
{
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;
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();
//if (wakeReason == 0 || wakeReason == 6){
adc1_config_channel_atten(ADC1_CHANNEL_4, ADC_ATTEN_DB_11);
adc1_config_width(ADC_WIDTH_BIT_12);
adc1_ulp_enable();
//}
}
static void start_ulp_program()
{
esp_err_t err = ulp_run((&ulp_entry - RTC_SLOW_MEM) / sizeof(uint32_t));
ESP_ERROR_CHECK(err);
}
Both work. So I can wake the processor with ADC and with the pushbutton. BUT: if it wakes with the pushbutton, then the ADC doesn’t work anymore. So if it’s going back to sleep, I can’t wake it with ADC, but only with the button…
I tried sooooo many things/settings/code changes/whatever: I can’t get the ADC working anymore after pushing the button. This also didn’t work in the Arduino IDE. I even have paid people on Fivver (or Upwork, didn’t remind it anymore) for this, but they also couldn’t get this working
It there a chance that you know the solution?
Thanks / best regards,
Stephan