LEARN.PARALLAX.COM
Published on LEARN.PARALLAX.COM (https://learn.parallax.com)

Home > Servo Spirit Project

Servo Spirit Project

Have you ever killed a servo?  This animated servo spirit - spooky or sweet - might come back to haunt you!  This project uses most of the parts in the Parallax Animation Kit - Limited Edition. Though it is and minimalistic and quick to put together, the approach and code are easy to repurpose for other projects.  

This project shows photos from a spooky spirit with a single eyeball and streamer draped arms, and also an angelic spirit with gauze-draped wings.

Parts List

  • (1) Animation Kit - Limited Edition (#910-28088) [1]
  • (1) Propeller Activity Board WX (#32912) [2]
  • Thin, stiff wire for arms and legs (I used Whisker Wires, #700-00056)
  • Plastic streamers, ribbons, or fabric
  • Translucent white, hollow plastic eyeball, or a white ping-pong ball and markers
  • Small plastic cylinder for a neck (I used an LED standoff)
  • External power, such as a 7.5 VDC, 1.6 A supply (#750-00009) [3]
  • Electrical tape
  • Silver sharpie for labeling electrical tape tags (or some other labeling stuff)

Tools Used

  • Hot glue gun
  • #1 Phillips screwdriver
  • Diagonal cutters
  • Soldering iron and solder

For your protection practice safe handling of sharp tools. When working with hot glue, and tools with moving parts, always wear safety glasses!

 

Servo Spirit Body

The body of the Servo Spirit is made from the two Parallax Standard Servos in the Animation Kit. The hollow, transluscent plastic eyeball serves as a head, backlit by the Neopixel ring.

  • Plug in your hot glue gun so it warms up while you prepare the servos.
  • Remove the horns from both servos, and save the screws.
  • Cut off opposite arms on each servo horn so you have two straight horns - one will be the shoulders and the other the hips.

  • Put a horn back on each servo’s spline, but don’t screw it in yet.
  • Gently twist a from one end of its range to the other, then move the horn until it is in the middle of its range.
  • Carefully pull off the horn, and then put it back on its spline so it sticks out to both sides of the servo case, then attach with the screw.
  • Glue the bottoms of the servos together so the cords are facing the same way.
  • Glue the neck on top of the servos, as far from the servo horn shoulders as you can.
  • Glue the eyeball/head onto the neck. You can have it turned toward the servo horn for arms like the spooky Servo Youkai below, or away from the servo horn for wings.

  • Carefully solder a male-male jumper wire into each of the four thru-holes on the neopixel ring.

  • Gently hold the ring against the back of the eyeball, and gather the wires together and press them against the servo case.
  • Adjust the wire lengths so the tension pushes the ring against the eyeball, and secure the wires together and to the case with electrical tape.
  • Run the servo and neopixel ring wires through the mounting holes to keep them tidy, and secure with electrical tape.

  • Make wire arms that loop firmly through a couple of holes in the shoulders servo horn so they stick out to the sides - these will be the arms.
  • Make wire legs that loop through the outermost holes in the hips servo horn,  letting them dangle freely.

  • Attach streamers, ribbons, or fabric to the top wires. Here I used gauze for wings.

 

Wiring it Up

There is no need to build circuits on the breadboard for this project. Instead, it takes advantage of the Activity Board WX's 3-pin headers for the servos, and its D/A socket to drive the magnetic speaker.

Propeller I/O pin connections

  • Neopixel ring Data out - P0
  • Neopixel ring Data input - P1
  • Speaker - D/A 0 (P26)
  • PIR Rev B - P3
  • Hip servo - P15
  • Shoulder servo - P17

  • With power to the board turned OFF, make sure your servo port power jumpers are set to 5 V.
  • Plug the hip servo cable into the P15 servo header, and the shoulder servo cable into the P17 servo header.
  • Connect one speaker lead to the D/A 0 socket, the other to GND - there's no + or - pins, either will do.
  • Connect the PIR sensor to to P3, 5V, and GND.
  • Connect the Neopixel ring Data out to P0, Data input to P1, 5 VDC to 5V, and GND to GND.

Which wire is which? Before you wrap your jumper wires together with electrical tape, get your code built and tested, and then label each wire. This is especially handy if you plugged two wires together of different colors to make a longer lead.

 

Program with Spooky Sounds

If you used an eyeball and are going for a scary theme, as I did with mine, you might like this Servo Youkai code—download it below.

Project60123-Servo-Youkai.svg [4]

  • Open the project in BlocklyProp Solo, connect your board to your computer with the USB cable, and make sure the Launcher is running and can see the board's COMM port.
  • Connect the external power supply to your your Activity Board WX, since the USB power does not supply enough current to run the servos.
  • With the 2-position switch in position 1 to disable the servos, save the code to EEPROM.
  • Hold up your Servo Youkai so the shoulders and hips can swivel freely, then put the switch in Position 2 and watch it spook!

How the Code Works

The code’s first task is to initialize the RGB LEDs. The rest of the code is in a repeat forever block.

This outermost infinite loop holds a repeat while check pin 3 block that monitors the PIR sensor. If motion is detected the PIR sends a high signal, and so this block returns a 1 (true) and the loop executes.

Once the PIR sensor detects motion, the first task is to set a color for the RGB LEDs,  and then use the RGB-LED update block to turn them on. (It is really easy to forget that block and suspect your wiring job for no reason...)

Next, a repeat item block counts from 45 to 135 using a variable named up. The value of up increments the servo angles to swivel hips and shoulders. A frequency block scales the value of up into an audible range for the speaker, sending the signal to P26 (D/A 0 socket).

Then, another repeat item loop does much the same thing with a variable named down. This time however,  down is subtracted from 180 to set the servo angles, so they start at 135 where they left off in the previous loop. Likewise, the frequency block both scales the value of down and subtracts it from 3375, the maximum frequency reached in the previous repeat item loop.

If the PIR sensor is no longer sensing motion, code execution exits the repeat while loop. Then the RGB-LED set and RGB-LED update blocks turn off the Neopixel ring. Your Servo Spirit is still, quiet, and dark until it senses motion again.

Program with a Sweet Song

If you are going for something sweet, the Servo Angel code download below might be a good choice. Instead of a scary sound effect, it plays the first 8 notes in a tune called Antioch, perhaps better known as the carol "Joy To The World."  You can change the note frequencies and durations for any tune you like; see the Circuit Practice with BlocklyProp - Piezo Beep tutorial [5] for more information.

Project63292-Servo-Angel.svg [6]

  • Download the Servo Angel project file above.
  • Open the project in BlocklyProp Solo [7], connect your board to your computer with the USB cable, and make sure the Launcher is running and can see the board's COMM port.
  • Connect the external power supply to your your Activity Board WX, since the USB power does not supply enough current to run the servos.
  • With the 2-position switch in position 1 to disable the servos, save the code to EEPROM.
  • Hold up your Servo Spirit so the shoulders and hips can swivel freely, then put the switch in Position 2.

How the Code Works

First, the code initializes and fills up two arrays with 8 elements each. JoyNotes holds a list of frequencies that will be played in order on the speaker.  JoyTime holds a list of durations that determines how long to play each note, in milliseconds.  These values will be used in the Sing function to play the tune.

Next, the code initializes the RGB LEDs in the Neopixel ring, noting it has 12 LEDs and its input is connected to P1.

Before we get to the main code, a new processor block launches the function "Sing." It goes in its own processor so the speaker can play the notes at the same time the servos move.

The rest of the code is in a repeat forever loop.  First thing in the loop, the check PIN 3 block checks if the PIR sensor has detected motion. If it has, a 1 is stored in the PIR variable.

Next is an if...do condition. If the PIR variable holds a 1, the RGB LED set and RGB LED update blocks turn on the Neopixel ring. That is followed by two repeat loops. The first repeat item block counts from 45 to 135 using the variable named up. The value of up increments the servo angles to swivel hips and shoulders. The second repeat item block does much the same thing with a variable named down. This time however,  down is subtracted from 180 to set the servo angles, so they start at 135 where they left off in the previous loop.  The pause 20 in each block sets the appropriate servo signal refresh rate.

Afer the servos are done moving, or if the PIR variable was holding a 0 instead of a 1, the code executes the lower RGB LED set and RGB LED update blocks turn off the Neopixel ring. Then, the code starts over at the top of the repeat forever loop.

Meanwhile the Sing function is executing its own repeat forever loop in a separate processor.  It also holds an if...do condition that starts by checking if the PIR variable holds a 1. If it does, a repeat loop increments the PlayJoy variable from 0 to 7, making 8 trips through the loop.  PlayJoy is used as an index to select values from the JoyTime and JoyNotes arrays for the frequency block.  PlayJoy starts at 0, because arrays start counting elements at zero, not at 1!

DISCUSSION FORUMS | PARALLAX INC. STORE

About | Terms of Use | Feedback: learn@parallax.com | Copyright©Parallax Inc. 2021


Source URL: https://learn.parallax.com/tutorials/language/blocklyprop/servo-spirit-project

Links
[1] http://www.parallax.com/product/910-28088
[2] http://www.parallax.com/product/32912
[3] http://www.parallax.com/product/750-00009)
[4] https://learn.parallax.com/sites/default/files/content/AB-Blockly/Projects/Servo-Youkai/Project60123-Servo-Youkai.svg
[5] http://learn.parallax.com/tutorials/language/blocklyprop/circuit-practice-blocklyprop/piezo-beep
[6] https://learn.parallax.com/sites/default/files/content/AB-Blockly/Projects/Servo-Youkai/Project63292-Servo-Angel.svg
[7] https://solo.parallax.com/