hello, im using ESP32 pico kit and i have to use ledc function to configurate four coreless motors,
i used this code and the Project compile correctly but ledc methodes stay in black and motors don't rotate.
can anyone help me?
const int A1 = 0;
const int A2 = 4;
const int D1 = 2;
const int D2 = 15;
const int freq = 5000;
const int A1CH = 1;
const int A2CH = 0;
const int D1CH = 2;
const int D2CH = 3;
const int resolution = 16;
void setup() {
ledcSetup(A1CH, freq, resolution);
ledcSetup(A2CH, freq, resolution);
ledcSetup(D1CH, freq, resolution);
ledcSetup(D2CH, freq, resolution);
ledcAttachPin(A1, A1CH);
ledcAttachPin(A2, A2CH);
ledcAttachPin(D1, D1CH);
ledcAttachPin(D2, D2CH);
}
void loop() {
for(int i=100;i<255;i=i+5)
{
ledcWrite(A1CH,i);
ledcWrite(A2CH,i);
ledcWrite(D1CH,i);
ledcWrite(D2CH,i);
delay(10);
}
}
I consider using the ESP32 ledc API to control motors is 2nd best. The better option would be to use the ESP32 MCPWM, the code looks harder but the motor control is much better. If you search on this site, you can find where I have posted my MCPWM code using the Arduino IDE, which should get you started.