GPIOs work in Arduino, but not Espressif-IDE!?

ignisuti
Posts: 42
Joined: Wed Nov 15, 2023 1:29 pm

GPIOs work in Arduino, but not Espressif-IDE!?

Postby ignisuti » Thu Jan 30, 2025 2:54 am

I'm using the Espressif-IDE (Eclipse) with custom hardware.

I could only get some of the GPIOs to work. So, I inspected the hardware and found no errors. I then inspected the firmware and also found no errors. I next decided to go back to Arduino and all the LEDs on my hardware were proven functional. My next step was to go back to the Espressif-IDE and use the Blink example (eliminating the RTOS from my project). I took that simple example and added all my LEDs. Same as before! Only some of them work!!!

Can someone please help me understand this? I'm against a timeline and need to resolve this quickly and I really don't want to use Arduino...

Sprite
Espressif staff
Espressif staff
Posts: 10636
Joined: Thu Nov 26, 2015 4:08 am

Re: GPIOs work in Arduino, but not Espressif-IDE!?

Postby Sprite » Thu Jan 30, 2025 6:55 am

Show your code, and tell us which GPIOs you are talking about. I'd normally check my crystal ball to divine those things, but unfortunately it's got a crack in it and needs to be repaired, so you'll have to do the tedious task of actually telling us *in detail* what you tried so we can replicate it if needed.

ignisuti
Posts: 42
Joined: Wed Nov 15, 2023 1:29 pm

Re: GPIOs work in Arduino, but not Espressif-IDE!?

Postby ignisuti » Thu Jan 30, 2025 1:36 pm

Here is the modified Blink example that I am currently using.
-GPIOs 36, 37, & 38 blink as expected.
-GPIO 39 is Dim as if it was receiving a 50% PWM signal.
-GPIOs 40, 41, & 42 remain OFF.

Again, hardware has been proven. All these LEDs work when I use similar code in Arduino.

Code: Select all

/* Blink Example

   This example code is in the Public Domain (or CC0 licensed, at your option.)

   Unless required by applicable law or agreed to in writing, this
   software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
   CONDITIONS OF ANY KIND, either express or implied.
*/
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#include "esp_log.h"
#include "led_strip.h"
#include "sdkconfig.h"

static const char *TAG = "example";

/* Use project configuration menu (idf.py menuconfig) to choose the GPIO to blink,
   or you can edit the following line and set a number here.
*/
#define BLINK_GPIO CONFIG_BLINK_GPIO

static uint8_t s_led_state = 0;

static void configure_led(void)
{
    ESP_LOGI(TAG, "Example configured to blink GPIO LED!");

    gpio_set_direction(36, GPIO_MODE_OUTPUT);
    gpio_set_direction(37, GPIO_MODE_OUTPUT);
    gpio_set_direction(38, GPIO_MODE_OUTPUT);
    gpio_set_direction(39, GPIO_MODE_OUTPUT);
    gpio_set_direction(40, GPIO_MODE_OUTPUT);
    gpio_set_direction(41, GPIO_MODE_OUTPUT);
    gpio_set_direction(42, GPIO_MODE_OUTPUT);
}

void app_main(void)
{

    /* Configure the peripheral according to the LED type */
    configure_led();

    while (1) {
        ESP_LOGI(TAG, "Turning the LED %s!", s_led_state == true ? "ON" : "OFF");
        gpio_set_level(36, s_led_state);
        gpio_set_level(37, s_led_state);
        gpio_set_level(38, s_led_state);
        gpio_set_level(39, s_led_state);
        gpio_set_level(40, s_led_state);
        gpio_set_level(41, s_led_state);
        gpio_set_level(42, s_led_state);
        
        
        s_led_state = !s_led_state;
        vTaskDelay(CONFIG_BLINK_PERIOD / portTICK_PERIOD_MS);
    }
}

chegewara
Posts: 2505
Joined: Wed Jun 14, 2017 9:00 pm

Re: GPIOs work in Arduino, but not Espressif-IDE!?

Postby chegewara » Thu Jan 30, 2025 2:15 pm

Using only "gpio_set_direction" to configure pin may not be enough.
You should check how to configure pins with more complex API or at least to use "gpio_reset_pin" before it.

ignisuti
Posts: 42
Joined: Wed Nov 15, 2023 1:29 pm

Re: GPIOs work in Arduino, but not Espressif-IDE!?

Postby ignisuti » Thu Jan 30, 2025 2:36 pm

chegewara,
That was the solution! Thank you for providing a quick and professional response.

Who is online

Users browsing this forum: ChatGPT-User and 2 guests