Dong Clerk
New member
Hi, I'm new to Teensy and this is my first project. I got a Teensy 4.1 and one of the thing I wanted to make is it to play music through a speaker. After spending hours looking online how I could achieve my objective I'm starting to lose hope. I do not know if it is achievable with only the pieces I'm using (Teensy 4.1, SD card, a very simple speaker). Ergo I am asking for help.
On Arduino, I have used the File>Examples>Audio>WavFilePlayer example as my main template. I removed some code that I think did not matter for what I am doing.
______________________________________________________________________________________________________________________________________________________
______________________________________________________________________________________________________________________________________________________
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
AudioPlaySdWav playWav1;
// Use one of these 3 output types: Digital I2S, Digital S/PDIF, or Analog DAC
//AudioOutputI2S audioOutput;
//AudioOutputSPDIF audioOutput;
AudioOutputAnalog audioOutput;
//On Teensy LC, use this for the Teensy Audio Shield:
// AudioOutputI2Sslave audioOutput;
AudioConnection patchCord1(playWav1, 0, audioOutput, 0);
AudioConnection patchCord2(playWav1, 1, audioOutput, 1);
AudioControlSGTL5000 sgtl5000_1;
// Use these with the Teensy 4.1 SD card
#define SDCARD_CS_PIN BUILTIN_SDCARD
#define SDCARD_MOSI_PIN 11 // not actually used
#define SDCARD_SCK_PIN 13 // not actually used
void setup() {
Serial.begin(9600);
// Audio connections require memory to work. For more
// detailed information, see the MemoryAndCpuUsage example
AudioMemory(8);
}
//Fonction----------------------------------------------------------------------------------
void playFile(const char *filename)
{
Serial.print("Playing file: ");
Serial.println(filename);
// Start playing the file. This sketch continues to
// run while the file plays.
playWav1.play(filename);
// A brief delay for the library read WAV info
delay(25);
// Simply wait for the file to finish playing.
while (playWav1.isPlaying()) {
// uncomment these lines if you audio shield
// has the optional volume pot soldered
//float vol = analogRead(15);
//vol = vol / 1024;
// sgtl5000_1.volume(vol);
}
}
//------------------------------------------------------------------------------------------
void loop() {
playFile("MUSIC.WAV"); // filenames are always uppercase 8.3 format
delay(500);
}
______________________________________________________________________________________________________________________________________________________
______________________________________________________________________________________________________________________________________________________
My most urgent questions are: Where should I connect the speaker on my Teensy 4.1? How do I call the music in the SD to the speaker and what important commands am I missing?
Thank you
On Arduino, I have used the File>Examples>Audio>WavFilePlayer example as my main template. I removed some code that I think did not matter for what I am doing.
______________________________________________________________________________________________________________________________________________________
______________________________________________________________________________________________________________________________________________________
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
AudioPlaySdWav playWav1;
// Use one of these 3 output types: Digital I2S, Digital S/PDIF, or Analog DAC
//AudioOutputI2S audioOutput;
//AudioOutputSPDIF audioOutput;
AudioOutputAnalog audioOutput;
//On Teensy LC, use this for the Teensy Audio Shield:
// AudioOutputI2Sslave audioOutput;
AudioConnection patchCord1(playWav1, 0, audioOutput, 0);
AudioConnection patchCord2(playWav1, 1, audioOutput, 1);
AudioControlSGTL5000 sgtl5000_1;
// Use these with the Teensy 4.1 SD card
#define SDCARD_CS_PIN BUILTIN_SDCARD
#define SDCARD_MOSI_PIN 11 // not actually used
#define SDCARD_SCK_PIN 13 // not actually used
void setup() {
Serial.begin(9600);
// Audio connections require memory to work. For more
// detailed information, see the MemoryAndCpuUsage example
AudioMemory(8);
}
//Fonction----------------------------------------------------------------------------------
void playFile(const char *filename)
{
Serial.print("Playing file: ");
Serial.println(filename);
// Start playing the file. This sketch continues to
// run while the file plays.
playWav1.play(filename);
// A brief delay for the library read WAV info
delay(25);
// Simply wait for the file to finish playing.
while (playWav1.isPlaying()) {
// uncomment these lines if you audio shield
// has the optional volume pot soldered
//float vol = analogRead(15);
//vol = vol / 1024;
// sgtl5000_1.volume(vol);
}
}
//------------------------------------------------------------------------------------------
void loop() {
playFile("MUSIC.WAV"); // filenames are always uppercase 8.3 format
delay(500);
}
______________________________________________________________________________________________________________________________________________________
______________________________________________________________________________________________________________________________________________________
My most urgent questions are: Where should I connect the speaker on my Teensy 4.1? How do I call the music in the SD to the speaker and what important commands am I missing?
Thank you
Last edited: