From a9944f5a473d4797b16e1a2fdb2570eff5f04e68 Mon Sep 17 00:00:00 2001 From: mattmcw Date: Tue, 30 Jan 2024 00:12:36 -0500 Subject: [PATCH] Caught the error that was making me think I broke my ESP32 dev boards. The ledcWrite() duty cycle was not being set on the pwmChannel. This is intended for LEDS but I don't know if it matters that it's being used for a variable speed DC motor. --- ino/esp32_dc_motor_poc/esp32_dc_motor_poc.ino | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/ino/esp32_dc_motor_poc/esp32_dc_motor_poc.ino b/ino/esp32_dc_motor_poc/esp32_dc_motor_poc.ino index 3279f70..89ecaf6 100644 --- a/ino/esp32_dc_motor_poc/esp32_dc_motor_poc.ino +++ b/ino/esp32_dc_motor_poc/esp32_dc_motor_poc.ino @@ -14,7 +14,7 @@ int enable1Pin = 14; const int freq = 30000; const int pwmChannel = 0; const int resolution = 8; -int dutyCycle = 200; +int dutyCycle = 250; void setup() { // sets the pins as outputs: @@ -28,6 +28,8 @@ void setup() { // attach the channel to the GPIO to be controlled ledcAttachPin(enable1Pin, pwmChannel); + ledcWrite(pwmChannel, dutyCycle); + Serial.begin(115200); // testing @@ -59,15 +61,4 @@ void loop() { digitalWrite(motor1Pin2, LOW); delay(1000); - // Move DC motor forward with increasing speed - digitalWrite(motor1Pin1, HIGH); - digitalWrite(motor1Pin2, LOW); - while (dutyCycle <= 255){ - ledcWrite(pwmChannel, dutyCycle); - Serial.print("Forward with duty cycle: "); - Serial.println(dutyCycle); - dutyCycle = dutyCycle + 5; - delay(500); - } - dutyCycle = 200; }