SD Card Folder not able to play more than 9 songs

Hello all

                I am using SD Card module and a saved folder  with 10 songs  inside the memory card

With general player code this one is not able to play after 9th song or a 9th audio short duration file

Labels are all good and formats are all OK but still it resets the arduino infact

Whats the issue and how to solve it

Show the code.
It seems like that the code has a problem with two-digit numbers :slight_smile:

Ya i thought same

if (tmrpcm.isPlaying() && digitalRead(2))
          {
          digitalWrite(IndiLiteA,1);
          }
        else
          {
          digitalWrite(IndiLiteA,0);
          }


        if (tmrpcm.isPlaying() && digitalRead(3))
          {
          digitalWrite(IndiLiteB,1);
          }
        else
          {
          digitalWrite(IndiLiteB,0);
          }

normal type code

Is this type of thing goes well ??

tmrpcm.play("/1/010.wav");

or need upgradation ??

please show ALL the code

For MEGA

#include <stdio.h>
#include <SD.h>
#include <SPI.h>
#include <TMRpcm.h>
#define SD_ChipSelectPin 53

TMRpcm tmrpcm;

const int pins[1] = {13};
int m = 10;
 
void setup()



{
tmrpcm.speakerPin = (46);


//Serial.begin(9600);
if (!SD.begin(SD_ChipSelectPin)) 

{
Serial.println("SD fail");
return;
}


{
for (int i=0; i<6; i++)
{
pinMode(pins[i], OUTPUT);
}

  // put your setup code here, to run once:

pinMode(22, INPUT_PULLUP);
pinMode(23, INPUT_PULLUP);
pinMode(24, INPUT_PULLUP);
pinMode(25, INPUT_PULLUP);
pinMode(26, INPUT_PULLUP);
pinMode(27, INPUT_PULLUP);
pinMode(28, INPUT_PULLUP);
pinMode(29, INPUT_PULLUP);
pinMode(30, INPUT_PULLUP);
pinMode(31, INPUT_PULLUP);

}

}

void loop()                 // put your main code here, to run repeatedly:

{

  while(digitalRead(22)==0 || digitalRead(23)==0 || digitalRead(24)==0 || digitalRead(25)==0 || digitalRead(26)==0 || digitalRead(27)==0 || digitalRead(28)==0 || digitalRead(29)==0 || digitalRead(30)==0 || digitalRead(31)==0)

{
  if (digitalRead(22) == LOW)
  {
    m = 0;
    while(digitalRead(22)==0);
    delay(5);
  }

   if (digitalRead(23) == LOW)
  {
    m = 1;
    while(digitalRead(23)==0);
    delay(5);
  }

   if (digitalRead(24) == LOW)
  {
    m = 2;
    while(digitalRead(24)==0);
    delay(10);
  }

    if (digitalRead(25) == LOW)
  {
    m = 3;
    while(digitalRead(25)==0);
    delay(10);
  }

  if (digitalRead(26) == LOW)
  {
    m = 4;
    while(digitalRead(26)==0);
    delay(10);
  }
if (digitalRead(27) == LOW)
  {
    m = 5;
    while(digitalRead(27)==0);
    delay(10);
  }
if (digitalRead(28) == LOW)
  {
    m = 6;
    while(digitalRead(28)==0);
    delay(10);
  }
if (digitalRead(29) == LOW)
  {
    m = 7;
    while(digitalRead(29)==0);
    delay(10);
  }
if (digitalRead(30) == LOW)
  {
    m = 8;
    while(digitalRead(30)==0);
    delay(10);
  }
if (digitalRead(31) == LOW)
  {
    m = 9;
    while(digitalRead(32)==0);
    delay(10);
  }


switch (m) {
   
   case 0: {

     tmrpcm.play("/1/001.wav");
     break;   
   }

   case 1: {
 
     tmrpcm.play("/1/002.wav");
     break;
   }

   case 2: {
     tmrpcm.play("/1/003.wav");
     break;
   }

   case 3: {
 
     tmrpcm.play("/1/004.wav");
     break;
   }

  case 4: {
     
     tmrpcm.play("/1/005.wav");
     break;
   
   }

  case 5: {
     
     tmrpcm.play("/1/006.wav");
     break;
   
   }

  case 6: {
     
     tmrpcm.play("/1/007.wav");
     break;
   
   }

  case 7: {
     
     tmrpcm.play("/1/008.wav");
     break;
   
   }

  case 8: {
     
     tmrpcm.play("/1/009.wav");
     break;
   
   }

  case 9: {
     
     tmrpcm.play("/1/010.wav");
     break;
   
   }


   return 0;
}

}
     
}

I just check and this one is not playing more than 9 files out of folder also . .

What the heck here ??

How do you check it?
You have 10 files in the code and said that only 9 from them works. Which file is not working?

Btw this is a bad mistake:

Your pins array has only one element, but you try to access up to sixth one in the for loop

And I don't see why do you need this array at all - you don't use it in the code

The 10th File is not working

In fact this one is resets the arduino and sometime starts a very high level distorting noise on speakers

Ya and that for loop blah blah things are from old startup scripts and continuing like that only and i am not using any of that on hardware

So now having final script

#include <stdio.h>
#include <SD.h>
#include <SPI.h>
#include <TMRpcm.h>
#define SD_ChipSelectPin 53

TMRpcm tmrpcm;

int m = 10;
 
void setup()



