problems shifting in with 74HC165N on Lilypad MP3

Hello.

I have been collaborating with someone on a project that uses the Sparkfun Lilypad MP3.

I used this schematic to incorporate only pins that didn’t have additional functions.

Shifting in is working perfectly fine when running this example code (confirmed by watching the serial monitor):
http://playground.arduino.cc/Code/ShiftRegSN74HC165N

However, once I’ve ported all of that code over into a sketch capable of playing MP3’s, I can’t even get serial monitor feedback to know whether or not the shift register input is successful. I still only have a few months of experience with micro controllers, so for all I know I could be messing up the timing somewhere.

As you can see in the code below, all I’m trying to do is print “100” if there is a change in the bit that was just shifted in.
Any advice? Thanks!

#include <SPI.h>            // To talk to the SD card and MP3 chip
#include <SdFat.h>          // SD card file system
#include <SFEMP3Shield.h>   // MP3 decoder chip

/* How many shift register chips are daisy-chained.
*/
#define NUMBER_OF_SHIFT_CHIPS   2

/* Width of data (how many ext lines).
*/
#define DATA_WIDTH   NUMBER_OF_SHIFT_CHIPS * 8

/* Width of pulse to trigger the shift register to read and latch.
*/
#define PULSE_WIDTH_USEC   5

/* Optional delay between shift register reads.
*/
#define POLL_DELAY_MSEC   1

/* You will need to change the "int" to "long" If the
 * NUMBER_OF_SHIFT_CHIPS is higher than 2.
*/
#define BYTES_VAL_T unsigned int


const int ploadPin        = 5;  // Connects to Parallel load pin the 165
const int clockEnablePin  = A1;  // Connects to Clock Enable pin the 165
const int dataPin         = 10; // Connects to the Q7 pin the 165
const int clockPin        = A0; // Connects to the Clock pin the 165

const int EN_GPIO1 = A2; // Amp enable + MIDI/MP3 mode select
const int SD_CS = 9;     // Chip Select for SD card


boolean debugging = false;

// Set interrupt = false if you would like a triggered file to
// play all the way to the end. If this is set to true, new
// triggers will stop the playing file and start a new one.

boolean interrupt = true;

// Set interruptself = true if you want the above rule to also
// apply to the same trigger. In other words, if interrupt = true
// and interruptself = false, subsequent triggers on the same
// file will NOT start the file over. However, a different trigger
// WILL stop the original file and start a new one.

boolean interruptself = false;

// We'll store the five filenames as arrays of characters.
// "Short" (8.3) filenames are used, followed by a null character.

char filename[15][13];

SFEMP3Shield MP3player;
SdFat sd;


BYTES_VAL_T buttonValues;
BYTES_VAL_T oldButtonValues;


void setup()
{

    Serial.begin(9600);

    int index;
    SdFile file;
    char tempfilename[13];


    /* Initialize our digital pins...
    */
    pinMode(ploadPin, OUTPUT);
    pinMode(clockEnablePin, OUTPUT);
    pinMode(clockPin, OUTPUT);
    pinMode(dataPin, INPUT);

    digitalWrite(clockPin, LOW);
    digitalWrite(ploadPin, HIGH);


    // The board uses a single I/O pin to select the
    // mode the MP3 chip will start up in (MP3 or MIDI),
    // and to enable/disable the amplifier chip:

    pinMode(EN_GPIO1,OUTPUT);
    digitalWrite(EN_GPIO1,LOW);  // MP3 mode / amp off


    // Initialize the SD card; SS = pin 9, half speed at first

    sd.begin(SD_CS, SPI_HALF_SPEED); // 1 for success


    // Start up the MP3 library

    MP3player.begin();


    // Start at the first file in root and step through all of them:

    sd.chdir("/",true);
    while (file.openNext(sd.vwd(),O_READ))
    {
        // get filename

        file.getFilename(tempfilename);

        // Does the filename start with char 'a' through 'o'?      

        if (tempfilename[0] >= 'A' && tempfilename[0] <= 'O')
        {
        // Yes! subtract char 'a' to get an index of 0 through 14.

            index = tempfilename[0] - 'A';
      
             // Copy the data to our filename array.

            strcpy(filename[index],tempfilename);
  
        }
      
        file.close();
    }



    // Set the VS1053 volume. 0 is loudest, 255 is lowest (off):

    MP3player.setVolume(50,50);
  
    // Turn on the amplifier chip:
  
    digitalWrite(EN_GPIO1,HIGH);
    
    oldButtonValues = buttonValues;

    delay(2);

}


void loop()
{
    /* Read the state of all zones.
    */
    buttonValues = read_shift_regs();

    /* If there was a chage in state, display which ones changed.
    */
    if(buttonValues != oldButtonValues)
    {

        Serial.println(100);
        //MP3player.stopTrack();
        //MP3player.playMP3(filename[random(0, 14)]);

        //play_audio();
        oldButtonValues = buttonValues;
    }


    delay(POLL_DELAY_MSEC);
    
   
}











/* This function is essentially a "shift-in" routine reading the
 * serial Data from the shift register chips and representing
 * the state of those pins in an unsigned integer (or long).
*/
BYTES_VAL_T read_shift_regs()
{
    long bitVal;
    BYTES_VAL_T bytesVal = 0;

    /* Trigger a parallel Load to latch the state of the data lines,
    */
    digitalWrite(clockEnablePin, HIGH);
    digitalWrite(ploadPin, LOW);
    delayMicroseconds(PULSE_WIDTH_USEC);
    digitalWrite(ploadPin, HIGH);
    digitalWrite(clockEnablePin, LOW);

    /* Loop to read each bit value from the serial out line
     * of the SN74HC165N.
    */
    for(int i = 0; i < DATA_WIDTH; i++)
    {
        bitVal = digitalRead(dataPin);

        /* Set the corresponding bit in bytesVal.
        */
        bytesVal |= (bitVal << ((DATA_WIDTH-1) - i));

        /* Pulse the Clock (rising edge shifts the next bit).
        */
        digitalWrite(clockPin, HIGH);
        delayMicroseconds(PULSE_WIDTH_USEC);
        digitalWrite(clockPin, LOW);
    }

    return(bytesVal);
}




/* Dump the list of zones along with their current status.
*/
void play_audio()
{
    int t;
    static int last_t;


    for(int t = 0; t < DATA_WIDTH; t++)
    {
        if((buttonValues >> t) & 0){
            
            if(interrupt && MP3player.isPlaying() && ((t != last_t) || interruptself)){
                MP3player.stopTrack();   
            }
        
            // Play the filename associated with the trigger number.    
            // (If a file is already playing, this command will fail
            //  with error #2).

            MP3player.playMP3(filename[t-1]);

            last_t = t;  // Save playing trigger        
        }

    }
}

Why are you pulsing the clock enable line to do a parallel load? Hard-wire
clock-enable to ground and don't do any clocking for the parallel load,
its an asynchronous operation.

You are using pin 10 as your data input from the shift register, but won't
work since the SPI hardware bombs out if pin 10 goes LOW. (see section
18.3.2 of the datasheet)

So when using hardware SPI you should always define pin 10 as an OUTPUT.

Select a different pin for the shift register data. You don't need A1 as I've pointed out
above so use that.

[All assuming the Lilypad MP3 is like the Lilypad and uses a 328P]