Page 1 of 1

Can I use "Boot" button as a GPIO push button after program is loaded onto flash in ESP32?

Posted: Wed Jan 04, 2017 2:21 pm
by nmtrivedi
I am new to ESP32 platform. I have ESP32_Core_board_v2 which doesn't have any dedicated Push Button GPIO on board. I can attach external switch with the GPIO pins but I want to use "Boot" button as push button GPIO meaning if I press it while the program is running, it will call registered call back function and I can do the required stuff there. Is this possible with ESP32 board that I have?

Re: Can I use "Boot" button as a GPIO push button after program is loaded onto flash in ESP32?

Posted: Wed Jan 04, 2017 8:46 pm
by ESP_Angus
Yes, BOOT is GPIO0 (HIGH when released, LOW when pressed) so you can use it like any other GPIO, and use the GPIO driver functions to connect an interrupt.

For a schematic of the ESP32 Core Board V2, see this thread.

Re: Can I use "Boot" button as a GPIO push button after program is loaded onto flash in ESP32?

Posted: Mon Jan 22, 2024 11:07 am
by DrMickeyLauer
We have used a similar design in that we double the functionality of the boot button to be a user button.

Now I wonder about the GPIO level readings... I was under the assumption that you need to debounce every button, but the boot button seems to not bounce. Is that a feature of the devkit or the recommended circuitry or pure luck?

Re: Can I use "Boot" button as a GPIO push button after program is loaded onto flash in ESP32?

Posted: Mon Jan 22, 2024 11:54 am
by boarchuz
There's nothing special about GPIO0 in this respect, so I would expect some bouncing from the tactile switch. There may be a capacitor which will filter out a bit of noise, but it may also cause boot issues so most designs exclude it.
Even if this particular switch is very well-behaved you shouldn't rely on this behaviour. To be sure, are you using an oscilloscope to visualise this (lack of) bouncing?

Re: Can I use "Boot" button as a GPIO push button after program is loaded onto flash in ESP32?

Posted: Sun Mar 10, 2024 10:42 am
by aliakseika
Could you give an example of working code for using the boot button? Unfortunately, I just can't get it to work. I am attaching my code

Code: Select all

#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#include "esp_log.h"
static const char *TAG = "button_example";
// Обработчик прерывания для кнопки
static void IRAM_ATTR button_isr_handler(void* arg) {
  int gpio_num = (int) arg;
  ESP_LOGI(TAG, "Button pressed on GPIO %d", gpio_num);
}

void app_main() {
  // Настройка GPIO для кнопки
  gpio_config_t button_config = {
    .pin_bit_mask = (1ULL << GPIO_NUM_0),
    .mode = GPIO_MODE_INPUT,
    .pull_up_en = GPIO_PULLUP_ENABLE,
    .intr_type = GPIO_INTR_NEGEDGE // Прерывание по низкому уровню
};
  gpio_config(&button_config);
  // Установка обработчика прерывания для кнопки
  gpio_install_isr_service(0);
  gpio_isr_handler_add(GPIO_NUM_0, button_isr_handler, (void*) GPIO_NUM_0);
  while (1) {
    vTaskDelay(pdMS_TO_TICKS(100)); // Пауза для избежания зацикливания
  }
}

Re: Can I use "Boot" button as a GPIO push button after program is loaded onto flash in ESP32?

Posted: Mon Mar 11, 2024 5:47 am
by ESP_Sprite
You can't ESP_LOGI in an interrupt handler. Use ESP_EARLY_LOGI instead.