Skip to content

DC motor — driver initialization (dc_motor_init)

What it does: Initializes an H-bridged DC motor using the dcmotorlib library on a pair of pins and sets the direction orientation.

dc_motor_init

Inputs

  • Field motor_name: Engine ID (1 to 6).
  • Field direction of rotation: motor rotation direction (normal / reverse).
  • pin1: first control pin.
  • pin2: second control pin.

Output

  • None (statement block).

When to use it

  • Before first setting block speed dc_motor_speed.
  • When configuring multiple motors with different pins.

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
  • Control the DC motor via a suitable H‑bridge/driver, not directly from the GPIO.
  • If the motor rotates in reverse, you can change direction of rotation instead of switching wires.

Usage example

example_dc_motor

Open example in ESP IDE

Generated Python example

dc_mot1 = dcmotorlib.DCMotor(26, 27, 0)