I have a ESP32- PWM sketch that control a motor that work just fine in a standalone (the code below). When I transfer this code to another sketch already full of other devices (IIC, SPI) then the PWM don't work anymore. Since my big sketch can turn the motor on and off using digitalWrite (HIGH / LOW) with no problem, I suspect my problem have to do with the PWM channel selection. My standalone sketch use PWM Channel 0 but maybe this channel is use by I2C or SPI. I also use RX0 and TX0 for serial communication?
My question is: Is there a way to know which one of the 16 PWM channel are available to use and which one are busy? Or maybe you think it is not related to my problem?
The working PWM sketch is here. The other code is very big for posting (I may post if require). The code below use channel 0. I also tried with channel 6 just to see. Even in this simple form, it don't work with channel 6. My device is a 38 pin ESP32 Wroom-32 (Dev. Board).
TEST CODE FOR PWM
// the PWM pin
const int ledPin = 25; // 25 corresponds to GPIO25
void setup(){
// configure PWM functionalitites
ledcSetup(0, 5000, 8); // Channel = 0 , Freq = 5000 and resolution = 8
// attach the channel to the GPIO
ledcAttachPin(ledPin, 0); (Channel = 0 here again)
}
void loop(){
ledcWrite(ledChannel, 255); // Pump max speed
delay(15000);
ledcWrite(ledChannel, 0); // Pump turn off
delay(15000);
ledcWrite(ledChannel, 125); // Pump half on
delay(15000);
ledcWrite(ledChannel, 0); // Pump off
delay(15000);
}
thank you