Updating with CRICKIT

If you'd prefer to opt for a CRICKIT powered 9000 series rather than use the Wave Shield, this page will show you how!

If this is your first time using CRICKIT, follow this guide to get acquainted.

To get your CRICKIT and HAL talking, you will need some alligator clip to male jumper wire connectors, a screwdriver, and a micro USB cable (to upload code from your computer).

We will be taking advantage of CRICKIT's ability to multitask combined with the ease of CircuitPython.

The Signal port will be used to detect the button press, the Drive block to control the LED, and the Speaker block send audio signal to the speaker.

Attach the alligator clips to the button terminals as shown. 

The two connections extending horizontally outwards detect a button press, while the two vertical terminals on the side are connected to the button's internal LED.

Connect button to CRICKIT

 

Now it's time to connect everything to your CRICKIT board.

 

Connect the red and black button wires to the Signal and GND ports.

 

Connect the LED+ wire to Drive 5V

 

Connect the LED– wire to Drive #1

 

Use a screwdriver to tighten down the connections to the Drive terminal blocks.

Connect speaker to CRICKIT

 

Take the red and black wires coming from the speaker and insert them into the Speaker terminal block.

 

Tighten both connections with a small screwdriver.

A small square of double sided foam tape will hold your CRICKIT in place on the back of the speaker. 

Connect 5V DC power to CRICKIT

Make sure you're using a 5 volt power supply for CRICKIT!

Once everything is connected you're ready for some code!

Getting Familiar with Mu

We will be using CircuitPython code, which is easiest to work with in the Mu Editor. If you haven't previously used Mu, this guide will get you started

If you haven't used Circuit Playground Express with CRICKIT before, make sure you've updated it with the latest special 'seesaw' version of the CPX firmware. This guide will show you how.

Copy and paste the code below in your Mu editor window. 

import os
import random
import time
import board
import audioio
from adafruit_crickit import crickit

# Hal button-and-voice example

# Button connected to Signal pin #1 & ground:
BUTTON = crickit.SIGNAL1
crickit.seesaw.pin_mode(BUTTON, crickit.seesaw.INPUT_PULLUP)

# LED connected to 5V & Drive pin #1:
LED = crickit.drive_1
LED.duty_cycle = 65535

# Find all Wave files in CIRCUITPY storage:
WAVEFILES = [file for file in os.listdir("/")
             if (file.endswith(".wav") and not file.startswith("._"))]
print("Audio files found:", WAVEFILES)

# Audio playback object:
AUDIO = audioio.AudioOut(board.A0)

# Function to play a wave file in its entirety:
def play_file(wavfile):
    print("Playing", wavfile)
    with open(wavfile, "rb") as f:
        wav = audioio.WaveFile(f)
        AUDIO.play(wav)
        while AUDIO.playing:
            LED.duty_cycle = random.randint(5000, 30000)
            time.sleep(0.1)
    LED.duty_cycle = 65535

while True:
    if not crickit.seesaw.digital_read(BUTTON):
        # Play a random wave file
        play_file(random.choice(WAVEFILES))
        # Then wait for button to be released
        while not crickit.seesaw.digital_read(BUTTON):
            continue

Use a micro USB cable to connect to the port on the Circuit Playground Express mounted on top of CRICKIT. You should see "CIRCUITPY" show up as a new device on your computer. 

Save this code to CIRCUITPY as a file named "code.py".

Audio files for HAL 9000 are not included here, lest we run afoul of copyright issues, but with just a bit of Google searching you can find an ample supply already in WAV format.

Once you have WAV files you're happy with, you'll want to drag and drop them directly onto your CIRCUITPY drive.

When all is said and done your CIRCUITPY drive should look something like this.

It's OK if the file names for your .wav files are different from those in this image (the code is only looking for a specific file type, the names of the files themselves don't matter).

HAL speaks!

Connect CRICKIT to power and you should see the red button illuminate. Give the button a press and you'll be greeted with a random HAL 9000 quote.

Controlling volume

If you find HAL's voice is too loud or too quiet you can easily adjust this on the fly without the need for changing the code.

Use the small potentiometer on CRICKIT to adjust the speaker's volume up or down. 

This guide was first published on Apr 29, 2013. It was last updated on Sep 19, 2018. This page (Updating with CRICKIT) was last updated on Aug 09, 2018.