# Problems with PWM when programming ESP32

**URL:** <https://forum.xod.io/t/problems-with-pwm-when-programming-esp32/6947>\
**Category:** XOD Programming Questions\
**Created:** [August 27, 2024, 10:16pm UTC](https://forum.xod.io/t/problems-with-pwm-when-programming-esp32/6947 "2024-08-27T22:16:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nazarijtipusak080](https://avatars.discourse-cdn.com/v4/letter/n/7c8e57/32.png) [@nazarijtipusak080](https://forum.xod.io/u/nazarijtipusak080)\
**Post date:** [August 27, 2024, 10:16pm UTC](https://forum.xod.io/t/problems-with-pwm-when-programming-esp32/6947/1 "2024-08-27T22:16:54Z")

</div>

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]

---

<div class="post-metadata">

**Author:** ![gweimer](https://avatars.discourse-cdn.com/v4/letter/g/a9adbd/32.png) [@gweimer](https://forum.xod.io/u/gweimer)\
**Post date:** [August 28, 2024, 1:22pm UTC](https://forum.xod.io/t/problems-with-pwm-when-programming-esp32/6947/2 "2024-08-28T13:22:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![nazarijtipusak080](https://avatars.discourse-cdn.com/v4/letter/n/7c8e57/32.png) [@nazarijtipusak080](https://forum.xod.io/u/nazarijtipusak080)\
**Post date:** [August 28, 2024, 2:43pm UTC](https://forum.xod.io/t/problems-with-pwm-when-programming-esp32/6947/3 "2024-08-28T14:43:32Z")

</div>

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/](https://xod.io/libs/nazarijtipusak080/universal-pwm/)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex027/uploads/xod/original/1X/eb7348baa04192c2ef932d1db54d44f09f8a7888.png) [@system](https://forum.xod.io/u/system)\
**Post date:** [September 27, 2024, 2:43pm UTC](https://forum.xod.io/t/problems-with-pwm-when-programming-esp32/6947/4 "2024-09-27T14:43:34Z")

</div>

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