Exercise: Servo Motion with the Pico

../../../_images/IMG_2289-servo.jpg

The most convenient device for creating movement in the course kit is the hobby servo. These are feedback-controlled motors which move an output shaft to a specified angular position. The chief limitation is a limited range of travel, typically 180 degrees of rotation.

This exercise is primarily about programming style, the main objective to practice structuring a program as parameterized functions. But even though the focus is not on mechanical design, you are encouraged to rig up a simple moving apparatus using the servo, even with basic materials such as paper, tape, cardboard, or paper clips.

Objectives

After this exercise, you should be able to:

  1. Control a hobby servomotor module.

  2. Structure a scripted action sequence as parameterized functions.

  3. Write code with integrated debugging using the serial port for user console communication.

Reference Guides

Please review the following reference guides as needed:

Steps and observations

The overall objective is to create a choreographed servo movement using a program structured around parameterized functions.

  1. Please attach a single hobby servo to your Pico as described in the figures. Please wire carefully and pay attention to exact placement; the circuit is powered from your USB port, it would be best not to create any short circuits.

  2. Please write a CircuitPython program to generate patterned movements with the servo. You may wish to start with one of the sample programs. For this exercise, there is no prescribed user input, the movements will be performed autonomously over time.

  3. For this exercise, I require that your structure your program around parameterized functions. The best choices of structure depend upon your objectives, but here are some suggestions:

    1. Functions that produce a short motion sequence to use as a compositional phrase or primitive. The parameters might relate to position, rate, or repeat count.

    2. Functions that produce an algorithmically generated movement, i.e. one based on iterated calculations without scripting data.

    3. Functions that produce a pseudo-random motion (see CircuitPython random number module). The parameters might relate to the position, scale, tempo, or duration.

    4. Functions that produce stillness. It’s an artistic question whether that is pure motionlessness or an active quiet.

    5. Functions that represent larger units of choreography and only call motion primitive functions instead of directly issuing servo commands.

  4. Please implement your ideas in code, then test and iterate. Please add debugging output to the serial monitor as needed.

Deliverables

The result of your explorations should include:

  1. A brief paragraph describing your choreographic intent and outcome, submitted as per Documentation Procedure. This may be private if you prefer.

  2. A CircuitPython program, submitted as a properly-formatted block within the post. The program should implement a hobby-servo choreography controller, and be structured as multiple parameterized functions.

  3. A live in-class demo at the start of class on the due date.

Challenges

If you would like to explore more, please consider the following optional challenge questions.

  1. Can you construct a simple apparatus moved by the servo?

  2. Try adding additional servos with coordinated movements.

  3. Can you structure your program to issue commands to multiple servos asynchronously?

  4. Can you use a Python generator function to produce a sequence of servo angles?

Figures

../../../_images/IMG_2282-overall.jpg

A basic wiring setup for the exercise. The Pico has header pin row soldered on both sides. The red jumper wire in pin 40 (VBUS) connects the USB +5V to the servo red power input. The blue wire on pin 38 (GND) connects ground to the servo brown ground input. The yellow wire on pin 1 (GP0) connects the control signal to the servo orange signal input. Note that the jumper wire colors themselves are not critical, but consistency helps with recognizing mistakes.

../../../_images/IMG_2283-pico.jpg

Detail of the jumper wires connecting to the Pico. Each short row of five sockets on the breadboard connect together, so the jumpers wires connect to the adjacent Pico pin.

../../../_images/IMG_2288-wires.jpg

Detail of the jumper wires connecting to the hobby servo. The servo has a female socket header, so the jumpers wires can directly connect, albeit the retention is weak.

../../../_images/Pico-R3-SDK11-Pinout.png

Pin diagram of the Raspberry Pi Pico.