Skip to content

Commit 578bea2

Browse files
committed
servo fix
1 parent 8d70934 commit 578bea2

File tree

1 file changed

+10
-4
lines changed
  • docs/_sections/_guide-primaries/sensors-and-actuators

1 file changed

+10
-4
lines changed

docs/_sections/_guide-primaries/sensors-and-actuators/actuators.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ To control a DC motor using the ESP32, a motor controller, and battery pack (**W
5252

5353
<img src="{{ '/_assets/images/DRV8833withDCMotor.png' | prepend: site.baseurl }}" alt="motor_with_external_power.png">
5454

55-
* Note that the wire polarity on the motor does not matter because DC motors' spin direction is based on the direction of current flowing through them.
55+
* Note that the wire polarity on the motor does not matter because DC motors' spin direction is based on the direction of current flowing through them. This direction is controlled by the H-bridge motor driver.
5656

5757
<br>
5858

5959
| Motor Controller Terminal | ESP32 Pin |
6060
|:-------------|:------------------|
61-
| 5V | 5V |
61+
| VCC | 5V |
6262
| IN1 | Any PWM enabled pin |
6363
| IN2 | Any PWM enabled pin |
6464

@@ -92,6 +92,8 @@ void loop() {
9292
digitalWrite(IN2, LOW);
9393

9494
delay(1000); // Stop for 1 second
95+
96+
vTaskDelay(1); // Yield CPU to not starve other ESP32 processes and cause WDT reset
9597
}
9698
```
9799
Again, more detailed information about the DRV8833 motor controllers can be [found here!](https://lastminuteengineers.com/drv8833-arduino-tutorial/)
@@ -102,7 +104,7 @@ Again, more detailed information about the DRV8833 motor controllers can be [fou
102104

103105
## What Are Servos?
104106

105-
Servos are motors that are designed for precise position control. Instead of freely rotating when powered, servos listen to a control signal (usually [PWM](https://learn.sparkfun.com/tutorials/pulse-width-modulation/all)) to determine where to rotate. Some servos offer limited rotation (like 0°–180°), while others can rotate continuously (like ours). More advanced servos have other ways to be even more precise such as a feedback system on top of the control signal, but that is not necessary for this competition.
107+
Servos are motors that are designed for precise position control. Instead of freely rotating when powered, servos listen to a control signal (usually [PWM](https://learn.sparkfun.com/tutorials/pulse-width-modulation/all)) to determine where to rotate. Some servos rotate continuously, while others rotate with a fixed angle range (like ours). More advanced servos have other ways to be even more precise such as a feedback system on top of the control signal, but that is not necessary for this competition.
106108

107109
## How to Use Servos?
108110

@@ -132,11 +134,15 @@ Servo myServo;
132134

133135
void setup() {
134136
myServo.attach(12);
135-
myServo.write(1750);
136137
}
137138

138139
void loop() {
140+
myServo.write(0); // Rotate to 0 degrees
141+
delay(1000); // Delay 1000 ms
142+
myServo.write(180); // Rotate to 180 degrees
143+
delay(1000);
139144

145+
vTaskDelay(1); // Yield CPU to not starve other ESP32 processes and cause WDT reset
140146
}
141147
```
142148

0 commit comments

Comments
 (0)