I am working my way through the “Learn ESP32 with Arduino IDE” course. All units have compiled without problem up to Module 2, Unit 3 (“ESP32 Pulse-Width Modulation (PWM)”. In particular the WiFi Scan test runs without problems.
Compile is giving me the following error message “C:\Data\Random Nerd ESP32 Course\My Sketches\av_analog_dimming_1\av_analog_dimming_1.ino: In function ‘void setup()’:
C:\Data\Random Nerd ESP32 Course\My Sketches\av_analog_dimming_1\av_analog_dimming_1.ino:14:3: error: ‘ledcSetup’ was not declared in this scope
14 | ledcSetup(ledChannel, freq, resolution);
| ^~~~~~~~~
C:\Data\Random Nerd ESP32 Course\My Sketches\av_analog_dimming_1\av_analog_dimming_1.ino:17:3: error: ‘ledcAttachPin’ was not declared in this scope; did you mean ‘ledcAttach’?
17 | ledcAttachPin(ledPin, ledChannel);
| ^~~~~~~~~~~~~
| ledcAttach
exit status 1
Compilation error: ‘ledcSetup’ was not declared in this scope.
The same error message is given for the second code example (three leds).
I have copied the code from the course without alteration.
My set up is as follows :-
Arduino IDE 2.3.2
Running as “Board ESP32 Dev Module” on Port (Com 11)
Device manager shows “Silicon Labs CP210x USB to UART Bridge (Com 11)
Board “ESP-WROOM-32”
USB/UART chip “SI CP2102”
Hi.
There was a recent update of the ESP32 boards add-on in Arduino IDE.
The new version, version 3, introduced some breaking changes. So, there are many codes that used to work that don’t work at the moment.
Meanwhile, we recommend you downgrade your boards installation to guarantee compatibility with our current projects.
Go to Tools > Boards > Boards Manager, search for ESP32. Downgrade to version 2.0.17.
The code should compile without problems.
Let me know if you can solve the issue.
If you prefer to use the newest version, you need to make some changes to the code.
You can now use analogWrite() to output a PWM signal. Pass as argument the GPIO, and the duty cycle.
void analogWrite(uint8_t pin, int value);
If using the ledcWrite() function, it now accepts only two arguments (the GPIO and the duty cycle).
bool ledcWrite(uint8_t pin, uint32_t duty);
You no longer need to assign a PWM channel. It will be automatically attributed. If you want to assign a specific PWM channel, use ledcAttachChannel().
bool ledcAttachChannel(uint8_t pin, uint32_t freq, uint8_t resolution, int8_t channel);
More info about this here: https://randomnerdtutorials.com/esp32-migrating-version-2-to-3-arduino/
Thanks for your patience.
Regards,
Sara
Thank you Sara. I had the same problem with compiling. ‘ledc…’
I was perplexed to find that even the examples wouldn’t compile. I hope there was a good reason for the change that would seem to break old code under maintenance.
Thanks also for giving us the new prototypes, and the method of going back to the earlier version.