i am attempting to get 8 leds to do a sweep with my arduino mega and an 74hc595n shifter regester after folling many tutorials and sample codes i get nothing.
int dataPin = 2; //Define which pins will be used for the Shift Register control
int latchPin = 3;
int clockPin = 4;
int seq[14] = {1,2,4,8,16,32,64,128,64,32,16,8,4,2}; //The byte sequence
void setup()
{
pinMode(dataPin, OUTPUT); //Configure each IO Pin
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
}
void loop()
{
for (int n = 0; n < 14; n++)
{
digitalWrite(latchPin, LOW); //Pull latch LOW to start sending data
shiftOut(dataPin, clockPin, MSBFIRST, seq[n]); //Send the data
digitalWrite(latchPin, HIGH); //Pull latch HIGH to stop sending data
delay(75);
}
}
and i have the shift register connected to pins 2,3,4, but i get nothing out of it the code compiles to the board fine
It might be worth operating the hardware side without the arduino attached -- jumper the latch pin low and the data pin high and wiggle the clock line by jumpering it to ground and +5 alternately…
ok that makes sense and i think i have bad shift registers out of the ten i have none of them do the same thing when i run that test on just the hardware
You are switching lots of current to the LEDs at fantastic speeds, if there's no decoupling capacitor close to the shift register the transients could reset the chip as it latches and make it look like its broken. Every logic chip should have decoupling close-by (within a cm or so), 0.1uF as a minimum, for higher current loads 1uF or more could be wise.
You don't show decoupling in your diagram so I assumed you'd omitted it...
[ assume 8 times 20mA, thats upto 0.16A switching in 3ns or so, over 50 million amps/second -
it doesn't take much stray inductance to induce several volts at those rates ]
hmm i dont know i was just following a tutorial and its wiring diagram just to get a start on how the shift registers work and when i set it up it didnt work. So basically i am lost.
juniorhowell:
hmm i dont know i was just following a tutorial and its wiring diagram just to get a start on how the shift registers work and when i set it up it didnt work. So basically i am lost.
Go and complain to the author of the tutorial! Decoupling capacitors are essential...
While adding decoupling is a good thing to do, I think that the problem is with your code.
The delay of 75 mills will with your data turn on each of your leds for 75 mills and then turn it off. This is so fast that all you would see (even if the hardware is ok) is a very faint glow on the led.
Try changing delay(75) to delay(2000). Than play around.
added the capacitor with no change. shift registers ares cheap enough i decided to order a new batch and try again. waiting for the new ones to come in
All I can tell you is that your code works. The problem is hardware.
He is wrong there is something wrong with both your hardware and your software.
Keep the capacitors, you still need them, the fact that it made no change means you have something else wrong as well. Up that delay and re check the wiring, especially power and ground.