ESP32 control BLDC

Hi i am a nube and beg for help please.
Want to control my ESP32 with my Arduino IDE and it previosuly worked, did a library update this morning and now all kinds of errors.
Here's my code:

#include <ESP32Servo.h> // ESP32Servo library installed by Library Manager
#include "ESC.h" // RC_ESP library installed by Library Manager

#define ESC_PIN 26 // connected to ESC control wire
#define LED_BUILTIN 2 // not defaulted properly for ESP32s/you must define it

ESC myESC (ESC_PIN, 1000, 2000, 500); // ESC_Name (PIN, Minimum Value, Maximum Value, Arm Value)

void setup() {
    pinMode(ESC_PIN, OUTPUT);
    myESC.arm();
    delay(1000);
    myESC.speed(1000);
    delay(2000);
}

void loop() {
  myESC.speed(1000); // Stop the main motor
  delay(2000);

  myESC.speed(1250); // Stop the main motor
  delay(5000);

}

I did the RC_ESC thing where you change servo. h to #include <ESP32Servo.h> in ESC.h
but still get this 'ledcAttach' and 'ledcDetach' error.
I have deleted Arduino, re-stalled, remapped to https://dl.espressif.com/dl/package_esp32_index.json in prefferences and prayed...nothing helped!
what am i doing wrong?

here's the error:
WARNING: library RC_ESC claims to run on avr architecture(s) and may be incompatible with your current board which runs on esp32 architecture(s).
c:\Users\kraus\OneDrive\Documents\Arduino\libraries\ESP32Servo\src\ESP32PWM.cpp: In destructor 'virtual ESP32PWM::~ESP32PWM()':
c:\Users\kraus\OneDrive\Documents\Arduino\libraries\ESP32Servo\src\ESP32PWM.cpp:53:17: error: 'ledcDetachPin' was not declared in this scope; did you mean 'ledcDetach'?
53 | ledcDetachPin(pin);
| ^~~~~~~~~~~~~
| ledcDetach
c:\Users\kraus\OneDrive\Documents\Arduino\libraries\ESP32Servo\src\ESP32PWM.cpp: In static member function 'static double ESP32PWM::_ledcSetupTimerFreq(uint8_t, double, uint8_t)':
c:\Users\kraus\OneDrive\Documents\Arduino\libraries\ESP32Servo\src\ESP32PWM.cpp:60:16: error: 'ledcSetup' was not declared in this scope
60 | return ledcSetup(chan, freq, bit_num);
| ^~~~~~~~~
c:\Users\kraus\OneDrive\Documents\Arduino\libraries\ESP32Servo\src\ESP32PWM.cpp: In member function 'double ESP32PWM::setup(double, uint8_t)':
c:\Users\kraus\OneDrive\Documents\Arduino\libraries\ESP32Servo\src\ESP32PWM.cpp:150:17: error: 'ledcDetachPin' was not declared in this scope; did you mean 'ledcDetach'?
150 | ledcDetachPin(pin);
| ^~~~~~~~~~~~~
| ledcDetach
c:\Users\kraus\OneDrive\Documents\Arduino\libraries\ESP32Servo\src\ESP32PWM.cpp:151:30: error: 'ledcSetup' was not declared in this scope
151 | double val = ledcSetup(getChannel(), freq, resolution_bits);
| ^~~~~~~~~
c:\Users\kraus\OneDrive\Documents\Arduino\libraries\ESP32Servo\src\ESP32PWM.cpp:155:16: error: 'ledcSetup' was not declared in this scope
155 | return ledcSetup(getChannel(), freq, resolution_bits);
| ^~~~~~~~~
c:\Users\kraus\OneDrive\Documents\Arduino\libraries\ESP32Servo\src\ESP32PWM.cpp: In member function 'void ESP32PWM::adjustFrequencyLocal(double, double)':
c:\Users\kraus\OneDrive\Documents\Arduino\libraries\ESP32Servo\src\ESP32PWM.cpp:172:17: error: 'ledcDetachPin' was not declared in this scope; did you mean 'ledcDetach'?
172 | ledcDetachPin(pin);
| ^~~~~~~~~~~~~
| ledcDetach
c:\Users\kraus\OneDrive\Documents\Arduino\libraries\ESP32Servo\src\ESP32PWM.cpp:176:17: error: 'ledcAttachPin' was not declared in this scope; did you mean 'ledcAttach'?
176 | ledcAttachPin(pin, getChannel()); // re-attach the pin after frequency adjust
| ^~~~~~~~~~~~~
| ledcAttach
c:\Users\kraus\OneDrive\Documents\Arduino\libraries\ESP32Servo\src\ESP32PWM.cpp: In member function 'void ESP32PWM::attachPin(uint8_t)':
c:\Users\kraus\OneDrive\Documents\Arduino\libraries\ESP32Servo\src\ESP32PWM.cpp:237:17: error: 'ledcAttachPin' was not declared in this scope; did you mean 'ledcAttach'?
237 | ledcAttachPin(pin, getChannel());
| ^~~~~~~~~~~~~
| ledcAttach
c:\Users\kraus\OneDrive\Documents\Arduino\libraries\ESP32Servo\src\ESP32PWM.cpp: In member function 'void ESP32PWM::detachPin(int)':
c:\Users\kraus\OneDrive\Documents\Arduino\libraries\ESP32Servo\src\ESP32PWM.cpp:264:9: error: 'ledcDetachPin' was not declared in this scope; did you mean 'ledcDetach'?
264 | ledcDetachPin(pin);
| ^~~~~~~~~~~~~
| ledcDetach

