🛠 Audio Shield SGTL5000 : boucle stéréo 44,1 kHz et outil de conception graphique
Objectives
Enter the world for which the Teensy 3.2 is famous: the Teensy Audio Library, which handles 16-bit / 44.1 kHz stereo streaming (polyphonic playback, synthesis, effects, FFT analysis, flexible routing) by leveraging the DSP instructions of the Cortex-M4. You will assemble the PJRC Audio Adapter (or "Audio Shield") with its SGTL5000 codec, create a stereo input → output loop, and then discover the graphical Audio System Design Tool which generates the C++ code for you.
Hardware
- 1 Teensy 3.2 + 1 PJRC Audio Adapter (solder kit, SGTL5000 codec, headphone/line-in/mic jacks, SD card and SPI-flash slots)
- 1 audio source (headphone output from a phone connected to the line-in jack) + 1 pair of headphones or amplified speakers
- Short cables between the shield and the board — stacking the shield solves this issue; in loose wiring, the MCLK/BCLK/LRCLK/TX/RX wires "must be short to avoid problems": long wires produce audible noise (PJRC forum)
- Optionally an SD card ≤ 32 GB (support for cards > 32 GB is only available since Teensyduino 1.54)
I2S Pinout (Teensy 3.x)
The shield uses the following pins: 11 (MCLK), 9 (BCLK), 23 (LRCLK), 22 (DOUT → shield), 13 (DIN ← shield), 18/19 (SDA/SCL to configure the SGTL5000 via I2C). The Teensy 3.2 also has its own 12-bit DAC (A14, mono) and ADC inputs to work without the shield.
Complete Code
Structure identical to that generated by the design tool (objects documented on the Audio library page):
#include <Audio.h>
#include <Wire.h> // SGTL5000 configure en I2C (broches 18/19)
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
AudioInputI2S i2sIn; // entree stereo (line-in ou mic du shield)
AudioOutputI2S i2sOut; // sortie stereo (casque / line-out)
AudioConnection patchCord1(i2sIn, 0, i2sOut, 0); // gauche -> gauche
AudioConnection patchCord2(i2sIn, 1, i2sOut, 1); // droite -> droite
AudioControlSGTL5000 sgtl5000;
void setup {
Audio.memory(16); // 16 blocs memoire audio (~16 ko)
sgtl5000.enable; // alimente le codeur
sgtl5000.volume(0.5); // niveau de sortie casque
// Le flux audio tourne en 44,1 kHz / 16 bits pendant que votre code tourne
}
void loop {
// Des objets DSP (effets, mixeurs, FFT...) s'insèrent entre i2sIn et
// i2sOut sans toucher au materiel I2S.
}
The Graphical Design Tool
<https://www.pjrc.com/teensy/gui/> : You connect boxes (inputs, outputs, delays, reverb, mixers, FFT analyzers…) like on a patchbay, and the tool exports the complete C++ code to paste into the IDE. The official video tutorial series is included in the examples: File > Examples > Audio > Tutorial. Two Audio Shields on the same Teensy 3.x provide 4 inputs / 4 outputs (quad), using the wiring published by SparkFun.
Expected Verification
Headphones on the shield, source on line-in: sound comes out in stereo, with no perceptible latency, while loop does nothing — the stream is driven by interrupts and DMA. Increase the volume gradually (0.5 = half) to avoid hurting your ears. Cut the input: the silence must be clean; a hum/background noise indicates I2S wires that are too long or poor grounding.
Common Errors
- I2S wires too long in a "loose" setup: audible noise guaranteed — stack the shield or keep cables very short.
- Forgetting
Audio.memory: without allocated memory blocks, no audio connection works. - SD card > 32 GB with an old Teensyduino: the SD library does not see it — update (≥ 1.54) or reformat to max 32 GB.
- Wrong microphone input volume: the SGTL5000 has mic gain settings distinct from line-in — consult the library examples.
- Failed soldering of the kit on the pin header: the classic symptom is a silent output on one channel — check DIN/DOUT (pins 13/22) for continuity.
- Confusing the integrated 12-bit DAC (A14, mono) and the shield's codec (16-bit stereo): both coexist but serve different purposes.
Other tutorials for this board
- Premiers pas sur la Teensy 3.2 : Teensyduino, HalfKay et premier Blink
- Broches, ADC 13 bits, DAC 12 bits et PWM : dompter les E/S de la Teensy 3.2
- Un instrument MIDI USB en 10 minutes : Bounce, boutons et règle d'or du drain
- OctoWS2811 : piloter 8 rubans WS2812 en parallèle par DMA (presque zéro CPU)
- Timers matériels, interruptions imbriquées et FASTRUN : la vitesse Cortex-M4
- Intégration produit : alimentation VIN/VUSB, régulateur 250 mA, RTC à quartz et EEPROM
Code examples for this board
clignotante.inoArduinotouche-capacitive.inoArduinoanalogique-12-bits.inoArduinomidi-piano.inoArduinopwm-respiration.inoArduinoservo-angle.inoArduino