Monday, February 21, 2011

Centipede shield

I originally started designing my project using 74HC595 shift registers.  There are some great tutorials, and the 74HC595 really isn't very difficult to use.  I was able to get a prototype working pretty easily, but 32 channels of output would have required four 8-bit shift registers, and the code would have been a little bit messy.  Then, I found the Centipede shield.  
I'm pretty impressed by this little guy.  It uses the I2C (inter IC communication) Wire interface to individually control the 64 individual inputs/outputs.  

"Hello world" for the Centipede is pretty simple:

#include <Wire.h>
#include <Centipede.h>

Centipede CS; //create Centipede object
int i;  //general loop variable

void setup() {
  Wire.begin(); //start I2C
  CS.initialize(); //set all registers to default

  for (i=0;i<32;i++) {  //set first 32 channels to output
   CS.pinMode(i, OUTPUT); 
   }

  for (i=0;i<32;i++) {  //set first 32 channels to HIGH
   CS.digitalWrite(i, HIGH);
   }
}

The library is exceptionally easy to use.
  • Include the Wire.h library and Centipede.h library.
  • Create the Centipede object
  • Initialize I2C and Centipede
  • Set the pinmode of each pin
  • And then you can read/write each individual pin
I use an inexpensive breakout board and connect it to the Centipede shield using a 2x10 connector (20 conductor) ribbon cable.
I had some difficulty building my cable.  You buy the connectors and ribbon cable separately.  To build the cable, you basically squish the connector pins through the cable and they are supposed to make a good connection.  Well, mine didn't.  I ended up buying a couple 12 inch cables on eBay for the same amount I could have bought a couple new connectors.

I still don't know what I did wrong.  I tried squishing the connector using a big book.  Maybe a vice would have provided more force without any twisting.  Oh, well.  eBay to the rescue.

In my next blog entry I'll look at the relays I'm using to switch the XMas lights on and off.

No comments:

Post a Comment