LCD printing weird characters in loop function

Hi, I'm working on a project that plays wav files from an SD card and prints a number for the song playing. I am using the Tmrpcm library and in the loop function of my sketch the lcd replaces my normal text with odd special characters. However the text in setup is normal. I believe to have narrowed it down to the program because the "hello world" example works just fine.

Here is my sketch:

#include <pcmRF.h>
#include <TMRpcm.h>
#include <SD.h>
#define SD_ChipSelectPin 10
#include <LiquidCrystal.h>

LiquidCrystal lcd(7, 8, 5, 6, 11, 12);
byte face[8] = {
  B01110,
  B10001,
  B11011,
  B10001,
  B10101,
  B01110,
  B00100,
  };

  TMRpcm tmrpcm;
  int track = 1;
  
  const int button1 = 4;
  const int button2 = 2;
  const int button3 = 3;
  int state1 = 0;
  int state2 = 0;
  int state3 = 0;

void setup(){ 
  lcd.createChar(0, face);
  lcd.begin(16, 2);
  lcd.write(byte(0));
  lcd.print(" AudioMan Rdy!");
  lcd.setCursor(0, 1);
  lcd.print("Select Trk 1-6");
  
  SD.begin(SD_ChipSelectPin);
  tmrpcm.speakerPin = 9;
  tmrpcm.play("BNV.wav");
  
  pinMode(button1, INPUT);
  pinMode(button2, INPUT);
  pinMode(button3, INPUT);
}

void loop(){
  if (track > 6) {    //Constrain numbers.
    track = 0;}
  if (track < 0) {
    track = 0;}
    
    state3 = digitalRead(button3);    //Button control.
    state2 = digitalRead(button2);
    state1 = digitalRead(button1);
    
    if (state3 == HIGH) {
      track = track + 1;
      delay(250);}
    if (state2 == HIGH) {
      track = 0;
      delay(250);}
    if (state1 == HIGH) {
      track = track - 3;
      delay(250);}
      
    if (track == 2) {    //Audio tracks.
      tmrpcm.play("BN3t.wav");
      track = 3;}
    else if(track == 0){ 
      tmrpcm.stopPlayback();}
    else if(track == 4){ 
      tmrpcm.play("BN4f.wav");
      track = 5;} 
}

Any help would be grealty appreciated. Thanks!

Your libraries are most likely using the same pins. Are they loose boards connected by wires, or stacked on top of each other?

Your limit check on the track number needs to be AFTER you change, not BEFORE you change it.

I have put the track limit at the end of the sketch and still have the error. I am using an SD shield that uses pin 10 and a homemade speaker shield that uses pin 9. The LCD and buttons are connected by wires from the breadboard. As far as I know they aren't using the same pins.

The PCM library uses pin 9 by default, and pin 10 for complimentary output. Either use a different pin (10) fro the SD shield or change the following lines in TMRpcm.cpp

from:

*OCRnA[tt] = *OCRnB[tt] = buffer[whichBuff][buffCount];

to:

*OCRnA[tt] = buffer[whichBuff][buffCount];

And this:

*TCCRnA[tt] = _BV(WGM11) | _BV(COM1A1) | _BV(COM1B0) | _BV(COM1B1);

to this:

*TCCRnA[tt] = _BV(WGM11) | _BV(COM1A1) ;

Not 100% sure if that is what is causing your specific problem, but figure it would... also SD cards usually use pins 11 and 12 for miso/mosi, so kind of wondering if multiple pins are being used between LCD and SD.