Teensy 4.0 audio shield Rev D cant connect to Micro SD card

ninja

Member
HI I have the following code and pin thinking that it may be reading sd card. My computer can read the MicroSd Card using adaptor . its 16 GB 10 however the IDE show
Unable to access the SD card
10
Unable to access the SD card
10
Unable to access the SD card
10


#include <Bounce.h>
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <TimeLib.h>

// DEFINES
// Define pins used by Teensy Audio Shield
#define SDCARD_CS_PIN 10
#define SDCARD_MOSI_PIN 11
#define SDCARD_SCK_PIN 13
// And those used for inputs
#define HOOK_PIN 0
#define PLAYBACK_BUTTON_PIN 1

SPI.setMOSI(SDCARD_MOSI_PIN);
SPI.setSCK(SDCARD_SCK_PIN);
if (!(SD.begin(SDCARD_CS_PIN))) {
// stop here if no SD card, but print a message
while (1) {
Serial.println("Unable to access the SD card" );
Serial.println(SDCARD_CS_PIN );
delay(500);
}
}
 
Those are the default SPI pins so the .set's are not needed.

Make sure a properly formatted and readable card is inserted.
> Try one of the included SD example sketches to listfiles with CS set to 10.

With the Rev D Audio shield properly soldered to the T_4.0 that should work.
 
Those are the default SPI pins so the .set's are not needed.

Make sure a properly formatted and readable card is inserted.
> Try one of the included SD example sketches to listfiles with CS set to 10.
Hey thank you for the respond . This is my first time doing a project period . I just did soldering myself . Regarding format, I don’t know what you mean by format. I don’t know how but it worked one time and then stopped working again .

With the Rev D Audio shield properly soldered to the T_4.0 that should work.

I have the 4.0 teensy solder to the audio shield I use multimeter and see connection :( . I don’t know what else to test or do

How do I make the format working ?
Found out the format of the card is FAT 32 . I am surprise it worked for short period of time
 
Last edited:
Did you try the installed example: {local install}\hardware\teensy\avr\libraries\SD\examples\listfiles\listfiles.ino

That even has the default: const int chipSelect = 10;

That should work with a properly installed IDE (1.8.19) and TeensyDuino (1.56)
 
Did you try the installed example: {local install}\hardware\teensy\avr\libraries\SD\examples\listfiles\listfiles.ino

That even has the default: const int chipSelect = 10;

That should work with a properly installed IDE (1.8.19) and TeensyDuino (1.56)

I actually just tried it now it works.

one thing is i found this github code that supposed to play greeting recording everytime and record your voice. but I cant hear the greeting. I hear the beep but not the greeting message. any idea why it wont be able to read the message?


Code:
SPI.setMOSI(SDCARD_MOSI_PIN);
  SPI.setSCK(SDCARD_SCK_PIN);
  if (!(SD.begin(SDCARD_CS_PIN))) {
    // stop here if no SD card, but print a message
    while (1) {
      Serial.println("Unable to access the SD card" );
       Serial.println(SDCARD_CS_PIN );
      delay(500);
    }
  }

  // Value in dB
  sgtl5000_1.micGain(20);

  setSyncProvider(getTeensy3Time);
  
  // Define a callback that will assign the correct datetime for any file system operations
  // (i.e. saving a new audio recording onto the SD card)
  FsDateTime::setCallback(dateTime);

  mode = Mode::Ready;
}

void loop() {
  // First, read the buttons
  buttonRecord.update();
  buttonPlay.update();

  switch(mode){
    case Mode::Ready:
      // Rising edge occurs when the handset is lifted
      if (buttonRecord.risingEdge()) {
        Serial.println("Handset lifted");
        mode = Mode::Prompting;
      }
      else if(buttonPlay.fallingEdge()) {
        playAllRecordings();
      }
      break;

    case Mode::Prompting:
      // Wait a second for users to put the handset to their ear
      wait(1000);
      // Play the greeting inviting them to record their message
      playWav1.play("greeting.wav");    
      // Wait until the  message has finished playing
      while (playWav1.isPlaying()) {
        // Check whether the handset is replaced
        buttonRecord.update();
        // Handset is replaced
        if(buttonRecord.fallingEdge()) {
          playWav1.stop();
          mode = Mode::Ready;
          return;
        }
      }
      // Debug message
      Serial.println("Starting Recording");
      // Play the tone sound effect
      waveform1.frequency(440);
      waveform1.amplitude(0.9);
      wait(250);
      waveform1.amplitude(0);
      // Start the recording function
      startRecording();
      break;

    case Mode::Recording:
      // Handset is replaced
      if(buttonRecord.fallingEdge()){
        // Debug log
        Serial.println("Stopping Recording");
        // Stop recording
        stopRecording();
        // Play audio tone to confirm recording has ended
        waveform1.frequency(523.25);
        waveform1.amplitude(0.9);
        wait(50);
        waveform1.amplitude(0);
        wait(50);
        waveform1.amplitude(0.9);
        wait(50);
        waveform1.amplitude(0);
      }
      else {
        continueRecording();
      }
      break;

    case Mode::Playing:
      break;  
  }   
}

