problems shifting in with 74HC165N on Lilypad MP3


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):

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.

/* Width of data (how many ext lines).

/* 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()


    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:

    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


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

    while (file.openNext(sd.vwd(),O_READ))
        // get filename


        // 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.


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

    // Turn on the amplifier chip:
    oldButtonValues = buttonValues;



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)

        //MP3player.playMP3(filename[random(0, 14)]);

        oldButtonValues = buttonValues;


/* 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);
    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);
        digitalWrite(clockPin, LOW);


/* 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)){
            // Play the filename associated with the trigger number.    
            // (If a file is already playing, this command will fail
            //  with error #2).


            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]