Pages: [1]   Go Down
Author Topic: Serial to Parallel Shifting-Out with a 74HC595 Example  (Read 1235 times)
0 Members and 1 Guest are viewing this topic.
Utah, USA
Offline Offline
Newbie
*
Karma: 2
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have been working with Serial to Parallel Shifting-Out with a 74HC595 Example http://arduino.cc/en/Tutorial/ShiftOut and I am trying to work with Code Sample 1.2 One by One. All I get when I open the Serial Monitor and type in an ASCII number 0-9 like I believe I am supposed to do and hit enter I can see the corresponding LED flick on and off very quickly and only the first LED stays on. I thought for each number I enter the corresponding LED stays on (4 = LED 5 on). Has anyone had experience with this example and had success? I tried the first sample, Code Sample 1.1 Hello World, and it works just fine so I believe my circuit hooked up right.
Logged

A bad day at the beach is better than a good day at work.

North Yorkshire, UK
Offline Offline
Faraday Member
**
Karma: 104
Posts: 5531
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well firstly, remove the capacitor (it's wrong) but I can't remember off hand exactly what that example does.

Here's some code written by bhagman (from Rogue Robotics) which turns on/off an LED (0-15) in either red, blue or purple (both). I'm using 4 daisy chained shift registers - the first two controlling red LEDs and the second two controlling blue LEDs. The values for the previous LEDs are stored so the other LEDs remain as they were when you turn another one on/off.

Code:
void setLED(uint8_t lednum, uint8_t colour)
{
  red_leds = (red_leds & ~(1 << lednum));
  blue_leds = (blue_leds & ~(1 << lednum));

  if (colour == LED_RED || colour == LED_PURPLE)
  {
    red_leds |= (1 << lednum);
  }
  if (colour == LED_BLUE || colour == LED_PURPLE)
  {
    blue_leds |= (1 << lednum);
  }
 
  shiftOut(dataPin, clockPin, MSBFIRST, (uint8_t) (blue_leds >> 8));
  shiftOut(dataPin, clockPin, MSBFIRST, (uint8_t) blue_leds);
  shiftOut(dataPin, clockPin, MSBFIRST, (uint8_t) (red_leds >> 8));
  shiftOut(dataPin, clockPin, MSBFIRST, (uint8_t) red_leds);
 
  digitalWrite(latchPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(latchPin, LOW);
}

void clearLEDs()
{
  red_leds = 0;
  blue_leds = 0;

  for (int i = 0; i < 4; i++)
  {
    shiftOut(dataPin, clockPin, MSBFIRST, 0);
  }

  digitalWrite(latchPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(latchPin, LOW);
}

You then need this sort of stuff at the top of your sketch:
Code:
/////////////////////////SHIFT REGISTER LED STUFF
const int latchPin = 8;//Pin connected to latch pin (ST_CP) of 74HC595
const int clockPin = 12;//Pin connected to clock pin (SH_CP) of 74HC595
const int dataPin = 11;//Pin connected to Data in (DS) of 74HC595

uint16_t red_leds;
uint16_t blue_leds;

#define LED_OFF 0
#define LED_RED 1
#define LED_BLUE 2
#define LED_PURPLE 3
/////////////////////////
« Last Edit: June 02, 2011, 12:46:52 am by mowcius » Logged

Utah, USA
Offline Offline
Newbie
*
Karma: 2
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the reply and the sample code.

From what I can tell from the description and comments for the example I am trying to get to work. I am supposed to be able to type any number from 0 to 7 and the corresponding LED is supposed to light up and I suppose stay on until I choose a different number. All it does is turn on and off in a flash at very low intensity. I can barely see it happening.

I am quite new to the Arduino world. Maybe this code will help me figure out how to work with this shift register.
Logged

A bad day at the beach is better than a good day at work.

North Yorkshire, UK
Offline Offline
Faraday Member
**
Karma: 104
Posts: 5531
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well I would test it but unfortunately I don't have any Shift Registers set up atm.

How's your wiring? Have you connected all the ground pins?
Logged

Pages: [1]   Go Up
Jump to: