Teensy 4.0 with Rev D2 Audio Shield Cannot execute playSdWav1.play

Sinistra

Member
Hi guys
I am working on an audio project that needs to pan between two audios. I used Teesy4.0 with RevD2 shield and I adopted code from the teensy audio library tutorial Part_2_02 mixer, but it does not work. There is no sound coming out. I tested the hardware, and that's not the problem. The code is literally the same code they used in the tutorial.

Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

// GUItool: begin automatically generated code
AudioPlaySdWav           playSdWav1;     //xy=140,266
AudioPlaySdWav           playSdWav2;     //xy=140,322
AudioMixer4              mixer2;         //xy=331,336
AudioMixer4              mixer1;         //xy=333,269
AudioOutputI2S           i2s1;           //xy=550,316
AudioConnection          patchCord1(playSdWav1, 0, mixer1, 0);
AudioConnection          patchCord2(playSdWav1, 1, mixer2, 0);
AudioConnection          patchCord3(playSdWav2, 0, mixer1, 1);
AudioConnection          patchCord4(playSdWav2, 1, mixer2, 1);
AudioConnection          patchCord5(mixer2, 0, i2s1, 1);
AudioConnection          patchCord6(mixer1, 0, i2s1, 0);
AudioControlSGTL5000     sgtl5000_1;     //xy=337,407
// GUItool: end automatically generated code

// Use these with the Teensy Audio Shield
#define SDCARD_CS_PIN    10
#define SDCARD_MOSI_PIN  7
#define SDCARD_SCK_PIN   14

void setup() {
  Serial.begin(9600);
  AudioMemory(8);
  sgtl5000_1.enable();
  sgtl5000_1.volume(0.5);
  SPI.setMOSI(SDCARD_MOSI_PIN);
  SPI.setSCK(SDCARD_SCK_PIN);
  if (!(SD.begin(SDCARD_CS_PIN))) {
    while (1) {
      Serial.println("Unable to access the SD card");
      delay(500);
    }
  }
  pinMode(13, OUTPUT); // LED on pin 13
  mixer1.gain(0, 0.5);
  mixer1.gain(1, 0.5);
  mixer2.gain(0, 0.5);
  mixer2.gain(1, 0.5);
  delay(1000);
}

void loop() {
  if (playSdWav1.isPlaying() == false) {
    Serial.println("Start playing 1");
    playSdWav1.play("SDTEST1.WAV");
    delay(10); // wait for library to parse WAV info
  }
  if (playSdWav2.isPlaying() == false) {
    Serial.println("Start playing 2");
    playSdWav2.play("SDTEST4.WAV");
    delay(10); // wait for library to parse WAV info
  }
  // uncomment this code to allow Knob A3 to pan between songs
  int knob = analogRead(A3);  // knob = 0 to 1023
  float gain1 = (float)knob / 1023.0;
  float gain2 = 1.0 - gain1;
  mixer1.gain(0, gain1);
  mixer1.gain(1, gain2);
  mixer2.gain(0, gain1);
  mixer2.gain(1, gain2);
}

The Serial Monitor only prints:
Code:
"Start playing 1"

so I guess playSdWav1.play has some problem and blocked the execution of the following code. so "Start playing 2" was never printed.

I tested with the SD_Card lib and it succeeded in reading the files in the SD. so the problem is not the SD Card.

I also tried the WavFilePlayer. Succeeded in playing the TEST song. so it's not the shield or hardware problem.

Please advise.
 
Try removing the line
Code:
 pinMode(13, OUTPUT); // LED on pin 13
as pin 13 is used for both the LED and SPI SCK on Teensy 4.x
 
Shouldn't "#define SDCARD_SCK_PIN 14" be changed to "#define SDCARD_SCK_PIN 13" also?
Same for "#define SDCARD_MOSI_PIN 7" to "#define SDCARD_MOSI_PIN 11".

Paul

Capture.PNG
 
You’d expect so, but I seem to remember the SPI driver checks for valid pin numbers and ignores attempts to set ones that don’t work. So actually you end up using the default ones on T4.x, which works provided you don’t mess with them after SD.begin().
 
Agree, for the Audio Adapter rev D2 you end up with the default SPI pins.

and ignores attempts to set ones that don’t work
How would the SPI driver know that pins do not work if you specifically assigned those to other valid pins? Ah OK, I see: Teensy 4 has only limited alternative SPI pins [on the back of board].
Yeah, in that case I can imagine the SPI driver ignores the non-valid assignments like in the OP's post.

Thanks,
Paul
 
Back
Top