🛠 Audio Shield SGTL5000 : boucle stéréo 44,1 kHz et outil de conception graphique

Teensy 3.2 · intermediaire · Schéma : IMG-teensy-32-intermediaire-4-teensy32-audio-shield-boucle.svg — Teensy 3.2 empilée sous un Audio Adapter (shield SGTL5000) : prises casque/ligne/micro à gauche, emplacement carte SD à droite, nappe de broches entre les deux ; flèches vers les broches 11, 9, 23, 22, 13, 18/19 et capture de l'outil de conception audio (boîtes reliées par des câbles).

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

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

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials