#include "driver/gpio.h"



Input Pins

Combined method
	const gpio_config_t InputPin = {
		.pin_bit_mask = BIT64(GPIO_NUM_4),
		.mode = GPIO_MODE_INPUT,
		.pull_up_en = GPIO_PULLUP_ENABLE,

	if (gpio_get_level(GPIO_NUM_4))
		//Do something
Individual functions method
	gpio_set_direction(GPIO_NUM_4, GPIO_MODE_INPUT);
	if (gpio_get_level(GPIO_NUM_4))
		//Do something



Output Pins

//Normal output
	gpio_set_direction(GPIO_NUM_4, GPIO_MODE_OUTPUT);
	gpio_set_level(GPIO_NUM_4, 1);		//Set high
	gpio_set_level(GPIO_NUM_4, 0);		//Set low

//Using a define example:
#define MY_IO_PIN_NAME(state)			(state ? gpio_set_level(GPIO_NUM_4, 1) : gpio_set_level(GPIO_NUM_4, 0))

//Open drain output
	gpio_set_direction(GPIO_NUM_4, GPIO_MODE_OUTPUT_OD);

	gpio_set_direction(GPIO_NUM_4, GPIO_MODE_INPUT_OUTPUT_OD);

//Set drive capability
	gpio_set_drive_capability(GPIO_NUM_4, GPIO_DRIVE_CAP_DEFAULT);
		//GPIO_DRIVE_CAP_0 (weak)
		//GPIO_DRIVE_CAP_1 (stronger)
		//GPIO_DRIVE_CAP_2 (medium)
		//GPIO_DRIVE_CAP_3 (strongest)

Disable Pins

	gpio_set_direction(GPIO_NUM_4, GPIO_MODE_DISABLE);

We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.


Your email address will not be published. Required fields are marked *