Bike light.


I’ve got a little 7-segment LED display lying around that I thought I might put to some use. But doing what? Well, yesterday I had a eureka moment as I was riding along with my training squad. I came up with the idea of using the 7-segment display to display messages on the back of my bike like temperature, speed, slogans,etc. You can’t use an LCD to do this because they are blue or green (except for the sparkfun ones) and a light on the back of a bike needs to be red. Why not build something more interesting than the usual flasher or scanner that are sold in bike shops?

I decided that my initial goal was going to be to make the display show the words: CCC, DEV, SQD which is short for Canberra Cycling Club Development Squad. Not that that’s the group I’m in or anything. If I do complete this project (as in temperature, serial message programming etc) I plan to get a PCB done so I can stow the electronics under my saddle and put the display on the seatpost. Maybe even make a kit…..

The project in action

The project in action

One of the first things you may notice about this photo is that the display appears to be powered by a little black chip. Don’t freak out, it’s just an atmega328 chip (the arduino 8 bit core) by itself. Here’s a tutorial if you don’t get it: http://arduino.cc/en/Tutorial/ArduinoToBreadboard . I’m still using an arduino board without the chip for programming and power. I think my FTDI standalone chip is dead. Let’s move on to the display.

 

Getting one of these displays working is not nearly as hard as getting an LCD working. Well at least not in my experience. However they are not that simple. They require 4 transistors and 12 digital logic pins to work. 4 of the pins on the display connect to ground. If, for example, the first ground pin is connected to ground the first number lights up. If the 3rd ground pin is connected the 3rd number lights up. When I say that the number lights up I do not mean that all 7 segments of the number light up, instead I mean that the segments of that number are able to light up. We can do this switching using BC547 transistors. I know it’s confusing. I’m doing my best.

Cool, you say, all I have to do is give power to the parts of the number I want to light up and the number (using the transistor) I want to light up. So how come there’s only 12 pins if there’s 4 numbers with 8 (there’s actually 8 segments if you include the decimal) segments? Because you can only light up all the numbers with the same pattern. So you can only display 4444 not 5672. This is because the number 4 appears on all the numbers no matter what you try and do. That’s why there’s only 12 pins. 8 segments and 4 numbers. This limits you to being able to display numbers like: 3,44,4444,555,22,1 etc. You can turn on and off how many numbers are displayed (1,111,1111) but you can only display the same number (1). If this doesn’t make sense leave a comment.

So how do you display number like 6785? Easy. You pulse the digits too fast for the human eye to see. You turn off all the numbers. Then you turn on one number with one pattern (set of segments like 5, 6, or 3). Then you turn off the number. Then you turn on the next number with a different pattern. And so on. Let’s look at the code for CCC, DEV, SQD.

