Hi!
I have a project which includes an Audio Shield.
The project has already been built multiple times with an Teensy 3.2 combined to an Audio Shield for Teensy 3.x (rev C)
Which works great!
Due to the current worldwide chip-problems, I'm forced to use an Teensy 4.0 with an Audio Shield for Teensy 4.x (rev D)
However, this doesn't work for me.
After my first try I uploaded the original 3.2 source code to the board, not noticing I had to made changes to the pins (mistake!), which didn't worked out.
After changing the pins I still faced issues on getting the board working. When done uploading the program the USB connection was lost and the SD card was not read.
Whenever I inserted the SD card, USB connection was lost. If I removed the SD card, USB was working again.
So my thoughts were/are (uncertain) that I've destroyed the board.
Now, today; I received a fresh brand new Teensy 4.0 with a new audio shield.
I've uploaded the correct code this time, and there is some progress; with SD card inserted I still have USB connection.
However; the monitor still gives the message: "Unable to access the SD card".
I did checked some similar threads on this forum, which were useful. But none of them has an working answer for me.
So I want to ask you myself, what am I doing wrong?
For your information, I do not use an breadboard neither have I connected any wires at the moment.
The shield is directly soldered with pins to the Teensy. (clean soldering; I have experience)
The SD card is correctly formatted.
The audio loaded on the SD card worked on the 3.2. It has the desired specs as mentioned online.
Oh and yes! the board is mounted the correct side. Minijack and USB port are on the same side.
SOURCE CODE
I have a project which includes an Audio Shield.
The project has already been built multiple times with an Teensy 3.2 combined to an Audio Shield for Teensy 3.x (rev C)
Which works great!
Due to the current worldwide chip-problems, I'm forced to use an Teensy 4.0 with an Audio Shield for Teensy 4.x (rev D)
However, this doesn't work for me.
After my first try I uploaded the original 3.2 source code to the board, not noticing I had to made changes to the pins (mistake!), which didn't worked out.
After changing the pins I still faced issues on getting the board working. When done uploading the program the USB connection was lost and the SD card was not read.
Whenever I inserted the SD card, USB connection was lost. If I removed the SD card, USB was working again.
So my thoughts were/are (uncertain) that I've destroyed the board.
Now, today; I received a fresh brand new Teensy 4.0 with a new audio shield.
I've uploaded the correct code this time, and there is some progress; with SD card inserted I still have USB connection.
However; the monitor still gives the message: "Unable to access the SD card".
I did checked some similar threads on this forum, which were useful. But none of them has an working answer for me.
So I want to ask you myself, what am I doing wrong?
For your information, I do not use an breadboard neither have I connected any wires at the moment.
The shield is directly soldered with pins to the Teensy. (clean soldering; I have experience)
The SD card is correctly formatted.
The audio loaded on the SD card worked on the 3.2. It has the desired specs as mentioned online.
Oh and yes! the board is mounted the correct side. Minijack and USB port are on the same side.
SOURCE CODE
Code:
/*
-- Audio player project --
Equipment: Teensy 4.0, Teensy Audio Shield
Developed: 13 September 2021
Version: 1.0
You are NOT allowed to use this code without permission by the author.
Copyright 2021
*/
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
AudioPlaySdWav playSdWav1;
AudioOutputI2S i2s1;
AudioConnection patchCord1(playSdWav1, 0, i2s1, 0);
AudioConnection patchCord2(playSdWav1, 1, i2s1, 1);
AudioControlSGTL5000 sgtl5000_1;
//Default
#define LED LED_BUILTIN
//Teensy Audio Shield pins
#define SDCARD_CS_PIN BUILTIN_SDCARD
#define SDCARD_MOSI_PIN 11
#define SDCARD_SCK_PIN 13
//Buttons
const int playButton = 0; //purple
const int stopButton = 1; //yellow
const int volUpButton = 2; //green
const int volDownButton = 3; //orange
//Set mode(debug ON/OFF)
bool debug = false; //for additional info in monitor (for instance to check inputs)
//Volume(set betweeen 0 and 1)
double volumeControl = .5; //set defaultVol on boot
float stepUp = .05; //change step size
float stepDown = .05; //change step size
double maxVolume = .70; //set limit
//Define trackname
const char * trackName = "SDTEST1.wav"; //this is the track name on the SD card
//Make sure it's a WAV file with 44.1KHz samping rate
//Booleans
bool allowPlay = true; //allow to play new track when done -- safety feature
bool trackRunning = false;
// Store track length
int trackLength = 0;
// Debounce button states
// PLAY
int statePlay;
int lastStatePlay = LOW;
// VOL UP
int volStateUp;
int lastVolStateUp = LOW;
// VOL DOWN
int volStateDown;
int lastVolStateDown = LOW;
//Background timer
unsigned long lastDebounceTime = 0; // the last time the output pin was toggled
unsigned long debounceDelay = 50; // the debounce time; increase if the output flickers
void setup() {
pinMode(playButton, INPUT_PULLUP);
pinMode(stopButton, INPUT_PULLUP);
pinMode(volUpButton, INPUT_PULLUP);
pinMode(volDownButton, INPUT_PULLUP);
pinMode(LED, OUTPUT);
Serial.begin(9600);
AudioMemory(8);
sgtl5000_1.enable();
sgtl5000_1.volume(volumeControl);
SPI.setMOSI(SDCARD_MOSI_PIN);
SPI.setSCK(SDCARD_SCK_PIN);
if (!(SD.begin(SDCARD_CS_PIN))) {
while (1) {
Serial.println("ERROR: Unable to access the SD card");
delay(5000);
}
}
digitalWrite(LED, HIGH); //show minimal feedback(LED ON)
Serial.println("HIDDEN FOR FORUM");
Serial.println("HIDDEN FOR FORUM");
Serial.println("HIDDEN FOR FORUM");
Serial.println();
delay(1000);
digitalWrite(LED, LOW); //LED is switched off to reduce power consumption
}
void loop() {
playAudio();
while (playSdWav1.isPlaying()) {
int readingStop = digitalRead(stopButton);
//volume control only available if track is playing
volUp();
volDown();
if (readingStop == LOW) {
if(debug) {
Serial.println("Debug: Stop button pressed");
}
playSdWav1.stop();
Serial.println("Track " + String(trackName) + " stopped");
trackRunning = false;
allowPlay = true;
}
if (playSdWav1.positionMillis() > 100) {
trackRunning = true;
}
}
//AUDIO FINISHED -- AUTO STOP
if (playSdWav1.isPlaying() == false && allowPlay == false && trackRunning == true) {
Serial.println("Track " + String(trackName) + " finished");
trackRunning = false;
allowPlay = true;
}
}
void playAudio() {
int readingPlay = digitalRead(playButton);
// DEBOUNCE PLAY
if (readingPlay != lastStatePlay) {
lastDebounceTime = millis(); //reset timer
}
if ((millis() - lastDebounceTime) > debounceDelay) {
if (readingPlay != statePlay) {
statePlay = readingPlay;
if (statePlay == LOW) {
if(debug) {
Serial.println("Debug: Play button is pressed");
}
if (playSdWav1.isPlaying() == false && allowPlay == true) {
playSdWav1.play(trackName);
Serial.println("Started playing: " + String(trackName));
allowPlay = false;
}
}
}
}
lastStatePlay = readingPlay;
}
void volUp() {
int readingUp = digitalRead(volUpButton);
// DEBOUNCE VOL UP
if (readingUp != lastVolStateUp) {
lastDebounceTime = millis(); //reset timer
}
if ((millis() - lastDebounceTime) > debounceDelay) {
if (readingUp != volStateUp) {
volStateUp = readingUp;
if (volStateUp == LOW) {
if(debug) {
Serial.println("Debug: volume up is pressed");
}
if (volumeControl < maxVolume) {
volumeControl += stepUp;
sgtl5000_1.volume(volumeControl);
Serial.println("Volume is: " + String(volumeControl));
}
}
}
}
lastVolStateUp = readingUp;
}
void volDown() {
int readingDown = digitalRead(volDownButton);
// DEBOUNCE VOL DOWN
if (readingDown != lastVolStateDown) {
lastDebounceTime = millis(); //reset timer
}
if ((millis() - lastDebounceTime) > debounceDelay) {
if (readingDown != volStateDown) {
volStateDown = readingDown;
if (volStateDown == LOW) {
if(debug) {
Serial.println("Debug: volume down is pressed");
}
if (volumeControl > 0) {
volumeControl -= stepDown;
sgtl5000_1.volume(volumeControl);
Serial.println("Volume is: " + String(volumeControl));
}
}
}
}
lastVolStateDown = readingDown;
}