Waving puppet
This project is based on my daughter’s paper puppet she brought back from daycare. The idea behind this project is to have a build that is easy to accomplish for kids and is meant as an introduction to electronics. It does not require having access to fancy equipment such as a 3D printer or that sort of thing. All the components that form the structure of the build are common materials you can find in a household.
The first version of the build will use the following electronic materials:
- The Raspberry Pi Pico. I recommend ordering the variant with pre-soldered headers. It is not much more expensive and it will greatly lower the barrier of entry for this build. The Raspberry Pi Pico comes with a micro USB cable which you will use to connect to your host machine for coding.
- A servo motor which will create the activation of the arm.
- Jumper wires to connect the Raspberry Pi with the servo motor.
- A breadboard for prototyping.
Wiring and Program
Before doing any wiring, it is important to get familiar with the basics of the GPIO. The most important part is the boxes annotated green starting with GP
followed by a number. These represent the pin numbers we will use to interface with the Pico in the software. A recommended read if you want to get further is this tutorial.
Connect your servo motor to the Raspberry Pi using the following configuration:
Connect your Raspberry Pi Pico with the USB controller to your host machine and fire up the Thonny Python code editor. If this is the first time doing so, you will have to flash the bootrom with MicroPython. This procedure is described here.
In the code editor, enter the following block of code and press the “Run current script” button, selecting the Raspberry Pi Pico as a target:
from machine import Pin, PWM, ADC
import utime
import math
servo = PWM(Pin(0))
servo.freq(50)
min_servo = 1500
max_servo = 3500
range_servo = max_servo - min_servo # 2000
mean_servo = min_servo + (range_servo / 2) # 2500
def control_servo():
modifier = math.sin(utime.ticks_ms() / 100) # between -1 and 1
value = mean_servo + (modifier * (range_servo / 2))
servo.duty_u16(int(value))
while True:
control_servo()
utime.sleep(0.001)
If everything works correctly, you should have a servo motor moving continuously between two angles similar to the animation below:
The Puppet
For the puppet creation, anything made out of cardboard such as packaging box. However, an essential piece for this build is to get some fasteners for the articulations of the arms, legs, and head.