Text Editor

Adafruit recommends using the Mu editor for editing your CircuitPython code. You can get more info in this guide.

Alternatively, you can use any text editor that saves simple text files.

Download the Project Bundle

Your project will use a specific set of CircuitPython libraries and the code.py file, along with a folder full of key configuration files. To get everything you need, click on the Download Project Bundle link below, and uncompress the .zip file.

Drag the contents of the uncompressed bundle directory onto your Feather board's CIRCUITPY drive, replacing any existing files or directories with the same names, and adding any new ones that are necessary.

# SPDX-FileCopyrightText: 2021 John Park for Adafruit Industries
# SPDX-License-Identifier: MIT
import time
import random
import board
import audiomp3
import audiopwmio
from adafruit_crickit import crickit

ss = crickit.seesaw  # Crickit seesaw setup

button = crickit.SIGNAL1  # momentary switch to trigger animation
ss.pin_mode(button, ss.INPUT_PULLUP)

LED = crickit.SIGNAL4  # standard LED for eyeball lighting
ss.pin_mode(LED, ss.OUTPUT)

attract_switch = crickit.SIGNAL8  # attract mode switch or jumper
ss.pin_mode(attract_switch, ss.INPUT_PULLUP)

audio = audiopwmio.PWMAudioOut(board.A0)  # Feather outputs this pin to Crickit amplifier
audio_files = [  # use your own mono .mp3 files
current_audio_file = 0

# two motors
motor_eye = crickit.dc_motor_1
motor_lid = crickit.dc_motor_2

def open_lid():
    motor_lid.throttle = 1  # full speed open
    motor_lid.throttle = 0  # hold

def close_lid():
    motor_lid.throttle = -1  # full speed closed
    motor_lid.throttle = 0

def blink(times):
    for _ in range(times):
        ss.digital_write(LED, True)
        ss.digital_write(LED, False)

def eye_look():
    motor_eye.throttle = random.uniform(0.6, 1.0)
    time.sleep(random.random())  # 0 to 1.0 seconds
    motor_eye.throttle = 0
    motor_eye.throttle = random.uniform(-1.0, -0.6)
    motor_eye.throttle = 0

while True:
    if ss.digital_read(attract_switch):  #  regular mode, attrack switch not closed/shorted
        if not ss.digital_read(button):  # button has been pressed
            decoder = audiomp3.MP3Decoder(open("ring.mp3", "rb"))
            while audio.playing:
            ss.digital_write(LED, True)  # light the eye
            decoder = audiomp3.MP3Decoder(open(audio_files[current_audio_file], "rb"))
            while audio.playing:
            motor_eye.throttle = 0  # audio is finished, pause the eye
            current_audio_file = ((current_audio_file + 1) % (len(audio_files)))  # go to next file

    else:  # attract mode
        ss.digital_write(LED, True)
        for _ in range(4):
        time.sleep(random.randint(2, 8))

Use The Hacked Animatronic

You can now run your customized animatronic using the Crickit board! Press the original pushbutton to get it started. It will then play the ring.mp3 audio file, open the eyelid, blink the LED, and start playing the first phrase file.

While the audio file plays, it'll run the eyeball motor back and forth, with some randomized speeds and timing. When the audio file is finished playing, the current loop of eye animation will complete and then the LED will turn off and the lid will close, ready for the next press of the button.

The next time the button is pressed the next audio file in the list will play, and so on until it loops back around to the first one.

Attract Mode: you can use a jumper across the Crickit SIGNAL8 and GND pins to put the device into "attract mode". It will run through eye animation but without playing any sounds.

Create Your Own Audio Files

You can make and load any .mp3 file you like onto your Feather RP2040's CIRCUITPY drive. Here's a guide on how to create them.

Make Your Own

To make your own .mp3, use audio software such as Audacity to save them with these settings:

  • bit rate: anywhere from 16 to 320 kb/s (lower will be smaller, higher is better quality)
  • sample rate: 22050Hz or 44100Hz are recommended, although 16kHz, 24kHz, and 48kHz should also work
  • channels: mono or stereo
  • must be DRM free

Then, simply change the name in the audio file list in code and you can enjoy your own spooky/funny/weird/sassy/you-name-it phrases being uttered by a disembodied eyeball doorbell!

This guide was first published on Nov 10, 2021. It was last updated on May 21, 2024.

This page (Code the Animatronic Eyeball Doorbell) was last updated on May 21, 2024.

Text editor powered by tinymce.