Skip to content

Latest commit

 

History

History
152 lines (94 loc) · 3.71 KB

008_motor_tutorials.md

File metadata and controls

152 lines (94 loc) · 3.71 KB

Motor

Table of Contents

Prolog

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.

Control servo via duty

The first option to steer the servo motor in a range of 90° is duty.

Requirements

  • mandatory 1x servo motor (example: SG90 or SG92R)
  • few cables
  • optional a breadboard

Example

sg90.jpg

Circuit

011_circuit_diagram_servo_motor.png

Code

# 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.

Control servo via duty_ns

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.

Requirements

... same as previous example ...

Circuit

... same as previous example ...

Code

# 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.

Control servo via duty_u16

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.

Requirements

... same as first example ...

Circuit

... same as first example ...

Code

# 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.

Control servo via angle

The fourth option to steer the servo motor is to use angle. The circuit stays the same only the code is slightly adjusted.

Requirements

... same as first example ...

Circuit

... same as first example ...

Code

# 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.

Home | Previous | Next