exit status 1

Compilation error: exit status 1

See ledcSetup with ESP32 Core V3.0.0 not work

Hi @pinkpanthernow.

Explanation

There are significant breaking changes in the recently released version 3.0.0 of the "esp32" boards platform.

Some of these breaking changes caused a loss of compatibility with the "ESP32Servo" library you are using in your sketch:

https://github.com/espressif/arduino-esp32/blob/master/docs/en/migration_guides/2.x_to_3.0.rst#ledc

LEDC

The LEDC API has been changed in order to support the Peripheral Manager and make it easier to use, as LEDC channels are now automatically assigned to pins. For more information about the new API, check /api/ledc.

Removed APIs

  • ledcSetup
  • ledcAttachPin

The breakage is being tracked by the library developer here:

I see that some work has been done already on a fix for the breakage, but unfortunately has not been completed:

Resolution

The easiest solution will be to use a version of the "esp32" boards platform that is compatible with the ESP32Servo library.

The breaking changes in the "esp32" boards platform were introduced in the 3.0.0 release, so you won't have these problems compiling the library if you install an older version of the "esp32" platform.

  1. Select Tools > Board > Boards Manager... from the Arduino IDE menus.
    The "Boards Manager" dialog will open.
  2. Wait for the updates to finish, as shown by the messages printed at the bottom of the "Boards Manager" dialog.
  3. Scroll down through the list of boards platforms until you find the "esp32" entry. Click on it.
    A "Select version" dropdown will appear in the entry.
  4. Click on the "Select version" dropdown.
    It will expand.
  5. Select "2.0.17" from the menu.
  6. Click the "Install" button in the "esp32" entry.
  7. Wait for the installation to finish.
  8. Click the "Close" button on the "Boards Manager" dialog.
    The "Boards Manager" dialog will close.

Now compile your sketch again. Hopefully this time the error will not occur and the library will work as expected.


Arduino IDE will occasionally notify you that a new version of the boards platform is available, you'll need to refrain from accepting the offer that will cause an update back to the problematic version of the platform. If you find these notifications annoying, you can disable them via the IDE preferences.

I'll provide instructions you can follow to do that:

  1. Select File > Preferences... (or Arduino > Settings... for macOS users) from the Arduino IDE menus.
    The "Preferences" dialog will open.
  2. Uncheck the box next to "Check for updates on startup" in the "Preferences" dialog.
  3. Click the "OK" button.
    The "Preferences" dialog will close.

If you disable the automatic update check, make sure to periodically do a manual check for newer versions of the installed boards platforms and libraries that you want to keep updated. You can check for new versions of Arduino IDE by selecting Help > Check for Arduino IDE Updates from the Arduino IDE menus. You can check for new versions of boards platforms and libraries by selecting "Updatable" from the "Type" menu in the Boards Manager and Library Manager views.

2 Likes

Thank you! Really appreciated! worked!

You are welcome. I'm glad it is working now.

Regards,
Per

Here's a tip for those who like to keep all libraries up-to-date. When downgrading the ESP32 version, remember to also downgrade the ESP32Servo library. Based on my current tests, combining ESP32Servo 1.2.1 with the ESP32 board library 2.0.17 works.

I noticed that the developer of ESP32Servo mentioned this issue has been resolved in ESP32Servo 3.0.0, but I haven't had time to test it yet. I'll update this with my test results when I have time.

ESP32 with Core V 3.0.0

Using ledcAttach, ledcWriteNote, ledcWrite, ledcDetach, below my Code

Some known code parameter change..

Like channel replace Pin No(port No)

#define soundpin 4

void setup() {

  Serial.begin(115200);
  delay(6000);
  Serial.println("Buzzer Start");

  ledcAttach(soundpin,NOTE_A,7); //ledcAttach(uint8_tpin,uint32_tfreq,uint8_tresolution); for ESP core V3
  
  delay(115); 
  ledcWriteNote(soundpin,NOTE_A, 7);    // PIN, frequency, octave for ESP core V3
  delay(900);
  
  ledcWrite(soundpin,0); // No sound 
  ledcDetach(soundpin);  
  Serial.println("Buzzer Stop");
}

void loop() {

}