Skip to content

Servo — channel initialization (servo_init)

What it does: Initializes the selected servo channel (servo1 to servo8) on the given pin and optionally reverses the direction.

servo_init

Inputs

  • Field ID: servo channel number (1 to 8).
  • pin: GPIO pin number for servo signal.
  • Field reverse direction of rotation: direction reversal option (True/False).

Output

  • None (statement block).

When to use it

  • At the beginning of the program before all blocks servo_angle, set_servo_speed, set_servo_us.
  • When you use multiple servers at the same time and want to separate them by ID.

Tips and pitfalls

  • When using drives, also use a block to stop them when you press the STOP button in ESP IDE. Block: Execute this code on program exit
  • Power the servo with a separate source. 3.3V is used to power the processor, not as a power supply voltage for motors and servos. The GPIO pin serves only as a control signal.
  • reverse direction of rotation is useful when the servo is mechanically mounted in reverse, or we use two servos mirrored next to each other.

Usage example

example_servo_angle

Open example in ESP IDE

Generated Python example

servo1 = Servo(Pin(18), reverse=True)