I2S Standard
Welcome to I2S Audio
In this lab, you will learn about Inter-IC Sound (I2S) — the digital bus that lets the Pico play high-quality audio. Say it like "eye-two-ess."
Inter-IC Sound (I2S) — pronounced "eye-two-ess" — is a serial bus that connects digital audio devices together. It sends Pulse-Code Modulation (PCM) audio data between chips. PCM is the same format used on CDs and in WAV files.
Key Idea
I2S and I2C sound almost identical but are completely different buses. I2C is for sensors and slow devices. I2S is specifically for high-quality digital audio — it is much faster and designed to keep audio in perfect time.
Why Use I2S?
A simple piezo buzzer can play tones, but it cannot play high-quality audio files. I2S lets you connect a proper Digital-to-Analog Converter (DAC) or a digital amplifier to the Pico. With I2S, you can play WAV files, synthesized music, and recorded speech at CD quality.
How I2S Works
I2S uses three wires:
| Wire | Name | Purpose |
|---|---|---|
| SCK | Serial Clock (Bit Clock) | Clocks each audio bit |
| WS | Word Select (Left/Right Clock) | Selects the left or right stereo channel |
| SD | Serial Data | The actual audio samples |
The clock speed depends on the audio quality you want. For standard 44.1 kHz stereo audio at 16-bit depth:
- SCK runs at 44,100 × 2 channels × 16 bits = 1.41 MHz
The Pico's I2S hardware can handle this easily.
MicroPython I2S Support
Since MicroPython version 1.17, the machine.I2S class lets you send and receive I2S audio. Here is a short example that plays a raw WAV file from the Pico's flash memory using an I2S DAC module:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | |
What Each Line Does
I2S(0, mode=I2S.TX, ...)— creates an I2S transmitter using peripheral 0.bits=16— each audio sample is 16 bits wide.format=I2S.STEREO— two channels (left and right).rate=44100— 44,100 samples per second (CD quality).ibuf=20000— the Pico buffers 20,000 bytes of audio so playback stays smooth.wav_file.seek(44)— skips the WAV file header. The first 44 bytes describe the file format, not the audio.audio_out.write(buf[:num_read])— sends the chunk of audio data to the DAC over I2S.audio_out.deinit()— frees the I2S hardware so other programs can use it.
Common I2S DAC Modules
| Module | Chip | Channels | Cost |
|---|---|---|---|
| MAX98357A | MAX98357A | Mono, 3 W | about $2 |
| PCM5102A | PCM5102A | Stereo | about $3 |
| UDA1334A | UDA1334A | Stereo | about $5 |
The MAX98357A is the most popular choice for beginners. It includes a speaker amplifier, so you can connect a small speaker directly to it with no extra parts.
Monty's Tip
Convert your audio files to 16-bit, 44.1 kHz WAV format before copying them to the Pico. The Converting Audio Files lab shows you exactly how to do this with free tools.
References
- Wikipedia — I2S
- MicroPython I2S Documentation
- The I2S Bus Lab — detailed wiring and usage examples
Great Work!
You now understand how I2S works and how to use it in MicroPython. Next, you will learn how to convert MP3 files into the WAV format the Pico can play.