GPIO - mriksman/esp-idf-homekit GitHub Wiki
GPIO
Simply setting the direction using gpio_set_direction(gpio_num, GPIO_MODE_###)
did not work for all pins. D5
(GPIO14
) and D6
(GPIO12
) would not work as an output. Instead, you must use the following method to configure and initialise a pin;
gpio_config_t io_conf = {0};
io_conf.mode = GPIO_MODE_OUTPUT;
io_conf.pin_bit_mask = (1ULL<<GPIO_NUM_14);
gpio_config(&io_conf);
The function (in gpio.c
) sets the direction and pullups, but it also seems to set up something called the 'Function Register' -- which is different depending on the GPIO number.
D0
(GPIO16
) is also a special case; it is the only pin to have an internal pull-down (but no pull-up). All other pins only have a pull-up. It is usually an RTC pin that allows the device to wake from deep sleep. No errors are thrown when trying to enable a pull-up on GPIO16
(or pull-down on the other pins), and the pin will be left floating.
Label | GPIO | Input | Output | Notes |
---|---|---|---|---|
D0 | GPIO16 | no internal pull-up | no PWM or I2C support | HIGH at boot. Used to wake up from deep sleep |
D1 | GPIO5 | OK | OK | Often used as SCL (I2C) |
D2 | GPIO4 | OK | OK | Often used as SDA (I2C) |
D3 | GPIO0 | pulled up | OK | Connected to FLASH button. Boot fails if pulled LOW |
D4 | GPIO2 | pulled up | OK | HIGH at boot. Connected to on-board LED. Boot fails if pulled low |
D5 | GPIO14 | OK | OK | SPI (SCLK) |
D6 | GPIO12 | OK | OK | SPI (MISO) |
D7 | GPIO13 | OK | OK | SPI (MOSI) |
D8 | GPIO15 | pulled to GND | OK | SPI (CS). Boot fails if pulled HIGH |
RX | GPIO3 | OK | RX pin | HIGH at boot |
TX | GPIO1 | TX pin | OK | HIGH at boot debug output at boot, boot fails if pulled LOW |
A0 | ADC0 | Analog Input | X |
GPIO15
has an external pull-down resistor on the development board, so you cannot use the internal pull-up resistor.GPIO0
andGPIO2
have an external pull-up resistor on the development board.GPIO0
is pulled high during normal operation, so you cannot use it as a Hi-Z input.GPIO2
cannot be low at boot, so you cannot connect a switch to it.GPIO0-15
all have a built-in pull-up resistor.GPIO16
has a built-in pull-down resistor.