Notifications
Clear all

ESP32 PWM Fan Controller Compile Errors

2 Posts
2 Users
0 Reactions
1,137 Views
(@daclap)
Member
Joined: 1 month ago
Posts: 1
Topic starter  

Hi everyone.

I am trying to recreate Bill's PWM fan controller but with an Arduino Uno Nano ESP32 instead of the Seeed but keep getting compile errors around the pwm configuration viz. ledcAttach and ledcWrite as follows -

------------------------------------------------------------------------

Arduino: 1.8.19 (Windows 10), Board: "Arduino Nano ESP32, With FAT partition (default), By GPIO number (legacy), Normal mode (TinyUSB)"

C:\Users\User\AppData\Local\Temp\arduino_modified_sketch_885013\sketch_dec16a.ino: In function 'void setup()':
sketch_dec16a:26:5: error: 'ledcAttach' was not declared in this scope
ledcAttach(PWM_PIN, PWM_FREQ, PWM_RESOLUTION);
^~~~~~~~~~
C:\Users\User\AppData\Local\Temp\arduino_modified_sketch_885013\sketch_dec16a.ino:26:5: note: suggested alternative: 'ledcAttachPin'
ledcAttach(PWM_PIN, PWM_FREQ, PWM_RESOLUTION);
^~~~~~~~~~
ledcAttachPin
exit status 1
'ledcAttach' was not declared in this scope

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

----------------------------------------------------------------------------------------

 

The more solutions I try from online reading regarding which commands have been retired and replaced and for which board etc. etc  more confused I get (sorry, beginner). I guess it's something to do with the different board but am stuck as to what to try next.

I would be grateful if anyone could guide me regarding what changes I would need to make to the two sketches involved to accommodate the different board and where I might find a cogent explanation of the whys and wherefores.

Thanks and happy holidays to all.

David   



   
Quote
(@harrya)
Member
Joined: 1 year ago
Posts: 6
 

Have you seen the info that contains:

The error 'ledcAttachPin' was not declared in this scope occurs when using the ESP32's LEDC (LED Control) API in Arduino IDE, typically due to changes in the ESP32 core library. Starting from version 3.x of the ESP32 library, the ledcAttachPin and ledcSetup functions have been replaced with a new API.

also:

The new API combines ledcSetup and ledcAttachPin into a single function called ledcAttach. Update your code as follows:

Corrected Code

#include <Arduino.h>

#define LEDC_PIN 12
#define LEDC_RESOLUTION 10

void setup() {
// Initialize LEDC with the updated API
ledcAttach(LEDC_PIN, 50, LEDC_RESOLUTION); // Set frequency to 50Hz, resolution to 10 bits
}
and:

Alternative: Downgrade ESP32 Core Library

If you prefer using the older API, you can downgrade the ESP32 board library to version 2.x via the Arduino IDE Board Manager.

By updating your code or reverting to an older library version, you can resolve this error and ensure compatibility with your ESP32 projects.



   
ReplyQuote