Teensy 4.1 & Audio Board Rev D Tutorial 01_04 Issue

Status
Not open for further replies.

Stodders

New member
Hi all, Im am attempting the tutorial series included. Everything is fine up until 01_04.
If I upload the code without any alterations it will hang after serial printing "Start playing" with no music playing.
If I comment out the the LED blinking section it will still hang, if I comment out the setting pinMode the code will run - music plays and prints the position
Code:
// Advanced Microcontroller-based Audio Workshop
//
// http://www.pjrc.com/store/audio_tutorial_kit.html
// https://hackaday.io/project/8292-microcontroller-audio-workshop-had-supercon-2015
// 
// Part 1-4: Blink LED while Playing Music
//
// Do something while playing a music file.  Admittedly
// only blink Teensy's LED and print info about the
// playing time in the file.  The point is that Arduino
// sketch code is free to do other work while the audio
// library streams data from the SD card to the headphones.

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

AudioPlaySdWav           playSdWav1;
AudioOutputI2S           audioOutput;
AudioConnection          patchCord1(playSdWav1, 0, audioOutput, 0);
AudioConnection          patchCord2(playSdWav1, 1, audioOutput, 1);
AudioControlSGTL5000     sgtl5000_1;

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

// Use these with the Teensy 3.5 & 3.6 SD card
//#define SDCARD_CS_PIN    BUILTIN_SDCARD
//#define SDCARD_MOSI_PIN  11  // not actually used
//#define SDCARD_SCK_PIN   13  // not actually used

// Use these for the SD+Wiz820 or other adaptors
//#define SDCARD_CS_PIN    4
//#define SDCARD_MOSI_PIN  11
//#define SDCARD_SCK_PIN   13

void setup() {
  Serial.begin(9600);
  AudioMemory(8);
  sgtl5000_1.enable();
  sgtl5000_1.volume(0.45);
  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
  delay(1000);
}

void loop() {
 if (playSdWav1.isPlaying() == false) {
    Serial.println("Start playing");
    playSdWav1.play("SDTEST3.WAV");
    Serial.println("Before 10ms Delay");
    delay(10); // wait for library to parse WAV info
    Serial.println("After 10ms Delay");
  }

  // print the play time offset
  Serial.print("Playing, now at ");
  Serial.print(playSdWav1.positionMillis());
  Serial.println(" ms");

  // blink LED and print info while playing
 /* digitalWrite(13, HIGH);
  delay(250);
  digitalWrite(13, LOW);
  delay(250);*/

In an attempt to debug I added print statements around the play command as follows
Code:
if (playSdWav1.isPlaying() == false) {
    Serial.println("Start playing");
    playSdWav1.play("SDTEST3.WAV");
    Serial.println("Before 10ms Delay");
    delay(10); // wait for library to parse WAV info
    Serial.println("After 10ms Delay");
  }
Neither of these commands are printed so it appears the hang happens on the 'playSdWav1' command.

Any ideas of how to further debug the issue?
Thanks for any help!
 
The rev C shields have DOUT, audio data from shield to Teensy on pin 13, and the SD card clock on pin 14, so when only playing music pin 13 can be used for blinking. On rev D boards the SD card clock is on pin 13 so blinking this one does not work when using the SD card
 
Ahh thank you, makes complete sense now. I've moved the SD to the Teensy mainboard slot and its now functioning!
Code:
// Use these with the Teensy Audio Shield
//#define SDCARD_CS_PIN    10
//#define SDCARD_MOSI_PIN  7
//#define SDCARD_SCK_PIN   14

// Use these with the Teensy 3.5 & 3.6 SD card
#define SDCARD_CS_PIN    BUILTIN_SDCARD
//#define SDCARD_MOSI_PIN  11  // not actually used
//#define SDCARD_SCK_PIN   13  // not actually used

// Use these for the SD+Wiz820 or other adaptors
//#define SDCARD_CS_PIN    4
//#define SDCARD_MOSI_PIN  11
//#define SDCARD_SCK_PIN   13

void setup() {
  Serial.begin(9600);
  AudioMemory(8);
  sgtl5000_1.enable();
  sgtl5000_1.volume(0.45);
 // 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);
    }
  }
 
Status
Not open for further replies.
Back
Top