{
tmrpcm.speakerPin = (46);


//Serial.begin(9600);
if (!SD.begin(SD_ChipSelectPin)) 

{
Serial.println("SD fail");
return;
}


                                                  // put your setup code here, to run once:

pinMode(22, INPUT_PULLUP);
pinMode(23, INPUT_PULLUP);
pinMode(24, INPUT_PULLUP);
pinMode(25, INPUT_PULLUP);
pinMode(26, INPUT_PULLUP);
pinMode(27, INPUT_PULLUP);
pinMode(28, INPUT_PULLUP);
pinMode(29, INPUT_PULLUP);
pinMode(30, INPUT_PULLUP);
pinMode(31, INPUT_PULLUP);



}

void loop()                 // put your main code here, to run repeatedly:

{

  while(digitalRead(22)==0 || digitalRead(23)==0 || digitalRead(24)==0 || digitalRead(25)==0 || digitalRead(26)==0 || digitalRead(27)==0 || digitalRead(28)==0 || digitalRead(29)==0 || digitalRead(30)==0 || digitalRead(31)==0)

{
  if (digitalRead(22) == LOW)
  {
    m = 0;
    while(digitalRead(22)==0);
    delay(5);
  }

   if (digitalRead(23) == LOW)
  {
    m = 1;
    while(digitalRead(23)==0);
    delay(5);
  }

   if (digitalRead(24) == LOW)
  {
    m = 2;
    while(digitalRead(24)==0);
    delay(10);
  }

    if (digitalRead(25) == LOW)
  {
    m = 3;
    while(digitalRead(25)==0);
    delay(10);
  }

  if (digitalRead(26) == LOW)
  {
    m = 4;
    while(digitalRead(26)==0);
    delay(10);
  }
if (digitalRead(27) == LOW)
  {
    m = 5;
    while(digitalRead(27)==0);
    delay(10);
  }
if (digitalRead(28) == LOW)
  {
    m = 6;
    while(digitalRead(28)==0);
    delay(10);
  }
if (digitalRead(29) == LOW)
  {
    m = 7;
    while(digitalRead(29)==0);
    delay(10);
  }
if (digitalRead(30) == LOW)
  {
    m = 8;
    while(digitalRead(30)==0);
    delay(10);
  }
if (digitalRead(31) == LOW)
  {
    m = 9;
    while(digitalRead(32)==0);
    delay(10);
  }


switch (m) {
   
   case 0: {

     tmrpcm.play("001.wav");
     break;   
   }

   case 1: {
 
     tmrpcm.play("002.wav");
     break;
   }

   case 2: {
     tmrpcm.play("003.wav");
     break;
   }

   case 3: {
 
     tmrpcm.play("004.wav");
     break;
   }

  case 4: {
     
     tmrpcm.play("005.wav");
     break;
   
   }

  case 5: {
     
     tmrpcm.play("006.wav");
     break;
   
   }

  case 6: {
     
     tmrpcm.play("007.wav");
     break;
   
   }

  case 7: {
     
     tmrpcm.play("008.wav");
     break;
   
   }

  case 8: {
     
     tmrpcm.play("009.wav");
     break;
   
   }

  case 9: {
     
     tmrpcm.play("010.wav");
     break;
   
   }


   return 0;
}

}
     
}

But this time also same issue with the 10th file

where I am putting all the files out of the folder and make the settings as per that in code !!

I think the reason is not in the file. Firstly, there is a bad error in your code that can lead to reset, and secondly, there is a lot of unnecessary stuff in it.

No its just a single folder with 10 files only and the whole card is properly formatted and was empty before the use

So now what about the code error You are finding it above ?

Is there anything with names ??

Try to playing with filenames. So if you create files like "010.wav"... "015.wav" and put it in the folder ( only 6 files) ?
And second - what will be if created 12 files with names like "a.wav"... "k.wav" ?

Oh OK let me go through that first !!!

I shortened your code a bit, try this one

#include <stdio.h>
#include <SD.h>
#include <SPI.h>
#include <TMRpcm.h>
#define SD_ChipSelectPin 53

TMRpcm tmrpcm;

void setup()
{
  tmrpcm.speakerPin = (46);
  Serial.begin(9600);
  if (!SD.begin(SD_ChipSelectPin))
  {
    Serial.println("SD fail");
    return;
  }

  for (byte i = 22; i < 32; i++) pinMode(i, INPUT_PULLUP);
}

void loop()                 // put your main code here, to run repeatedly:
{
  int m = 10;
  for (byte i = 22; i < 32; i++)
  {
    if (digitalRead(i) == LOW)
    {
      m = i - 22;
      while (digitalRead(i) == 0);
      delay(5);
      break;
    }
  }

  const char* songs[10] = {"001.wav", "002.wav", "003.wav", "004.wav", "005.wav",
                       "006.wav", "007.wav", "008.wav", "009.wav", "010.wav"
                      };

  if (m < 10) tmrpcm.play(songs[m]);
  
}

Installation and Troubleshooting is for Problems with the Arduino IDE itself NOT your project. It says so in the description of the section.

Therefore I have moved your post here. Please be more careful where you post in future.

You may want to read this before you proceed:-
how to get the best out of this forum

1 Like

Oh that's very kind of you and thanks a lot for the help

I ll definitely take care of this further !!! :slight_smile:

O woww !! That is working great and with no issues and no other kind of disturbance !!!

What i am thinking that - Suppose i want to make any of the file under a loop system then to go for it ??

Like tmrpcm.loop(1) type of thing for particular individuals

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.