Help me find a solution to the issue

#include <WiFi.h>
#include <Firebase_ESP_Client.h>

/* 1. Define the WiFi credentials */
#define WIFI_SSID "ALHN-141E"
#define WIFI_PASSWORD "A5cNt3UnKX"

/* 2. Define the API Key */
#define API_KEY "AIzaSyA-wGe7dkPYmPMDxw4KzT5qPrWksU7QvTQ"

/* 3. Define the RTDB URL */
#define DATABASE_URL "https://testproject1-172ba-default-rtdb.firebaseio.com/"

/* 4. Define the user Email and password that already registered or added in your project */
#define USER_EMAIL "khaled.benhadouga@univ-bba.dz"
#define USER_PASSWORD "12345678"

// Define Firebase Data object
FirebaseData fbdo;

FirebaseAuth auth;
FirebaseConfig config;

unsigned long sendDataPrevMillis = 0;

// Define LED pin and channel
const int ledPin = 25;
const int pwmChannel = 0; // PWM Channel for LED
const int pwmFrequency = 5000; // Frequency for PWM
const int pwmResolution = 8; // Resolution for PWM (0-255 for 8 bits)

void setup()
{
// Configure LED PWM functionality
ledcSetup(pwmChannel, pwmFrequency, pwmResolution);
ledcAttachPin(ledPin, pwmChannel);

Serial.begin(115200);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);

Serial.print("Connecting to Wi-Fi");
while (WiFi.status() != WL_CONNECTED)
{
Serial.print(".");
delay(300);
}
Serial.println();
Serial.print("Connected with IP: ");
Serial.println(WiFi.localIP());
Serial.println();

/* Assign the api key (required) */
config.api_key = API_KEY;

/* Assign the user sign-in credentials */
auth.user.email = USER_EMAIL;
auth.user.password = USER_PASSWORD;

/* Assign the RTDB URL (required) */
config.database_url = DATABASE_URL;

Firebase.reconnectNetwork(true);

fbdo.setBSSLBufferSize(4096, 1024);
fbdo.setResponseSize(2048);

Firebase.begin(&config, &auth);

Firebase.setDoubleDigits(5);

config.timeout.serverResponse = 10 * 1000;
}

void loop()
{
if (Firebase.ready() && (millis() - sendDataPrevMillis > 1000 || sendDataPrevMillis == 0))
{
sendDataPrevMillis = millis();

int brightness;
if (Firebase.RTDB.getInt(&fbdo, "/led/brightness", &brightness))
{
  // Map brightness value to PWM range (0-255)
  brightness = constrain(brightness, 0, 255);
  ledcWrite(pwmChannel, brightness);
  Serial.print("Brightness set to: ");
  Serial.println(brightness);
}
else
{
  Serial.print("Error reading brightness: ");
  Serial.println(fbdo.errorReason().c_str());
}

}
}

C:\Users\Administrator\AppData\Local\Temp.arduinoIDE-unsaved20241124-8868-1azfnha.0les\sketch_dec24b\sketch_dec24b.ino: In function 'void setup()':
C:\Users\Administrator\AppData\Local\Temp.arduinoIDE-unsaved20241124-8868-1azfnha.0les\sketch_dec24b\sketch_dec24b.ino:35:3: error: 'ledcSetup' was not declared in this scope
35 | ledcSetup(pwmChannel, pwmFrequency, pwmResolution);
| ^~~~~~~~~
C:\Users\Administrator\AppData\Local\Temp.arduinoIDE-unsaved20241124-8868-1azfnha.0les\sketch_dec24b\sketch_dec24b.ino:36:3: error: 'ledcAttachPin' was not declared in this scope; did you mean 'ledcAttach'?
36 | ledcAttachPin(ledPin, pwmChannel);
| ^~~~~~~~~~~~~
| ledcAttach
Multiple libraries were found for "SD.h"
Used: C:\Users\Administrator\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.7\libraries\SD
Not used: C:\Users\Administrator\AppData\Local\Arduino15\libraries\SD
Not used: C:\Users\Administrator\Documents\Arduino\libraries\SD
exit status 1

Compilation error: 'ledcSetup' was not declared in this scope

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'


Use code tags (the < CODE/ > icon above the compose window) to make it easier to read and copy for examination

https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum

Please post your sketch, using code tags when you do
Posting your code using code tags prevents parts of it being interpreted as HTML coding and makes it easier to copy for examination

In my experience the easiest way to tidy up the code and add the code tags is as follows
Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help.

Surely that code is for the v2.x API of the ESP32 core and you are using v3.x which has changes and no longer supports ledcSetup() and other related statements.
Look

1 Like

Roll back the Espressif ESP32 board entry to 2.0.17.

Thank you very much for your help. The issue has been fixed.

Are you done now, or will you start another post concerning the ESP32, titled "Find a solution" with the solution a fallback board support package?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.