Skip to content

servo module

doomke edited this page Sep 2, 2023 · 8 revisions

Description

Uses the PWM controler of the ESP32 to drive a servo motor. Handles initialization, position control and speed limitation.

Settings

setting type default range description
pin integer 26 > 0 number of the pin connected to the control input of the servo
frequency integer 50 > 0 frequency (in $\text{Hz}$) of the PWM signal for the servo
channel integer 3 (0, 15) channel of the ESP32 pwm controller [1]
minDuty integer 1000 ≥ 0 minimum duty time (in µs) per PWM cycle
maxDuty integer 2000 > 0 maximum duty time (in µs) per PWM cycle
minAngle float 0.0 minimum of the range used to control the servo[2]
maxAngle float 90.0 maximum of the range used to control the servo[2]
maxSpeed float 0.0 ≥ 0 maximum speed at which the motor moves from one position to the next[3]
initial float 0.0 (minAngle, maxAngle) position on the value range that the motor will drive to on initialization
infoLED String "" ID of an LED, module will attempt to send commands to the LED to indicate when changes have been made by a user[4]
  1. Some PWM channels might be in use by other hardware: Do not use channels 0 and 1 if a camera module is present on the same ESP32. When attaching more than one pin to a channel, both pins will deliver the same signal.
  2. The value range (minAngle,maxAngle) can be chosen freely and adjusted to suit the purpose. For example a symmetric 90° range (-45,45) or a percent range (0,100) can be used.
  3. Speed limit does not apply to first initialization, where the motor moves as fast as possible. Unit of measurement is that of the value range per second. Value of 0 means as fast as possible.
  4. Defaults to an empty String, in which case no attempts to operate the LED will be made.

Command Keys

key type range description
move integer move the specified distance on the value range starting from the current position
moveTo integer (minAngle, maxAngle) move to the specified position on the value range (absolute position)
binaryCtrl boolean move to minAngle if false and to maxAngle if true
hold hold keep motor powered after movement if true
identify integer > 0 highlight the hardware by its LED[4] for the specified time (in ms)
  1. infoLED must be assigned, otherwise no LED will light up

Status

"controlId":"pinhole",
"status":
{
    "busy":false,
    "absolute":90,
    "relative":100
}
  • busy – boolean, true if the motor is currently moving to a new position
  • absolute – integer, current position of the motor on the value scale
  • relative – float, current position of the motor as percentage of the total range

Events

  • busy – occurs when the motor starts moving
  • ready – occurs when the motor is done moving

General

Guides

Principle of Operation

Modules

Software Hardware
camera camera
infoLED infoLED
input input
macro macro
output output
servo servo
socket socket
stepper stepper
WiFi wifi

Clone this wiki locally