void startRecording() {
  // Find the first available file number
  for (uint8_t i=0; i<9999; i++) {
    // Format the counter as a five-digit number with leading zeroes, followed by file extension
    snprintf(filename, 11, " %05d.RAW", i);
    // Create if does not exist, do not open existing, write, sync after write
    if (!SD.exists(filename)) {
      break;
    }
  }
  frec = SD.open(filename, FILE_WRITE);
  if(frec) {
    Serial.print("Recording to ");
    Serial.println(filename);
    queue1.begin();
    mode = Mode::Recording;
  }
  else {
    Serial.println("Couldn't open file to record!");
  }
}

void continueRecording() {
  // Check if there is data in the queue
  if (queue1.available() >= 2) {
    byte buffer[512];
    // Fetch 2 blocks from the audio library and copy
    // into a 512 byte buffer.  The Arduino SD library
    // is most efficient when full 512 byte sector size
    // writes are used.
    memcpy(buffer, queue1.readBuffer(), 256);
    queue1.freeBuffer();
    memcpy(buffer+256, queue1.readBuffer(), 256);
    queue1.freeBuffer();
    // Write all 512 bytes to the SD card
    frec.write(buffer, 512);
  }
}

void stopRecording() {
  // Stop adding any new data to the queue
  queue1.end();
  // Flush all existing remaining data from the queue
  while (queue1.available() > 0) {
    // Save to open file
    frec.write((byte*)queue1.readBuffer(), 256);
    queue1.freeBuffer();
  }
  // Close the file
  frec.close();
  mode = Mode::Ready;
}
 
Last edited by a moderator:
Are the sound files actually on your SD card with the same data format and filenames this program expects?
@paulStoffregen
yes there is file called greeting there

now I am getting complie errer

C:\Users\airbez\AppData\Local\Temp\arduino_build_115709\libraries\Wire\WireIMXRT.cpp.o: In function `TwoWire::endTransmission(unsigned char)':
C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Wire/WireIMXRT.cpp:230: undefined reference to `yield'
C:\Users\airbez\AppData\Local\Temp\arduino_build_115709\libraries\Wire\WireIMXRT.cpp.o: In function `TwoWire::requestFrom(unsigned char, unsigned char, unsigned char)':
C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Wire/WireIMXRT.cpp:286: undefined reference to `yield'
C:\Users\airbez\AppData\Local\Temp\arduino_build_115709\sketch\AudioGuessBook.ino.cpp.o: In function `FsBaseFile::isOpen() const':
C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src/FsLib/FsFile.h:279: undefined reference to `Serial'
C:\Users\airbez\AppData\Local\Temp\arduino_build_115709\sketch\AudioGuessBook.ino.cpp.o: In function `wait(unsigned int)':
C:\Users\airbez\AudioGuessBook/AudioGuessBook.ino:316: undefined reference to `Serial'
C:\Users\airbez\AppData\Local\Temp\arduino_build_115709\sketch\AudioGuessBook.ino.cpp.o: In function `setup':
C:\Users\airbez\AudioGuessBook/AudioGuessBook.ino:124: undefined reference to `Serial'
C:\Users\airbez\AppData\Local\Temp\arduino_build_115709\sketch\AudioGuessBook.ino.cpp.o: In function `playAllRecordings()':
C:\Users\airbez\AudioGuessBook/AudioGuessBook.ino:291: undefined reference to `Serial'
C:\Users\airbez\AppData\Local\Temp\arduino_build_115709\sketch\AudioGuessBook.ino.cpp.o: In function `loop':
C:\Users\airbez\AudioGuessBook/AudioGuessBook.ino:157: undefined reference to `Serial'
C:\Users\airbez\AppData\Local\Temp\arduino_build_115709\libraries\SdFat\SdCard\SdioTeensy.cpp.o: In function `SysCall::yield()':
c:\program files (x86)\arduino\hardware\teensy\avr\libraries\sdfat\src\common/syscall.h:90: undefined reference to `yield'
C:\Users\airbez\AppData\Local\Temp\arduino_build_115709/..\arduino_cache_162580\core\core_88a2d4dfef9509c3677628f3762a6fb0.a(delay.c.o): In function `delay':
C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy4/delay.c:62: undefined reference to `yield'
C:\Users\airbez\AppData\Local\Temp\arduino_build_115709/..\arduino_cache_162580\core\core_88a2d4dfef9509c3677628f3762a6fb0.a(usb_serial.c.o): In function `usb_serial_write':
C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy4/usb_serial.c:362: undefined reference to `yield'
C:\Users\airbez\AppData\Local\Temp\arduino_build_115709/..\arduino_cache_162580\core\core_88a2d4dfef9509c3677628f3762a6fb0.a(main.cpp.o): In function `main':
C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy4/main.cpp:54: undefined reference to `yield'
collect2.exe: error: ld returned 1 exit status
Error compiling for board Teensy 4.0.
 
