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

nmtrivedi
Posts: 6
Joined: Wed Jan 04, 2017 2:10 pm

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

Postby nmtrivedi » Wed Jan 04, 2017 2:21 pm

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?

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

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

Postby ESP_Angus » Wed Jan 04, 2017 8:46 pm

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.

DrMickeyLauer
Posts: 168
Joined: Sun May 22, 2022 2:42 pm

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

Postby DrMickeyLauer » Mon Jan 22, 2024 11:07 am

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?

boarchuz
Posts: 606
Joined: Tue Aug 21, 2018 5:28 am

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

Postby boarchuz » Mon Jan 22, 2024 11:54 am

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?

aliakseika
Posts: 2
Joined: Wed Oct 18, 2023 7:35 am

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

Postby aliakseika » Sun Mar 10, 2024 10:42 am

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)); // Пауза для избежания зацикливания
  }
}

ESP_Sprite
Posts: 9764
Joined: Thu Nov 26, 2015 4:08 am

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

Postby ESP_Sprite » Mon Mar 11, 2024 5:47 am

You can't ESP_LOGI in an interrupt handler. Use ESP_EARLY_LOGI instead.

Who is online

Users browsing this forum: Bing [Bot] and 174 guests