Page 1 of 1

Not able to set GPIO level

Posted: Thu May 11, 2023 8:34 pm
by khu8rt
I have ESP32-C3-wroom-02 dev kit and i want to use a GPIO to set it high or low based on my requirement.
I tried the following code, but the GPIO18 is not changing

Code: Select all

#include <stdio.h>
#include "driver/gpio.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include <unistd.h>
#define LED_PIN 18

void app_main(void)
{
  gpio_set_direction(GPIO_NUM_18, GPIO_MODE_OUTPUT);
  int ON = 0;
while(true)
{
   ON = !ON;
   gpio_set_level(GPIO_NUM_18, ON);
   sleep(1);
}
}

Re: Not able to set GPIO level

Posted: Fri May 12, 2023 6:45 am
by ESP_Sprite
Use gpio_reset_pin() first.

Re: Not able to set GPIO level

Posted: Sat May 20, 2023 1:22 pm
by khu8rt
Great, thanks it worked!