Teensy 3.2, Audio Board and Optimized SD_t3.h failing.

Status
Not open for further replies.

SteveFenton

New member
Hi,

I'm currently experimenting to see how many WAV files I can play from the SD Card slot on the Audio Board. I'm using a Teensy 3.2. Arduino IDE 1.6.11 and Teensyduino 1.3.

I understand there you can gain access to an optiized 'read' library for the SDCard by uncommenting the following line in SD_t3.h

//#define USE_TEENSY3_OPTIMIZED_CODE

Unfortunately, when I do this, I receive a message "Unable to access the SD card", so the first SD.Begin() returns false;

Here is my code...

Code:
// **************************

// Advanced Microcontroller-based Audio Workshop
//
// Stream as many files as possible from SD card..
//

// WAV files for this and other Tutorials are here:
// http://www.pjrc.com/teensy/td_libs_AudioDataFiles.html

#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
//# include <SD_t3.h> //also tried to include this (as it's included if you add library from the IDE) but the problem //still exists.
#include <SerialFlash.h>


AudioControlSGTL5000     sgtl5000_1;

// GUItool: begin automatically generated code
AudioPlaySdWav           playSdWav4;     //xy=119,766
AudioPlaySdWav           playSdWav2;     //xy=120,628
AudioPlaySdWav           playSdWav1;     //xy=126,571
AudioPlaySdWav           playSdWav3;     //xy=128,693
AudioPlayMemory          playMem1;       //xy=142,1377
AudioMixer4              mixer1;         //xy=311,638
AudioMixer4              mixer2;         //xy=322,734
AudioOutputI2S           i2s1;           //xy=476,695
AudioConnection          patchCord1(playSdWav4, 0, mixer1, 3);
AudioConnection          patchCord2(playSdWav4, 1, mixer2, 3);
AudioConnection          patchCord3(playSdWav2, 0, mixer1, 1);
AudioConnection          patchCord4(playSdWav2, 1, mixer2, 1);
AudioConnection          patchCord5(playSdWav1, 0, mixer1, 0);
AudioConnection          patchCord6(playSdWav1, 1, mixer2, 0);
AudioConnection          patchCord7(playSdWav3, 0, mixer1, 2);
AudioConnection          patchCord8(playSdWav3, 1, mixer2, 2);
AudioConnection          patchCord9(mixer1, 0, i2s1, 0);
AudioConnection          patchCord10(mixer2, 0, i2s1, 1);
// GUItool: end automatically generated code

float VolControl, VolControl2, VolControl3, VolControl4;



void setup() {
  Serial.begin(9600);
  AudioMemory(10);
  sgtl5000_1.enable();
  sgtl5000_1.volume(0.4);
  SPI.setMOSI(7);
  SPI.setSCK(14);
  if (!(SD.begin(10))) {
    while (1) {
      Serial.println("Unable to access the SD card");
      delay(500);
    }
  }
  delay(1000);

  //Setup Default Start mix
  mixer1.gain(0, 0.25);
  mixer1.gain(1, 0.25);
  mixer1.gain(2, 0.25);
  mixer1.gain(3, 0.25);
  mixer2.gain(0, 0.25);
  mixer2.gain(1, 0.25);
  mixer2.gain(2, 0.25);
  mixer2.gain(3, 0.25);

}


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("SDTEST2.WAV");
    delay(10); // wait for library to parse WAV info
  }

    if (playSdWav3.isPlaying() == false) {
    Serial.println("Start playing 3");
    playSdWav3.play("SDTEST3.WAV");
    delay(10); // wait for library to parse WAV info
  }

   //if (playSdWav4.isPlaying() == false) {
   // Serial.println("Start playing 4");
   // playSdWav4.play("SDTEST4.WAV");
   // delay(10); // wait for library to parse WAV info
  //}
  
  
  // do nothing while playing...

}

What could be the cause of the SD.Begin returning false please? If I leave the line commented, it all works fine.

Thanks,

Steve.
 
**Update

Hi,

I'm currently experimenting to see how many WAV files I can play from the SD Card slot on the Audio Board. I'm using a Teensy 3.2. Arduino IDE 1.6.11 and Teensyduino 1.3.

I understand there you can gain access to an optiized 'read' library for the SDCard by uncommenting the following line in SD_t3.h