nvm i got it figured out . but still doesnt read the greeting and it only plays the beep one time
 
I have a Teensy 4.0 with Audio shield Rev D2 hooked up with soldered on headers. I've tried everything but the SD Card just doesn't detect. Keeps showing "Unable to access the SD card".

Going by this comment, I've checked with a multimeter the connection of the G pin between 5v and 3.3v and the GND pin and they are connected. CS is set to 10. I've also tried 7 through 14.

What am I doing wrong?? Would really appreciate the help.
 
Hi friend..

This is how I check my SD card

Code:
// init SD card on Teensy 4.1 ---------------------------

    if (!SD.begin(chipSelect)) {       // chipSelect is 254
         Serial.print("No SD card!");
        while(1) { };
    }
    else {
        Serial.print("SD card is connected");
    }
 
Hello, I have the same issue here.

Here is my setup:
* Teensy 4.0
* Audio Shield
* SD Card inserted (PNY 64G)
Not able to run the listfiles

Getting these error messages on the serial monitor
Initializing SD card...initialization failed!
Initializing SD card...initialization failed!
Initializing SD card...initialization failed!
Initializing SD card...initialization failed!
Initializing SD card...initialization failed!
Initializing SD card...initialization failed!

This is my code

/*
SD card basic directory list example

This example shows how to create and destroy an SD card file
The circuit:
* SD card attached to SPI bus as follows:
** MOSI - pin 11, pin 7 on Teensy with audio board
** MISO - pin 12
** CLK - pin 13, pin 14 on Teensy with audio board
** CS - pin 4, pin 10 on Teensy with audio board

created Nov 2010
by David A. Mellis
modified 9 Apr 2012
by Tom Igoe

This example code is in the public domain.

*/
#include <SD.h>
// change this to match your SD shield or module;
// Teensy 2.0: pin 0
// Teensy++ 2.0: pin 20
// Wiz820+SD board: pin 4
// Teensy audio board: pin 10
// Teensy 3.5 & 3.6 & 4.1 on-board: BUILTIN_SDCARD
const int chipSelect = 10;
void setup()
{
//Uncomment these lines for Teensy 3.x Audio Shield (Rev C)
// SPI.setMOSI(7); // Audio shield has MOSI on pin 7
// SPI.setSCK(14); // Audio shield has SCK on pin 14

// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect.
}
Serial.print("Initializing SD card...");
if (!SD.begin(chipSelect)) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");
File root = SD.open("/");

printDirectory(root, 0);

