Can I use "Boot" button as a GPIO push button after program is loaded onto flash in ESP32?
Can I use "Boot" button as a GPIO push button after program is loaded onto flash in ESP32?
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?
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.
For a schematic of the ESP32 Core Board V2, see this thread.
-
- 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?
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?
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?
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?
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?
-
- 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?
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)); // Пауза для избежания зацикливания
}
}
-
- Posts: 9723
- 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?
You can't ESP_LOGI in an interrupt handler. Use ESP_EARLY_LOGI instead.
Who is online
Users browsing this forum: Bing [Bot] and 275 guests