Problems with PWM when programming ESP32

Hello everyone! I see that only Mr. @wayland and Mr. @gweimer have been active lately. I managed to connect esp32 to xod. Tested the work with LCD and OLED displays, everything works. The buzzer also works. But there is a problem with the PWM node. I really hope for your help, because I am sure that the problem can be solved)). I use ESP32 wroom 32. Before compiling, I select “ESP32 Dev Module”. If I try to light the built-in LED at the GPiO2 output simply with the digital-write node, everything works. I was also able to dim the LED using a digital write node and square waves. When trying to do this through a node with PWM, an error occurs at the stage of code compilation:

C:\Users\Samsung\AppData\Local\Temp\xod_temp_sketchbookZfmaeU\libraries\ESP32Servo\src\ESP32PWM.cpp: In destructor ‘virtual ESP32PWM::~ESP32PWM()’:
C:\Users\Samsung\AppData\Local\Temp\xod_temp_sketchbookZfmaeU\libraries\ESP32Servo\src\ESP32PWM.cpp:50:17: error: ‘ledcDetachPin’ was not declared in this scope; did you mean ‘ledcDetach’?
50 | ledcDetachPin(pin);
| ^~~~~~~~~~~~~
| ledcDetach

C:\Users\Samsung\AppData\Local\Temp\xod_temp_sketchbookZfmaeU\libraries\ESP32Servo\src\ESP32PWM.cpp: In static member function ‘static double ESP32PWM::_ledcSetupTimerFreq(uint8_t, double, uint8_t)’:
C:\Users\Samsung\AppData\Local\Temp\xod_temp_sketchbookZfmaeU\libraries\ESP32Servo\src\ESP32PWM.cpp:57:16: error: ‘ledcSetup’ was not declared in this scope
57 | return ledcSetup(chan, freq, bit_num);
| ^~~~~~~~~

C:\Users\Samsung\AppData\Local\Temp\xod_temp_sketchbookZfmaeU\libraries\ESP32Servo\src\ESP32PWM.cpp: In member function ‘double ESP32PWM::setup(double, uint8_t)’:
C:\Users\Samsung\AppData\Local\Temp\xod_temp_sketchbookZfmaeU\libraries\ESP32Servo\src\ESP32PWM.cpp:148:17: error: ‘ledcDetachPin’ was not declared in this scope; did you mean ‘ledcDetach’?
148 | ledcDetachPin(pin);
| ^~~~~~~~~~~~~
| ledcDetach

C:\Users\Samsung\AppData\Local\Temp\xod_temp_sketchbookZfmaeU\libraries\ESP32Servo\src\ESP32PWM.cpp:149:30: error: ‘ledcSetup’ was not declared in this scope
149 | double val = ledcSetup(getChannel(), freq, resolution_bits);
| ^~~~~~~~~

C:\Users\Samsung\AppData\Local\Temp\xod_temp_sketchbookZfmaeU\libraries\ESP32Servo\src\ESP32PWM.cpp:153:16: error: ‘ledcSetup’ was not declared in this scope
153 | return ledcSetup(getChannel(), freq, resolution_bits);
| ^~~~~~~~~

C:\Users\Samsung\AppData\Local\Temp\xod_temp_sketchbookZfmaeU\libraries\ESP32Servo\src\ESP32PWM.cpp: In member function ‘void ESP32PWM::adjustFrequencyLocal(double, float)’:
C:\Users\Samsung\AppData\Local\Temp\xod_temp_sketchbookZfmaeU\libraries\ESP32Servo\src\ESP32PWM.cpp:170:17: error: ‘ledcDetachPin’ was not declared in this scope; did you mean ‘ledcDetach’?
170 | ledcDetachPin(pin);
| ^~~~~~~~~~~~~
| ledcDetach

C:\Users\Samsung\AppData\Local\Temp\xod_temp_sketchbookZfmaeU\libraries\ESP32Servo\src\ESP32PWM.cpp:174:17: error: ‘ledcAttachPin’ was not declared in this scope; did you mean ‘ledcAttach’?
174 | ledcAttachPin(pin, getChannel()); // re-attach the pin after frequency adjust
| ^~~~~~~~~~~~~
| ledcAttach

C:\Users\Samsung\AppData\Local\Temp\xod_temp_sketchbookZfmaeU\libraries\ESP32Servo\src\ESP32PWM.cpp: In member function ‘void ESP32PWM::attachPin(uint8_t)’:
C:\Users\Samsung\AppData\Local\Temp\xod_temp_sketchbookZfmaeU\libraries\ESP32Servo\src\ESP32PWM.cpp:235:17: error: ‘ledcAttachPin’ was not declared in this scope; did you mean ‘ledcAttach’?
235 | ledcAttachPin(pin, getChannel());
| ^~~~~~~~~~~~~
| ledcAttach

C:\Users\Samsung\AppData\Local\Temp\xod_temp_sketchbookZfmaeU\libraries\ESP32Servo\src\ESP32PWM.cpp: In member function ‘void ESP32PWM::detachPin(int)’:
C:\Users\Samsung\AppData\Local\Temp\xod_temp_sketchbookZfmaeU\libraries\ESP32Servo\src\ESP32PWM.cpp:256:9: error: ‘ledcDetachPin’ was not declared in this scope; did you mean ‘ledcDetach’?
256 | ledcDetachPin(pin);
| ^~~~~~~~~~~~~
| ledcDetach

Error during build: exit status 1
Compilation failed
Command Process exited with code 1
The generated C++ code contains errors. It can be due to a bad node implementation or if your board is not compatible with XOD runtime code. The original compiler error message is above. Fix C++ errors to continue. If you believe it is a bug, report the problem to XOD developers.
username or email
password
Select a node or patch to view
[/quote]

Only a few IO pins support PWM, and which pins those are vary by Arduino model. Are you using a pin that explicitly supports PWM? If some of the pin labels on the board include a tilda (~), those are pins supporting PWM; otherwise, you will need to refer to documentation for your specific model.

1 Like

Dear @gweimer, Thank you for your reply! As I mentioned, the error occurs during compilation, the output I chose is supported. However, the standard pwm-write node itself does not work. As a way out of the situation, I created a simple PWM analogue from standard nodes and a digital-write. And it works! I checked with an oscilloscope, everything is fine. This is not the best solution to the problem, but I will use it for now.))
https://xod.io/libs/nazarijtipusak080/universal-pwm/

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