int time = 0;
int count;
void setup() {
//SEGMENTS
  pinMode(8, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(2, OUTPUT);
  pinMode(1, OUTPUT);
  pinMode(0, OUTPUT);
//SEGMENT CONTROL
  pinMode(A1, OUTPUT);
  pinMode(A2, OUTPUT);
  pinMode(A3, OUTPUT);
  pinMode(A4, OUTPUT);

}
void loop(){
  time = 3;

//ccc
if (count<100){
  digitalWrite (A1,HIGH);
digitalWrite (0, HIGH);
digitalWrite (1, HIGH);
digitalWrite (3, HIGH);
digitalWrite (4, HIGH);
delay(time);
digitalWrite (0, LOW);
digitalWrite (1, LOW);
digitalWrite (3, LOW);
digitalWrite (4, LOW);
digitalWrite (A1,LOW);

digitalWrite (A2,HIGH);
digitalWrite (0, HIGH);
digitalWrite (1, HIGH);
digitalWrite (3, HIGH);
digitalWrite (4, HIGH);
delay(time);
digitalWrite (0, LOW);
digitalWrite (1, LOW);
digitalWrite (3, LOW);
digitalWrite (4, LOW);
digitalWrite (A2,LOW);

digitalWrite (A3,HIGH);
digitalWrite (0, HIGH);
digitalWrite (1, HIGH);
digitalWrite (3, HIGH);
digitalWrite (4, HIGH);
delay(time);
digitalWrite (0, LOW);
digitalWrite (1, LOW);
digitalWrite (3, LOW);
digitalWrite (4, LOW);
digitalWrite (A3,LOW);

digitalWrite (A4,HIGH);
delay(time);
digitalWrite (A4,LOW);

}
if (count>100){
  if (count>200){
    goto a;
  }
  //letter D
digitalWrite (A1,HIGH);
digitalWrite (0, HIGH);
digitalWrite (1, HIGH);
digitalWrite (2, HIGH);
digitalWrite (3, HIGH);
digitalWrite (4, HIGH);
digitalWrite (6, HIGH);
delay(time);
digitalWrite (0, LOW);
digitalWrite (1, LOW);
digitalWrite (2, LOW);
digitalWrite (3, LOW);
digitalWrite (4, LOW);
digitalWrite (6, LOW);
digitalWrite (A1,LOW);

  //letter E
digitalWrite (A2,HIGH);
digitalWrite (0, HIGH);
digitalWrite (1, HIGH);
digitalWrite (3, HIGH);
digitalWrite (4, HIGH);
digitalWrite (7, HIGH);
delay(time);
digitalWrite (0, LOW);
digitalWrite (1, LOW);
digitalWrite (3, LOW);
digitalWrite (4, LOW);
digitalWrite (7, LOW);
digitalWrite (A2,LOW);
 //letter V
 digitalWrite (A3,HIGH);
digitalWrite (1, HIGH);
digitalWrite (2, HIGH);
digitalWrite (3, HIGH);
digitalWrite (4, HIGH);
digitalWrite (6, HIGH);
delay(time);
digitalWrite (1, LOW);
digitalWrite (2, LOW);
digitalWrite (3, LOW);
digitalWrite (4, LOW);
digitalWrite (6, LOW);
digitalWrite (A3,LOW);
}
a:
if (count>200){
  //letter S
digitalWrite (A1,HIGH);
digitalWrite (0, HIGH);
digitalWrite (1, HIGH);
digitalWrite (4, HIGH);
digitalWrite (6, HIGH);
digitalWrite (7,HIGH);
delay(time);
digitalWrite (0, LOW);
digitalWrite (1, LOW);
digitalWrite (4, LOW);
digitalWrite (6, LOW);
digitalWrite (7,LOW);
digitalWrite (A1,LOW);
  //letter Q
 digitalWrite (A2,HIGH);
digitalWrite (0, HIGH);
digitalWrite (1, HIGH);
digitalWrite (2, HIGH);
digitalWrite (6, HIGH);
digitalWrite (7,HIGH);
delay(time);
digitalWrite (0, LOW);
digitalWrite (1, LOW);
digitalWrite (2, LOW);
digitalWrite (6, LOW);
digitalWrite (7,LOW);
digitalWrite (A2,LOW); 


//letter D
digitalWrite (A3,HIGH);
digitalWrite (0, HIGH);
digitalWrite (1, HIGH);
digitalWrite (2, HIGH);
digitalWrite (3, HIGH);
digitalWrite (4, HIGH);
digitalWrite (6, HIGH);
delay(time);
digitalWrite (0, LOW);
digitalWrite (1, LOW);
digitalWrite (2, LOW);
digitalWrite (3, LOW);
digitalWrite (4, LOW);
digitalWrite (6, LOW);
digitalWrite (A3,LOW);
}
if (count>300){
count = 0;
}
count++;
}

In this case I am using analog pins A1, A2, A3 and A4 to do the transistor switching. I am using digital pins 0 to 7 to power the segments. It’s very long and tedious. That’s because the arduino has to turn on and off each part of the number matrix individually. I’m working on a shorter more algorithmic version and help would be appreciated from someone who’s done this before. Maybe there’ll be someone at MHV.Then again, it does only weigh in at around 2,000 bytes. But it’s unwieldy.

Anyway, you can see that I have achieved the illusion of lighting up different number combinations by turning on and off parts of the display (using the transistors as switches) really fast. Almost 16.000 MHZ fast. Now I know that doesn’t sound very fast compared to modern computers but it’s more than enough for this. That’s one of the cool things about the arduino. Less is more. Now I’m going to try and write something cleaner and more powerful. But at least I’ve achieved my initial goal. I’ll also do up a fritzing diagram at some point. I know all that sounded pretty confusing so if you don’t understand please leave a comment and I’ll get right back to you.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s