Spark Fun SKU#: Hitt-HC4LED (SPI LED 4 Num Disp)

Hi,

I am looking at this page: http://www.sparkfun.com/commerce/product_info.php?products_id=751 and I am interested to know if this item can be driven by an Arduino board?

If so, would a single Arduino board be able to drive 2 display units at the same time?

I am a beginner and have a very specific project in mind and have been repeatedly told to start with an Arduino board. It wasn't until I found that display unit at Spark Fun that I actually had a reason to buy components and build something.

Thanks for your time, Jona

Although there has been many views of this post, there haven't been any replys. I went ahead and started a similar thread at the spark fun forums to see what they might have to say. Look here: http://www.sparkfun.com/cgi-bin/phpbb/viewtopic.php?t=3897. While this gives me some encouragment about my project, it doesn't answer my primary question; will the Arduino be able to drive the seven segment display unit in question? If so, will it be able to drive 2?

Again, I am a beginner and am really interested in using the Arduino for my electronic scoreboard project, but feel like I need a little bit of information up front.

Any help from this user base will be most helpful!

Thanks, Jona

SPI (the protocol used to control the LED display) is supported in the hardware of the ATmega8 on the Arduino board, but we haven't yet implemented a library to take advantage of it. This means it's possible to use the display with Arduino, but would require mucking around a bit in the Arduino internals. SPI (along with TWI/I2C) are things we plan to add to Arduino at some point, but I'm not sure when we'll have time. If you give it a shot, we'll help you out.

Okay, thanks for the reply.

When I posed the question to the Spark Fun support email, I got this reply:

Yes, you should be able to drive it directly with the Arduino board. We don't sell any kits, but it should be as easy as removing the control wires from the SPI LED connector and inserting those wires into the Arduino board connector.

Does this sound correct?

Update: I have ordered my Arduino and the 4 digit, 7 segment LED display. I can't wait until it arrives so I can actually start playing around with this idea.

When I do get it, and come to some hurdles, you can bet I will be posting again.

Thanks.

Okay, I got my Arduino and the HC4LED display unit today and was able to get the board to blink a LED. I then followed the advice of the Spark Fun support by removing the SPI connector from the control wires on the display unit. I then attempted to connect the display to the Arduino via several of the connections on the board, but was not successful in getting the display to react at all.

At this point I am wondering how exactly I should connect the display to the Arduino?

Could someone look at this spec sheet (http://user.pa.net/~bean/hc4led/HC4LED%20Datasheet.pdf) for the display and let me know where the 5 control wires should connect to the Arduino?

Any help would be great!

I'm attempting the same thing. Did you ever have any luck with this?

I have two and have only tried one, and it works really well, ill post my code when i get home from school in an hour.

The white wire goes to +5, and the two wires next to it go to ground. then the two blue wires on the end of the connector go to to separate digital outs. the data wire is the blue wire on the end of the connector, and the clock is the one right next to it. You will need to edit some of the functions to use 2 displays.

#define CLOCKPIN  12  //change this to the pin where the clock is going in to
#define DATA_PIN   13  // change to the pin where the data wire is plugged in to
int time = 2400;
int digits[10] = { 126, 24, 109, 61, 27, 55, 119, 28, 127, 31 }; // define numerals (0-9)
int digitC = 60;
int digitF = 71;
int digitE = 103; 
int flashDelay = 1400;
int minDelay = 500;
char* numStr = "                        ";
void setup()
{
  Serial.begin(9600);
  pinMode(DATA_PIN, OUTPUT);
  pinMode(CLOCKPIN, OUTPUT);    
}
void numOut(int num){
  int g;
   
  char* *numStrPtr;
  //char *numDigitPtr;
   
  numStrPtr = &numStr;
  //numDigitPtr = &numDigit;
   
  itoa(num, *numStrPtr, 10);  
   
  for (g=3; g >= 0; g--) {
       
    if (g == 0) {  
     digitOut(digits[numStr[g]-48], flashDelay);
    } else {
     digitOut(digits[numStr[g]-48], minDelay);
    }
 
  }
 
} 
void digitOut(byte dataOut, int curDelay) {
  // This shifts bits out MSB first, on the rising edge of the clock:
  int i;     // bit counter
  if (curDelay < minDelay) { curDelay = minDelay; } // delay  
    for (i=7; i>=0; i--)  {
 
     if ( dataOut & (1<<i) ) {
       digitalWrite(DATA_PIN, HIGH);
     }
     
     // if this bit of the dataOut variable is a 0,
     // then set the data pin low to shift out a 0:
     else {
       digitalWrite(DATA_PIN, LOW);
     }
 
     digitalWrite(CLOCKPIN, HIGH);
     // pulse the clock:
     if (i == 0) {
       delayMicroseconds(curDelay);
     } else {
       delayMicroseconds(minDelay);
     }
     digitalWrite(CLOCKPIN, LOW);
 
    }
 
} 
void loop()
{

  time = time - 1;
    
  numOut(time);  //use this function to display what you want to display
  //Serial.println(time);
  delay(1000);
  }

ZeddMaxim - sorry for the long delay (somehow I wasn't alerted when you posted your reply) but here is another thread that I started that actually has some good information in it and example code for the Arduino and the HC4LED unit - http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1157807338/8

Karlcswanson - wow, thanks for the program! Although as you might see in the thread mentioned above, I have a program that is working, I still am not able to arbitrarily display a number (i.e. I am displaying the numbers 0 - 1000 in a counting up and then counting down loop). Also, I just got some push buttons that actually work for my application last week, so your post is especially timely.

I will be playing around with this program tonight, I'll post anything that I discover.

Again, thanks. Jona

Alright!

So, I combined your program with the sample program found here http://www.arduino.cc/en/Tutorial/Pushbutton and I wired up my buttons as shown in the schematic from the article in MAKE Zine #7 named “Hello, world” on page 149 (http://makezine.com/07/diycircuits_hello/) and voila!

Press one button and the display shows a “1”, press it again and the display shows a “2”. Press the other button and the display shows a “1”.

This is the fundamental functionality of my application.

Thanks again!

#define CLOCKPIN  12  //change this to the pin where the clock is going in to
#define DATA_PIN  13  // change to the pin where the data wire is plugged in to
int upPin = 7;   // pushbutton for counting up
int dnPin = 5;   // pushbutton for counting down
int val = 0;     // variable for reading the pin status
int time = 0;  // the number to display
int digits[10] = { 126, 24, 109, 61, 27, 55, 119, 28, 127, 31 }; // define numerals (0-9)
int digitC = 60;
int digitF = 71;
int digitE = 103; 
int flashDelay = 1400;
int minDelay = 500;
char* numStr = "                        ";
void setup()
{
  Serial.begin(9600);
  pinMode(DATA_PIN, OUTPUT);
  pinMode(CLOCKPIN, OUTPUT);    
  pinMode(upPin, INPUT);    // declare pushbutton as input
  pinMode(dnPin, INPUT);    // declare pushbutton as input
}

void numOut(int num){
  int g;
   
  char* *numStrPtr;
  //char *numDigitPtr;
   
  numStrPtr = &numStr;
  //numDigitPtr = &numDigit;
   
  itoa(num, *numStrPtr, 10);  
   
  for (g=3; g >= 0; g--) {
       
    if (g == 0) {  
      digitOut(digits[numStr[g]-48], flashDelay);
    } else {
      digitOut(digits[numStr[g]-48], minDelay);
    }
 
  }
 
} 
void digitOut(byte dataOut, int curDelay) {
  // This shifts bits out MSB first, on the rising edge of the clock:
  int i;     // bit counter
  if (curDelay < minDelay) { curDelay = minDelay; } // delay  
    for (i=7; i>=0; i--)  {
 
      if ( dataOut & (1<<i) ) {
       digitalWrite(DATA_PIN, HIGH);
      }
      
      // if this bit of the dataOut variable is a 0,
      // then set the data pin low to shift out a 0:
      else {
       digitalWrite(DATA_PIN, LOW);
      }
 
      digitalWrite(CLOCKPIN, HIGH);
      // pulse the clock:
      if (i == 0) {
       delayMicroseconds(curDelay);
      } else {
       delayMicroseconds(minDelay);
      }
      digitalWrite(CLOCKPIN, LOW);
 
    }
 
} 
void loop()
{
  val = digitalRead(upPin);  // read input value
  if (val == HIGH) {         // check if the input is HIGH (button pressed)
    time = time + 1;  // increment the number
    numOut(time);  //use this function to display what you want to display
    Serial.println(time);
    delay(1000);
    }
  val = digitalRead(dnPin);  // read input value
  if (val == HIGH) {         // check if the input is HIGH (button pressed)
    time = time - 1;  // decrement the number
    numOut(time);  //use this function to display what you want to display
    Serial.println(time);
    delay(1000);
  }
  delay(10);
}

I think i got the HC4LED code from code from this post. try this, i think the problem was with the val

void loop()
{
  dn_pin_val = digitalRead(dnPin);
  up_pin_val = digitalRead(upPin);  // read input value
  if (up_pin_val == HIGH)        // check if the input is HIGH (button pressed)
    {
    time++;  // increment the number
    }
   else if (dn_pin_val == HIGH)         // check if the input is HIGH (button pressed)
    {
    time--;  // decrement the number
    }
    numOut(time);  //use this function to display what you want to display
    Serial.println(time);
    delay(1000);
}

Thanks karlcswanson; I have tweaked this section again; it is working without issue:

  if (digitalRead(upPin) == HIGH) {
    delay(10);
    if (upBtnState == 0) {
      time++;
      upBtnState = 1;
    } else {
      upBtnState = 0;
    }
  } else if (digitalRead(dnPin) == HIGH) {
    delay(10);
    if (dnBtnState == 0) {
      time--;
      dnBtnState = 1;
    } else {
      dnBtnState = 0;
    }
  }

  numOut(time);  //use this function to display what you want to display
  Serial.println(time);
  delay(100);

At this point the only thing I want to do that I haven't figured out is how to display stuff that is not a digit (0-9), like letters or maybe "----","____", or even "PLAY".

And finally, how do I move shift the number being displayed to the right-most digit of the display instead of the the left most?

For example, I currently have "1 " on the display where the 3 spaces are dark digits. I want to change it to be either " 1" or "0001".

Has anyone figured this out?

try numOut(time + 0000);

also to display characters, look at the manual

http://user.pa.net/~bean/hc4led/HC4LED%20Datasheet.pdf

and the int digitC... in your code. thats all i know so far.