//#define USE_TEENSY3_OPTIMIZED_CODE

Unfortunately, when I do this, I receive a message "Unable to access the SD card", so the first SD.Begin() returns false;

Here is my code...

Code:
// **************************

// Advanced Microcontroller-based Audio Workshop
//
// Stream as many files as possible from SD card..
//

// WAV files for this and other Tutorials are here:
// http://www.pjrc.com/teensy/td_libs_AudioDataFiles.html

#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
//# include <SD_t3.h> //also tried to include this (as it's included if you add library from the IDE) but the problem //still exists.
#include <SerialFlash.h>


AudioControlSGTL5000     sgtl5000_1;

// GUItool: begin automatically generated code
AudioPlaySdWav           playSdWav4;     //xy=119,766
AudioPlaySdWav           playSdWav2;     //xy=120,628
AudioPlaySdWav           playSdWav1;     //xy=126,571
AudioPlaySdWav           playSdWav3;     //xy=128,693
AudioPlayMemory          playMem1;       //xy=142,1377
AudioMixer4              mixer1;         //xy=311,638
AudioMixer4              mixer2;         //xy=322,734
AudioOutputI2S           i2s1;           //xy=476,695
AudioConnection          patchCord1(playSdWav4, 0, mixer1, 3);
AudioConnection          patchCord2(playSdWav4, 1, mixer2, 3);
AudioConnection          patchCord3(playSdWav2, 0, mixer1, 1);
AudioConnection          patchCord4(playSdWav2, 1, mixer2, 1);
AudioConnection          patchCord5(playSdWav1, 0, mixer1, 0);
AudioConnection          patchCord6(playSdWav1, 1, mixer2, 0);
AudioConnection          patchCord7(playSdWav3, 0, mixer1, 2);
AudioConnection          patchCord8(playSdWav3, 1, mixer2, 2);
AudioConnection          patchCord9(mixer1, 0, i2s1, 0);
AudioConnection          patchCord10(mixer2, 0, i2s1, 1);
// GUItool: end automatically generated code

float VolControl, VolControl2, VolControl3, VolControl4;



void setup() {
  Serial.begin(9600);
  AudioMemory(10);
  sgtl5000_1.enable();
  sgtl5000_1.volume(0.4);
  SPI.setMOSI(7);
  SPI.setSCK(14);
  if (!(SD.begin(10))) {
    while (1) {
      Serial.println("Unable to access the SD card");
      delay(500);
    }
  }
  delay(1000);

  //Setup Default Start mix
  mixer1.gain(0, 0.25);
  mixer1.gain(1, 0.25);
  mixer1.gain(2, 0.25);
  mixer1.gain(3, 0.25);
  mixer2.gain(0, 0.25);
  mixer2.gain(1, 0.25);
  mixer2.gain(2, 0.25);
  mixer2.gain(3, 0.25);

}


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("SDTEST2.WAV");
    delay(10); // wait for library to parse WAV info
  }

    if (playSdWav3.isPlaying() == false) {
    Serial.println("Start playing 3");
    playSdWav3.play("SDTEST3.WAV");
    delay(10); // wait for library to parse WAV info
  }

   //if (playSdWav4.isPlaying() == false) {
   // Serial.println("Start playing 4");
   // playSdWav4.play("SDTEST4.WAV");
   // delay(10); // wait for library to parse WAV info
  //}
  
  
  // do nothing while playing...

}

What could be the cause of the SD.Begin returning false please? If I leave the line commented, it all works fine.

Thanks,

Steve.


**UPDATE

I also tried to compile the code at reduced CPU rates, 24MHz for example, the problem still exists.

***
 
Further update..

**UPDATE

I also tried to compile the code at reduced CPU rates, 24MHz for example, the problem still exists.

***

I also tried to switch the generic card for a SanDisk Ultra 8GB card. The issues changed slightly with the latter in that recognised the card but playback of the audio was stuttered and it sounded like it was downsampling ..playing back slowly. This was playing one file.

When I removed the optimisation switch the same issue occurred.

So...what so the 'correct' combination of processor speed at compile time, optimisation switch to use and microSD card to use please?

Thanks.
 
Status
Not open for further replies.
Back
Top