Not able to set GPIO level

khu8rt
Posts: 9
Joined: Sun Aug 21, 2022 10:42 pm

Not able to set GPIO level

Postby khu8rt » Thu May 11, 2023 8:34 pm

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);
}
}

ESP_Sprite
Posts: 9730
Joined: Thu Nov 26, 2015 4:08 am

Re: Not able to set GPIO level

Postby ESP_Sprite » Fri May 12, 2023 6:45 am

Use gpio_reset_pin() first.

khu8rt
Posts: 9
Joined: Sun Aug 21, 2022 10:42 pm

Re: Not able to set GPIO level

Postby khu8rt » Sat May 20, 2023 1:22 pm

Great, thanks it worked!

Who is online

Users browsing this forum: No registered users and 96 guests