using the Wire.h library causes a problem

Hi,

I have a problem: I am trying to play a set of sounds in a loop, and using the Wire.h library causes my system to skip the first two(2) instances. after the first two , all is well again. (no actual use of Wire.h was made yet, just including the library at the begining).

if I don’t use the Wire.h , it works fine (but I want it as I am to add an LCD display).

I am using the TMRpcm library for playing the sounds.

any help on this will be very appreciated …

Thanks!

#include <Wire.h>
#include <TMRpcm.h>  
#include <SD.h>


//#include <Adafruit_BMP085.h>

TMRpcm tmrpcm;
//Adafruit_BMP085 bmp;


int ist;
int digipin1 = 6;  //  white
int stopping = 0;
String station = "";
String Nstation = "";
char stationchar[20];
char Nstationchar[20];
float alt = 0;


void setup()
{
  
  Serial.begin(38400);
  pinMode(digipin1, INPUT);      // sets the digital pin 6 as input (stopped=0 , moving=1)
 
  tmrpcm.speakerPin = 9; //Set speaker output pin to 9 
  pinMode(9, INPUT);
   if (!SD.begin(10)) {
    Serial.println("SD card initialization failed!");

    return;
  }
  
  //digitalWrite(9,HIGH);
  //tmrpcm.volume(1);
    
  delay(1000);
  
  
   
// if (!bmp.begin()) {
//	Serial.println("Could not find a valid BMP085 sensor, check wiring!");
//	while (1) {}
// }


ist = 0;
}



String Stationname(int ist)
{
  String service;
  switch(ist) {
       case (1):
       service = ("paris");
       break;
       case (2):
       service = ("solel");
       break;
       case (3):
       service = ("neviim");
       break;
       case (4):
       service = ("masada");
       break;
       case (5):
       service = ("golomb");
       break;
       case (6):
       service = ("ganhaem");
       break;
       case (7):
       service = ("golomb");
       break;
       case (8):
       service = ("masada");
       break;
       case (9):
       service = ("neviim");
       break;
       case (10):
       service = ("solel");
       break;
       case (11):
       service = ("paris");
       break;
 
  }
  return service;
}



void loop()
{

stopping = digitalRead(digipin1);


    if (stopping > 0.8) {
      Serial.print("ist = ");
      Serial.println(ist);
      if (ist < 0.5)
      {
                  ist = 1;
      }
      else if (ist > 10.5)
      {
                 ist = 1;
               station = ("A" + Stationname(ist) + ".wav"); 
               station.toCharArray(stationchar,15);
               tmrpcm.play(stationchar);
                Serial.println(stationchar);
                delay (10000);
      }
      else {
        station = ("A" + Stationname(ist) + ".wav"); 
        station.toCharArray(stationchar,15);
        tmrpcm.play(stationchar);
        Serial.println(stationchar);
        delay (10000);  
      }
        while (stopping > 0.8){
          stopping = digitalRead(digipin1);
          delay(500);
          
        }  
        
      if (stopping < 0.2) {
          
         delay(10000);
                
                  ist = ist+1;
                  Serial.println(ist);
            
             Nstation = ("C" + Stationname(ist) + ".wav");
             Nstation.toCharArray(Nstationchar,15);
             delay(1000);
             tmrpcm.play(Nstationchar);
             Serial.println(Nstationchar);
             delay(6000);

        }
      
    }


Serial.print("  stopping=");
Serial.println(stopping);
Serial.println("");
delay(1000);

}

Which Arduino are you using? Check sram usage. Maybe low on sram. I know the sd library uses a lot, but i don't know about the other libraries. You can gain some sram back by using the F() macro on the string literals (like print(F("some string "));).