ESP32 Plus and FAN libraries

Hello.
I have a esp32 plus board. I have connected a fan. It have 4 pin IN-, IN+, V and G.
On board i have conected IN- to io18, IN+ to io19 and when i compiled a example from my smarthome kit i get a error. I use arduino ide 2.3.4. I have tested with another analogwrite libraries but it doesnt words.
This is code:


#include <analogWrite.h>
#define fanPin1 19
#define fanPin2 18

void setup() {
  pinMode(fanPin1, OUTPUT);
  pinMode(fanPin2, OUTPUT);
}

void loop() {
  digitalWrite(fanPin1, LOW); //pwm = 0
  analogWrite(fanPin2, 180);
  delay(3000);
  digitalWrite(fanPin1, LOW);
  digitalWrite(fanPin2, LOW);
  delay(1000);
  digitalWrite(fanPin1, HIGH); //pwm = 255
  analogWrite(fanPin2, 210);
  delay(3000);
  digitalWrite(fanPin1, LOW);
  digitalWrite(fanPin2, LOW);
  delay(1000);

}

And this is error i get:

c:\Users\Pepe\Documents\Arduino\libraries\ESP32_AnalogWrite\analogWrite.cpp: In function 'int analogWriteChannel(uint8_t)':
c:\Users\Pepe\Documents\Arduino\libraries\ESP32_AnalogWrite\analogWrite.cpp:44:9: error: 'ledcSetup' was not declared in this scope
44 | ledcSetup(channel, _analog_write_channels[i].frequency, _analog_write_channels[i].resolution);
| ^~~~~~~~~
c:\Users\Pepe\Documents\Arduino\libraries\ESP32_AnalogWrite\analogWrite.cpp:45:9: error: 'ledcAttachPin' was not declared in this scope; did you mean 'ledcAttach'?
45 | ledcAttachPin(pin, channel);
| ^~~~~~~~~~~~~
| ledcAttach

exit status 1

Compilation error: exit status 1

Can you help me?
Thanks.

Hi @jopeme. The error you are encountering when compiling the "ESP32_AnalogWrite" library are caused by breaking changes introduced in version 3.0.0 of the "esp32" boards platform.

However, this isn't a problem because the "esp32" platform's core now provides an analogWrite function. So you don't need to use the ESP32_AnalogWrite library anymore.

So just delete this line from your sketch:

Then try compiling or uploading again. This time there should not be any error.

1 Like

Which version of the ESP32 board files do you have installed ?

The ledc functionality was changed in recent versions which has caused problems

Sounds like you're the victim of the change in the ESP32 boards package from version 2.x to 3.x. And the analogWrite library that you're using is not compatible with that change; any reason to use a specific library?

Your code compiles with ESP32 board package 3.1.0 for and ESP32 Dev module (I do not know which board you have selected, I could not find a ESP32 plus) if you remove the line #include <analogWrite.h>.

Thanks to all for your answers.


I use ESP32 Dev Module.

Thanks a lot. Now it works if i don't use analogwrite.h library. I have use a code from example of my smarthome kit ks5009.
It is incredible that there are these errors in the manufacturer's own code.
Regards

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

Regards, Per

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