Overview

Amazon's playful boxes

Amazon recently started shipping boxes that include graphics which can be cut out and turned into masks. This project takes it a step further and repurposes the entire box to create an animatronic panda friend.

For this project, most any rectangular shipping box will work, but an A3 box seems to have just the right proportions.

If you don't have an Amazon box that has these graphics, do not fear! Drawing whatever you like with a sharpie pen does the trick just as well. You can create any animal you want!

We have the technology

This project pairs CRICKIT and Circuit Playground Express with two servo motors.

1 x Circuit Playground Express
Circuit Playground Express is the perfect introduction to electronics and programming
1 x Adafruit CRICKIT for Circuit Playground Express
Creative Robotics and Interactive Construction Kit is an add-on to our popular Circuit Playground Express that lets you #MakeRobotFriend using CircuitPython
1 x TowerPro SG-5010 Servo
High-torque standard servo can rotate approximately 180 degrees (90 in each direction)
1 x Micro Servo
This little servo can rotate approximately 180 degrees (90 in each direction). Works just like standard servos you're used to but smaller.
1 x 5V 2A (2000mA) switching power supply
Power supply that gives a clean regulated 5V output at up to 2000mA, 110 or 240 input
1 x USB cable - A/MicroB - 3ft
Standard A to micro-B USB cable

Other supplies you will need

The other supplies can be found around the home. Along with a box you will need:

  • Scissors
  • Double-sided tape
  • String or fishing line (~20 inches long)

The box will be flipped on one end with the top flap folded down and the other three flaps bent outwards.

Create your Panda

Cut out the legs

These legs can be as simple or as fancy as you want. Two hemispheres will do, or you can add extra features like claws!

Cut out the arms

These arms will attach to a servo motor and flap back and forth. Make them as simple or as complicated as you like.

Cut out the face

Cut out and tape your panda face to a scrap length of cardboard. This piece of cardboard will hold out and suspend the panda face in front of the box. Tape this face to the top of the box.

Add a door

Use a spare piece of scrap cardboard to tape a door to the front of your panda. This will create a space to store your CRICKIT.

Add Electronics

Now it's time to add electronics to the panda!

Cut a rectangular hole in the back of the box.

 

Insert servo housing into cardboard.

Cut another rectangular hole in front flap of the box.

 

Insert second servo motor into this hole.

 

The fit should be fairly tight so it doesn't fall out accidentally.

 

 

Synchronized Servos

CRICKIT can control up to four servos at once! For this project we will only need two. We will use Mu to upload the CircuitPython code to Circuit Playground Express and control both servos simultaneously.

If you have not used Mu before, this is the guide on how to install it

For a quick primer on using CircuitPython and Servos, it is recommended to read through this learn guide as well.

Connect your servos to CRICKIT as shown in the diagram below. Be sure the yellow wire faces the edge of the CRICKIT board and the brown/black wire faces the Circuit Playground Express.

Making Connections

Use fishing line or string to tie a loop around your panda's arms.

 

Tie the other end to the tip of the servo hub. This will pull the arms back and forth in a flapping motion.

Use double sided tape to affix servo hub to piece of cardboard.

 

Press hub onto servo motor.

Cut a small square hole in the base of the box.

 

This will allow you to feed 5V power into the box.

 

Connect 5V power to your CRICKIT board.

Uploading Code with Mu

But first...

To use Circuit Playground Express and CRICKIT together, you'll first need to install the special 'seesaw' version of the CPX firmware. This guide will take you through how to install CRICKIT support onto your circuit playground express.

Adafruit recommends editing your code in the Mu Editor which is super simple to use and has features to help us code and see results. See this guide on installing Mu.

Once you have completed this step you're ready to move on.

Testing 1...2...3...

Follow these three steps to get your motors turning

1) Connect Circuit Playground Express to your computer with a micro USB cable

 

2) Copy & paste the code below into the Mu Editor

 

3) Press the Save button in Mu - your code should be saved to the CIRCUITPY disk drive (which appears when the Circuit Playground Express is plugged into your computer) as code.py. If you name the program something else, like panda.py, the Circuit Playground Express won't automatically run it, that's why it's named code.py.

# Code for the Trash Panda tutorial with Adafruit Crickit and Circuit Playground Express
import time
import board
from digitalio import DigitalInOut, Direction
from adafruit_crickit import crickit

# built in LED
led = DigitalInOut(board.D13)
led.direction = Direction.OUTPUT

# TowerPro servos like 500/2500 pulsewidths, make the wings flap a full 180
crickit.servo_1.set_pulse_width_range(min_pulse=500, max_pulse=2500)
crickit.servo_2.set_pulse_width_range(min_pulse=500, max_pulse=2500)

print("Its TRASH PANDA TIME!")

while True:
    print("tick")
    led.value = True
    crickit.servo_1.angle = 0
    time.sleep(0.5)
    crickit.servo_2.angle = 180
    time.sleep(1.0)

    print("tock")
    led.value = False
    crickit.servo_1.angle = 180
    time.sleep(0.5)
    crickit.servo_2.angle = 0
    time.sleep(1.0)

How The Code Works

We start by importing all our helper libraries

Download: file
# Code for the Trash Panda tutorial with Adafruit Crickit and Circuit Playground Express
import time
import board
from digitalio import DigitalInOut, Direction
from adafruit_crickit import crickit

We'll use the little red LED on the CPX to let us know visually what it's up to, so set that up as an output

Download: file
# built in LED
led = DigitalInOut(board.D13)
led.direction = Direction.OUTPUT

We get from the crickit library access to the Servo #1 and Servo #2 ports, where we have our servos plugged in. The TowerPro servos we're using work best with a 500us to 2500us pulse width, so we let the servo objects know that.

Download: file
# TowerPro servos like 500/2500 pulsewidths
crickit.servo_1.set_pulse_width_range(min_pulse=500, max_pulse=2500)
crickit.servo_2.set_pulse_width_range(min_pulse=500, max_pulse=2500)

Finally, in our loop we go through a cycle of setting the crickit.servo_1 and crickit.servo_2 angles from 0 to 180 with delays. Try changing those time.sleep() delays to speed up or slow down the movement of your panda! But note, if you try to go too fast, the servo won't have time to move all the way.

We blink the LED so you can see what part of the loop its running, look on your CPX to see the red LED next to the USB connector!

Download: file
while True:
    print("tick")
    led.value = True
    crickit.servo_1.angle = 0
    time.sleep(0.5)
    crickit.servo_2.angle = 180
    time.sleep(1.0)

    print("tock")
    led.value = False
    crickit.servo_1.angle = 180
    time.sleep(0.5)
    crickit.servo_2.angle = 0
    time.sleep(1.0)

Save & Run Code!

Check that both servos are rotating back and forth.

You should also be able to open the REPL within Mu, via pressing the button labeled REPL, and see "tick tock" printing out on your screen.

Long Live Trash Panda!

Exploring further

If you enjoy CircuitPython and want to continue learning you can find lots more CircuitPython projects on the Adafruit Learn System.

This guide was first published on May 24, 2018. It was last updated on May 24, 2018.