Lab 05: Test the Speaker
This lab plays a steady 400 Hz tone for two seconds. It talks to the amplifier directly, without the kit's sound library, so the only things that can stop it are the wires and the amplifier.
Welcome to Lab 05
This is the lab where your clock finds its voice. One steady beep
today means chimes, alarms, and timer beeps later. Let's make time
tick!
What You Will Learn
- how a computer makes sound out of numbers
- what samples and sample rate mean
- how the Pico sends sound to the amplifier over I2S
Run It
Keep the speaker away from your ear, open 05-speaker-test.py, and click
Run. You should hear a two-second beep. The shell prints:
1 2 3 4 5 6 | |
Sound Is a List of Numbers
A speaker makes sound by pushing its cone out and pulling it back, very fast. A 400 Hz tone pushes and pulls 400 times a second. To describe that movement, the program sends a number for where the cone should be, 16,000 times every second. Each number is a sample, and 16,000 per second is the sample rate.
1 2 | |
A wave, one number at a time
Think of a flip book. Each page is one sample, and flipped fast enough
the pages become smooth motion. Here, 40 numbers trace one full wave,
and 400 of those waves every second are the beep you hear.
The program works out one chunk of the wave with math.sin() and sends
it again and again. The first chunk fades in and the last fades out, so
the tone starts and stops without a click.
Sending It: I2S
The samples travel to the amplifier on three wires, called I2S:
| Wire | Pico pin | What it does |
|---|---|---|
| BCLK | GP9 | Ticks once for every bit of every sample |
| LRC | GP10 | Marks where each sample starts |
| DIN | GP11 | The bits of the samples themselves |
1 2 3 4 | |
config.set_gain() sets the amplifier's GAIN pin. On this kit the GAIN
wire goes to a Pico pin, so a program can pick 6, 9, or 12 decibels
of boost (GAIN_DB in config.py).
Try This
- Change
FREQto800. The pitch goes up an octave. KeepFREQa number that divides 16,000 exactly, like 200, 500, 800, or 1000. - Change
VOLUMEinconfig.pyto 10, then 80. Which is comfortable? - Change
GAIN_DBinconfig.pyto 12. How much louder is it?
If It Doesn't Work
- No sound at all. Check the amplifier's VIN and GND first: with no power it is silent. Then check that DIN goes to GP11, and that the speaker's wires are in the amplifier's + and − terminals.
- An error when
I2S()starts. BCLK and LRC are swapped. LRC must be on the pin right after BCLK. GAIN_DB must be 6, 9, or 12. Fix the number inconfig.py.
Your Clock Has a Voice!
You turned a list of numbers into a real sound, and you know what
samples, sample rate, and I2S mean. Every chime and alarm in this kit
is built the same way.
Next: Lab 06: Check Your WiFi