Serial.println("done!");
}
void loop()
{
// nothing happens after setup finishes.
}
void printDirectory(File dir, int numSpaces) {
while(true) {
File entry = dir.openNextFile();
if (! entry) {
//Serial.println("** no more files **");
break;
}
printSpaces(numSpaces);
Serial.print(entry.name());
if (entry.isDirectory()) {
Serial.println("/");
printDirectory(entry, numSpaces+2);
} else {
// files have sizes, directories do not
int n = log10f(entry.size());
if (n < 0) n = 10;
if (n > 10) n = 10;
printSpaces(50 - numSpaces - strlen(entry.name()) - n);
Serial.print(" ");
Serial.print(entry.size(), DEC);
DateTimeFields datetime;
if (entry.getModifyTime(datetime)) {
printSpaces(4);
printTime(datetime);
}
Serial.println();
}
entry.close();
}
}
void printSpaces(int num) {
for (int i=0; i < num; i++) {
Serial.print(" ");
}
}
void printTime(const DateTimeFields tm) {
const char *months[12] = {
"January","February","March","April","May","June",
"July","August","September","October","November","December"
};
if (tm.hour < 10) Serial.print('0');
Serial.print(tm.hour);
Serial.print(':');
if (tm.min < 10) Serial.print('0');
Serial.print(tm.min);
Serial.print(" ");
Serial.print(tm.mon < 12 ? months[tm.mon] : "???");
Serial.print(" ");
Serial.print(tm.mday);
Serial.print(", ");
Serial.print(tm.year + 1900);
}

What am I missing?

Thank you!
JRaghavan
 
What am I missing?

Photos of the hardware are what's missing here. The problem is almost certainly poor soldering or a wiring mistake or misunderstanding.

I can confirm 64GB cards definitely do work with the audio shield and Teensy 4.0.

We can help you get the hardware connected properly, but to advise how to fix things we need to be able to actually see the hardware as you've connected.
 
Hi,
I am building an audio guest book using Teensy 4.0 and Audioshield Rev D2. I have a similar problem with initializing SD Card.

In the very beginning when I was using code for audio guestbook from github (https://github.com/playfultechnology/audio-guestbook?tab=readme-ov-file#readme) which is mentioned in the first post from Ninja, everything, includes SD Card, was working correctly.

After recording about 6 wav SD Card suddenly stops working.

I've tested few different SD Cards (128 MB Sandisk, Kingston Canvas Select Plus 64 GB A1 and Kingston 1GB) with Audio Example from Arduino IDE (file->examples->audio->hardware testing->sd card->sd card test) and they still don't work.

I checked soldering with multimeter and it looks like my wiring is correct.

I have no idea what can I do to fix this problem. I attached some pictures. Could You please advise something?


1.jpeg
 

Attachments

  • 2.jpeg
    2.jpeg
    149.8 KB · Views: 57
  • 3.jpeg
    3.jpeg
    148 KB · Views: 58
Try re-heating the solder on pin 13 underneath the audio shield.

1710410167945.png


For reference, check out this soldering tutorial.


Look at "Cold Joint" on the 2nd row. There's a good chance the solder ball is just sitting on top of the PCB's metal surface, maybe touching sometimes but other times not making good contact. Just reheating the solder so it flows properly should be enough.

As you inspect the rest of the solder, the SD card only depends on pins 10, 11, 12, 13, 3.3V and GND (next to pin 0). Focus only on those 6 pins.
 
Try re-heating the solder on pin 13 underneath the audio shield.

View attachment 33674

For reference, check out this soldering tutorial.


Look at "Cold Joint" on the 2nd row. There's a good chance the solder ball is just sitting on top of the PCB's metal surface, maybe touching sometimes but other times not making good contact. Just reheating the solder so it flows properly should be enough.

As you inspect the rest of the solder, the SD card only depends on pins 10, 11, 12, 13, 3.3V and GND (next to pin 0). Focus only on those 6 pins.

Hello,
I've reheated all joints that looked 'suspicious' - especially pins 10, 11, 12, 13, 3.3V and GND as you sugested. It seems that was the problem!

Correcting the soldering not only helped with SD Card but also improved sound quality of recordings and sound quality in telephone speaker.
I added photos of new solders for everyone who wants to compare before and after

Thank You for fast and professional help!
 

Attachments

  • Zrzut ekranu 2024-03-25 174330.png
    Zrzut ekranu 2024-03-25 174330.png
    816.2 KB · Views: 72
  • IMG_0334.JPEG
    IMG_0334.JPEG
    159.7 KB · Views: 51
Back
Top