I’m trying to get the BPI-Leaf-S3 onboard neo-pixel to blink with the esp-idf framework.
On the board there is printed “GPIO48” below the neo-pixel.
If I use the Arduino framework, it is working fine.
This is the Arduino code: (working) - esp-idf code follows…
#include <Arduino.h>
void setup() {
Serial.begin(115200);
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
digitalWrite(LED_BUILTIN, HIGH);
delay(500);
digitalWrite(LED_BUILTIN, LOW);
delay(500); // wait for a second
Serial.println(LED_BUILTIN);
}
LED_BUILTIN is defined in bpi_leaf_s3 > pins_arduino.h :
static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT+48;
#define LED_BUILTIN LED_BUILTIN
with SOC_GPIO_PIN_COUNT being:
#define SOC_GPIO_PIN_COUNT (49)
So LED_BUILTIN is 49+48 = 97 (unsigned?)
→ This code is working, the pixel blinks and prints 97 to the terminal.
This is the esp-idf code: (not working)
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#include "rom/gpio.h"
#include "sdkconfig.h"
#define BLINK_GPIO 97U
void app_main()
{
gpio_pad_select_gpio(BLINK_GPIO);
gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT);
while(1) {
printf("Turning off the LED\n");
gpio_set_level(BLINK_GPIO, 0);
vTaskDelay(1000 / portTICK_PERIOD_MS);
printf("Turning on the LED %d \n", BLINK_GPIO);
gpio_set_level(BLINK_GPIO, 1);
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}
→ This compiles, and I get “Turning on the LED 97” in the terminal, but the pixel is not blinking
I tried with 97 instead of 97U, but that makes no difference.
Any thoughts on what I’m doing wrong?
Thanks!