What is an AFM file?

Hi, I'm trying to use Simple SD Audio.

My codes are standard but I don't get any sound with Wav file. My product is Arduino Mega but my adaptor for Micro SD.

This is my code for this;

#include <SimpleSDAudio.h>
 
void setup()
{
 
SdPlay.setSDCSPin(4);
 
if (!SdPlay.init(SSDA_MODE_FULLRATE | SSDA_MODE_MONO | SSDA_MODE_AUTOWORKER))


if(!SdPlay.setFile("91.wav"))

{}
}
 
void loop(void) {
 
if(Serial.read() == 'p'){SdPlay.play();}
}

Also this is not work with standard internet codes. Do I need a AFM file?

AFM file
But why do you think you need one?

Check that the library you are using is suitable for the Mega.

How have you wired up the Arduino to the speaker?

For Mega, 44 (and GND) for Speaker, 50-51-52 (MISO, MOSI, SCK) and 4 (SD_CS) for Micro SD.

My PCM (Wav) file specifications are like this;

8 bit (Unsigned), 16000 Hz, Mono. If I can use Simple SD Audio, actually there is not a problem, but i can't.

How i can get this sound?

You have not answered my question:-

How have you wired up the Arduino to the speaker?

Also an SD card is 3V3 and you have a 5V Arduino so have you got level shifters on those pins like it says here?

If I can use Simple SD Audio, actually there is not a problem, but i can't.

Correct you need to convert your wav file, have you seen: SimpleSDAudio – Hackerspace Ffm

Is your SD card formatted as a FAT file system?

The file extension AFM is made up by the author, it is not a standard name, that is why you can find no trace of it. Have you followed the instructions for changing your file format.

Why not use TMRpcm, then you don't have to convert the file? Home · TMRh20/TMRpcm Wiki · GitHub

I did, TMRpcm works perfect but TMRpcm and bluetooth (Hardware Serial) don't work together. With Simple SD Audio, bluetooth works perfect but i don't get any sound. Actually, i don't get any sound with standard internet codes too.

My Arduino and Speaker connected or wired well. (I know, because TMRpcm works perfect by itself)

My Micro SD Card Product has a voltage regulator. (5V to 3.3V)

So, I'm trying a little bit more. Thank you.

TMRpcm and bluetooth (Hardware Serial) don't work together.

Their is no technical reason why that should be true, they do not use the same hardware resource.

My Micro SD Card Product has a voltage regulator. (5V to 3.3V)

I didn’t say that I said the DATA lines should have a voltage level shifter.

With Simple SD Audio, bluetooth works perfect but i don't get any sound.

That is a very odd definition of working perfectly. I would say no sounds means they are not working together.

Unless you start engaging and answering questions there is little I can do.

Ha ha, my english is not very good, sorry. By the way, i know you, your knowledge is very good.

In my micro SD card product, the shield has a regulator chip for all lines, so i don't need a level shifter, I'm sure, otherwise, TMRpcm did not work but did.

This is my whole code, maybe you can help. (tmrpcm.play is in buttonstate line)

#include <SD.h>                      // need to include the SD library
#define SD_ChipSelectPin 53  //using digital pin 4 on arduino nano 328, can use other pins
#include <TMRpcm.h>           //  also need to include this library...
#include <SPI.h>

TMRpcm tmrpcm;   // create an object for use in this sketch

#include <Servo.h>
int aci=90,i;
Servo myservo; 
int gecikme=40;
HardwareSerial &Bluetooth = Serial1;

// Variables used for incoming data
const byte maxDataLength = 20;
char receivedChars[21] ;
boolean newData = false;

// Pins de HC-SR04
const int trigger_sol = 33;
const int echo_sol = 35;

// Pins de HC-SR04
const int trigger_sag = 37;
const int echo_sag = 39;

// Constants for hardware
const byte m_PIN[] = {23,25,27,29};
boolean m_State[] = {false,false,false,false};

const int on_sol = 22;
const int on_orta = 24;
const int on_sag =  26;

const int hareket_sensoru_sol = 38;
const int hareket_sensoru_sag = 40;

int durum;
int engel_oku1;
int engel_oku2;
int engel_oku3;

