ESP-IDF: Wie man GPIO als Ausgang mit aktiviertem Pulldown konfiguriert

Das folgende Beispiel konfiguriert GPIO12 als Ausgang mit aktiviertem integrierten Pulldown-Widerstand unter Verwendung der ESP-IDF-API.

esp32_gpio_pulldown.cpp
#include <driver/gpio.h>

gpio_config_t io_conf;
// Disable interrupt
io_conf.intr_type = GPIO_INTR_DISABLE;
// Set as output mode
io_conf.mode = GPIO_MODE_OUTPUT;
// Bit mask of the pins that you want to set
io_conf.pin_bit_mask = (1ULL << GPIO_NUM_12);
// Set to pull-down in case of floating => fix boot
io_conf.pull_down_en = GPIO_PULLDOWN_ENABLE;
// Disable pull-up mode
io_conf.pull_up_en = GPIO_PULLUP_DISABLE;
// Configure GPIO with the given settings
gpio_config(&io_conf);

Check out similar posts by category: ESP32, ESP-IDF, C/C++