- Prolog
- Control servo via duty
- Control servo via duty_ns
- Control servo via duty_u16
- Control servo via angle
Now bring some movement into the game. Again, PWM` is used here. When experimenting with servos, be careful not to overdrive them! I had to get new ones after they broke very quickly.
The first option to steer the servo motor in a range of 90° is duty
.
- mandatory 1x servo motor (example: SG90 or SG92R)
- few cables
- optional a breadboard
Example
# create new subdirectory
$ mkdir -p ~/Projects/ESP/examples/motor
# create script
$ touch ~/Projects/ESP/examples/motor/servo_duty.py
Source Code for
servo_duty.py
Check your circuit and copy the script to the microcontroller as main.py
.
# copy file into pyboard as main.py
(venv) $ rshell -p [SERIAL-PORT] cp examples/motor/servo_duty.py /pyboard/main.py
# start repl
(venv) $ rshell -p [SERIAL-PORT] repl
Start with keys Control
+ d
. To leave the REPL, press keys Control
+ x
.
The second option to steer the servo motor in a range of 90° is duty_ns
. The circuit stays the same only the code is slightly adjusted.
... same as previous example ...
... same as previous example ...
# create script
$ touch ~/Projects/ESP/examples/motor/servo_duty_ns.py
Source Code for
servo_duty_ns.py
Check your circuit and copy the script to the microcontroller as main.py
.
# copy file into pyboard as main.py
(venv) $ rshell -p [SERIAL-PORT] cp examples/motor/servo_duty_ns.py /pyboard/main.py
# start repl
(venv) $ rshell -p [SERIAL-PORT] repl
Start with keys Control
+ d
. To leave the REPL, press keys Control
+ x
.
The third option to steer the servo motor in a range of 90° is duty_u16
. The circuit stays the same only the code is slightly adjusted.
... same as first example ...
... same as first example ...
# create script
$ touch ~/Projects/ESP/examples/motor/servo_duty_u16.py
Source Code for
servo_duty_u16.py
# copy file into pyboard as main.py
(venv) $ rshell -p [SERIAL-PORT] cp examples/motor/servo_duty_u16.py /pyboard/main.py
# start repl
(venv) $ rshell -p [SERIAL-PORT] repl
Start with keys Control
+ d
. To leave the REPL, press keys Control
+ x
.
The fourth option to steer the servo motor is to use angle. The circuit stays the same only the code is slightly adjusted.
... same as first example ...
... same as first example ...
# create script
$ touch ~/Projects/ESP/examples/motor/servo_angle.py.py
Source Code for
servo_angle.py
# copy file into pyboard as main.py
(venv) $ rshell -p [SERIAL-PORT] cp examples/motor/servo_angle.py /pyboard/main.py
# start repl
(venv) $ rshell -p [SERIAL-PORT] repl
Start with keys Control
+ d
. To leave the REPL, press keys Control
+ x
.