void setup() {

   Serial.begin(9600);
    myservo.attach(10);
  // Configuración de los pines
    pinMode(trigger_sol, OUTPUT);
    pinMode(echo_sol, INPUT);


   pinMode(trigger_sag, OUTPUT);
   pinMode(echo_sag, INPUT);


  //Engel switchler pull-up olacak


    for (byte pin = 0; pin < 4; pin++) 
    {
         
         
       pinMode(m_PIN[pin], OUTPUT);  digitalWrite(m_PIN[pin],LOW);
    }
    
    pinMode(22,INPUT_PULLUP); // on_sol
    pinMode(24,INPUT_PULLUP); //on_orta
    pinMode(26,INPUT_PULLUP); 


    pinMode(38,INPUT);
    pinMode(40,INPUT);
    
    
  
    

 kafa_test();
 ileri_git(); delay(1000);dur();
 geri_git(); delay(200);dur();
 sola_don(); delay(200);dur();
 saga_don(); delay(200);dur();

 // open serial communication for debugging
    Serial.begin(9600);
    Serial.print("Sketch:   ");   Serial.println(__FILE__);
    Serial.print("Uploaded: ");   Serial.println(__DATE__);
    Serial.println(" ");
     
    //  open software serial connection to the Bluetooth module.
    Bluetooth.begin(9600); 
    Serial.println("Serial started at 9600"); 
          
    newData = false;




 
{

  tmrpcm.speakerPin = 46; //5,6,11 or 46 on Mega, 9 on Uno, Nano, etc

  Serial.begin(9600);
  if (!SD.begin(SD_ChipSelectPin)) {  // see if the card is present and can be initialized:
    Serial.println("SD fail");  
    return;   // don't do anything more if not
  }
}


}
//***********************************************************

void loop() {

    {engel_oku1 = digitalRead(22);

   if (engel_oku1 == LOW) {Bluetooth.print("<L,1,0>" );Bluetooth.print("<L,2,0>" );Bluetooth.print("<L,3,1>" );Bluetooth.print("<L,4,0>" ); 
   digitalWrite(23,LOW);digitalWrite(25, HIGH);digitalWrite(27, LOW);digitalWrite(29, HIGH);sistem_test();dur();Bluetooth.print("<L,3,0>" );}

   

   }
   
    {engel_oku2 = digitalRead(24);
   if (engel_oku2 == LOW) {Bluetooth.print("<L,1,0>" );Bluetooth.print("<L,2,1>" );Bluetooth.print("<L,3,0>" );Bluetooth.print("<L,4,0>" ); 
   digitalWrite(23,LOW);digitalWrite(25, HIGH);digitalWrite(27, HIGH);digitalWrite(29, LOW);sistem_test();dur();Bluetooth.print("<L,2,0>" );}

      
      }
   
    {engel_oku3 = digitalRead(26);
  
   if (engel_oku3 == LOW) {Bluetooth.print("<L,1,0>" );Bluetooth.print("<L,2,0>" );Bluetooth.print("<L,3,0>" );Bluetooth.print("<L,4,1>" ); 
   digitalWrite(23,HIGH);digitalWrite(25, LOW);digitalWrite(27,HIGH);digitalWrite(29, LOW);sistem_test();dur();Bluetooth.print("<L,4,0>" );}

    }
         
    recvWithStartEndMarkers();                // check to see if we have received any new commands
    if (newData)  {   processCommand();  }    // if we have a new command do something about it

   { Serial.println(" Hareket Kontrol Ediliyor ");
int buttonState_sol = digitalRead(38);
int buttonState_sag = digitalRead(40);

if (buttonState_sol == LOW) {Serial.println(" SOLDA ENGEL ");
Bluetooth.print("<L,1,0>" );Bluetooth.print("<L,3,1>");Bluetooth.print("<L,2,0>" );Bluetooth.print("<L,4,0>" );tmrpcm.play("kayra.wav"); 
   digitalWrite(25, HIGH);digitalWrite(29, HIGH);digitalWrite(23, LOW);digitalWrite(27, LOW);
   delay(2000);sistem_test();dur();Bluetooth.print("<L,3,0>");}

   
else if(buttonState_sag == LOW)

{ Serial.println(" SAGDA ENGEL ");
Bluetooth.print("<L,2,0>" );Bluetooth.print("<L,4,1>" );Bluetooth.print("<L,1,0>" );Bluetooth.print("<L,3,0>");tmrpcm.play("kayra.wav"); 
   digitalWrite(23, HIGH);digitalWrite(27, HIGH);digitalWrite(25, LOW);digitalWrite(29, LOW);delay(2000);sistem_test();dur();Bluetooth.print("<L,4,0>");}
   }



}


