SPI Shift Registers don't work right


i using breadboard atmega328p set of shift registers controlling 3 3x3 rgb led matrices (formed cube). have 1 shift register hooked first 2 columns , 2 common cathode rows on 1 matrix, thereby controlling bottom 4 leds in square. suggested here, put .1 uf capacitor in series latch line. setup can controlled 9v battery or arduino.

here's problem: latch line connected, display doesn't start @ all! sometimes, work, out of tempo. sometimes, skips frames. makes sequences didn't code! when switch 9v arduino +5v, above happens less frequently.

so disconnected latch, , starts making horrible, extremely brief flashing in leds shouldn't turn on. still happens arduino power. works ~5 seconds, starts getting out of sync , starts making frames. if reconnect latch during sketch, flashing goes away, sketch loses sync. doesn't lose sync without latch arduino, latch, starts lag again.

reset returns sketch sync @ beginning.

here code:
code: [select]
// rgb led cube sketch
// uses atmega328 control 3x3x3 cube of rgb leds with
// 5 595 shift registers (8 bit).

//currently using 1 register!

// spi code examples http://www.gammon.com.au/forum/?id=11518
// , http://www.gammon.com.au/spi

// shift register wiring , other example code can found
// @ http://www.arduino.cc/en/tutorial/shiftout

#include <spi.h>

const byte latch = 9; // edit change latch pin on arduino
const byte maxsize = 16; // edit change size of array (counting 0 --> (2^x)-1). try make divisible numofreg.
byte dataarray[maxsize]; // if using absurdly large array (i.e. >256 bytes) change int

byte data; // if using absurdly large array (i.e. >256 bytes) change int

const byte numofreg = 1; //edit change # of registers

byte j = 0; // start @ byte 0

void setup() {
  spi.setclockdivider(spi_clock_div128);
  pinmode(13, output);
  digitalwrite(13, high);
  delay(20);
  digitalwrite(14, low);
  spi.begin ();
  digitalwrite(latch, high);
  delay(100);
  digitalwrite(latch, low);
  serial.begin(1200);

  // define each byte of array in hex here!
  // example, if maxsize = 8, define dataarray[0] through [7]
  // each item here adds 6 bytes program size. (out of 32k)
  // each frame (# of sr's) backwards.

  // example turns each led blue, red, green, white!
  dataarray[0]=0x09;
  dataarray[1]=0x0a;
  dataarray[2]=0x0c;
  dataarray[3]=0x0f; // end of led #6
  dataarray[4]=0x18;
  dataarray[5]=0x28;
  dataarray[6]=0x48;
  dataarray[7]=0x78; // end of led #5
  dataarray[8]=0x81;
  dataarray[9]=0x82;
  dataarray[10]=0x84;
  dataarray[11]=0x87; // end of led #9
  dataarray[12]=0x90;
  dataarray[13]=0xa0;
  dataarray[14]=0xc0;
  dataarray[15]=0xf0; // end of led #8
  // continue define each unit of array
}

void loop() {
  digitalwrite(latch, low);
  // here transfer each byte of data!
  // example, if sending bytes 0x13, 0xde, 0x4a:
  // 0x13 xx xx
  // 0xde 0x13 xx
  // 0x4a 0xde 0x13

  (int = 0; < numofreg; i++) {
      data = dataarray[j];
      digitalwrite(latch, low);
      spi.transfer(data);
      delay(10);
      j++; // j, not i!
      // in nutshell: write each byte j sequentially (so ends backwards) in groups of numofreg, latch, repeat.
  }
 
  digitalwrite(latch, high);
  delay(500);
 
  if (j == maxsize) {
      j = 0; // loops beginning. can change create 'intro' main 'loop'.
 
  }
  }
 
 

what wrong?

quote
as suggested here, put .1 uf capacitor in series latch line.
no putting in parallel not series.

this tutorial wrong, should not connect capacitor latch pin. connect capacitor between 5v power pin , ground pin of each shift register. latch pin connected direct arduino without capacitor


Arduino Forum > Using Arduino > LEDs and Multiplexing > SPI Shift Registers don't work right


arduino

Comments