//***********************************************************
//***********************************************************
//***********************************************************
//***********************************************************


//+++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++


void sola_don()   // sola dön
{
digitalWrite(23, HIGH);digitalWrite(27, HIGH); delay(100);Serial.println("     SOLA donuyorum    "); durum=1;
}

void saga_don()
{
digitalWrite(25, HIGH);digitalWrite(29, HIGH); delay(100); Serial.println("     SAGA donuyorum    ");durum=1;
}


void ileri_git()  // geri git
{
digitalWrite(23, HIGH);digitalWrite(29, HIGH); delay(100);Serial.println("     ilerliyorum    ");durum=1;
}

void geri_git() // ileri olacak
{
digitalWrite(25, HIGH);digitalWrite(27, HIGH); delay(100);Serial.println("     GERi Gidiyorum    ");durum=1;
}

void dur()
{
    digitalWrite(23, LOW);
    digitalWrite(25, LOW);
    digitalWrite(27, LOW);
    digitalWrite(29, LOW);
    delay(500); Serial.println("     DURDUM    ");
}
//*******************************************************//


void kafa_test()
{
  
  for(i=1;i<=15;i=i+1)
  {
  aci=aci+5;
  myservo.write(aci); 
    // sets the servo position according to the scaled value
  delay(gecikme);   
  }
  Serial.print("1= "); Serial.println(aci); delay(500);
  
    for(i=1;i<=30;i=i+1)
  {
  aci=aci-5;
  myservo.write(aci);  
  delay(gecikme);   
  }
Serial.print("2= "); Serial.println(aci); delay(500);
    for(i=1;i<=15;i=i+1)
  {
    aci=aci+5;
  
  myservo.write(aci);   
   // sets the servo position according to the scaled value
  delay(gecikme);   
  }

Serial.print("3: "); Serial.println(aci); delay(500);
  delay(2000); 
   
  
}

void processCommand()
{
     Serial.print("receivedChars = ");   Serial.println(receivedChars);

    if (receivedChars[0] == 'L')      
    {
        
        
        byte mnum = receivedChars[1] - 48;          // convert ascii to value by subtracting 48
        boolean mstatus = receivedChars[2] - 48;
        
        digitalWrite(m_PIN[mnum-1],mstatus);
        m_State[mnum-1] = mstatus;
    }

    receivedChars[0] = '\0';
    newData = false;
}


void sistem_test()
{
  
  for(i=1;i<=5;i=i+1)
  {
  aci=aci+5;
  myservo.write(aci); 
    // sets the servo position according to the scaled value
  delay(gecikme);   
  }
  Serial.print("test1= "); Serial.println(aci); delay(500);
  
    for(i=1;i<=5;i=i+1)
  {
  aci=aci-5;
  myservo.write(aci);  
  delay(gecikme);   
  }
Serial.print("test2= "); Serial.println(aci); delay(500);
  
}

void recvWithStartEndMarkers()
{
     static boolean recvInProgress = false;
     static byte ndx = 0;
     char startMarker = '<';
     char endMarker = '>';
     char rc;
 
     if (Bluetooth.available() > 0) 
     {
          rc = Bluetooth.read();
          if (recvInProgress == true) 
          {
               if (rc != endMarker) 
               {
                    receivedChars[ndx] = rc;
                    ndx++;
                    if (ndx > maxDataLength) { ndx = maxDataLength; }
               }
               else 
               {
                     receivedChars[ndx] = '\0'; // terminate the string
                     recvInProgress = false;
                     ndx = 0;
                     newData = true;
               }
          }
          else if (rc == startMarker) { recvInProgress = true; }
     }
}

Hi, i do. I use Simple SD Audio for sound and ServoTimer2 for servo motor and also bluetooth can work. But there is a big distortion. Probably because of codes that working together, because there is so much codes but this is acceptable for me. Thank you.

The audio generation and the servo control both use the same timer so they will not work together. You might be able to hack one or other library but perhaps the easiest soloution would be to use some hardware to drive the servos.
Something like Overview | Adafruit PCA9685 16-Channel Servo Driver | Adafruit Learning System