How to make a Leanlight

##There’s no new blog posts until Saturday because I am at the coast. Doesn’t mean you can’t still enjoy the old ones. 🙂 ##

This morning I was riding behind someone when they were hit by a car and it made me think about how I might be able to make something that can prevent further bicycle vs motorist incidents. I came up with a very simple and easy to make circuit called the Leanlight.

The Leanlight is a simple circuit that accepts 7-12V batteries. It lights up a bright light when the rider leans their bike to turn. The leaning motion of the bike is detected by a simple circuit with a tilt switch. The Leanlight is easy for anyone to make and use.

Parts.

Let’s start by looking at what parts you’ll need to make this simple project:

  1. Some prototyping copper stripboard or veroboard. This is what I mean:
  2. 1 nice bright LED. Choose any colour as long as it’s bright and easy to see. 
  3. 1 220 ohm resistor. You may need a different value depending on what LED you’re using. Check the datasheet for the LED. 
  4. A tilt switch. I’m using a rolling ball type. See here for more on these devices: http://www.ladyada.net/learn/sensors/tilt.html .
  5. 1 7805 voltage regulator.
  6. 2 10uF capacitors.

Tools.

  1. A half decent soldering iron.
  2. Some wire strippers.
  3. Some wire cutters (mine are built-in to my wire stripper).
  4. You will also need something for cutting the veroboard. I’ll be using a dremel with a flexible shaft and cutting attachment.

    The cutting attachment.

    The cutting attachment.

Let’s get started

So now that we have the parts gathered we can make a start on a prototype. You don’t need to make one of these before soldering up a Leanlight as I’ve already done the testing for you. However, it might be a good idea to make one just to check that your components are working. You’ll need a solderless breadboard to do this.

The breadboard prototype hooked up to a 9V battery.

The breadboard prototype hooked up to a 9V battery.

The breadboard prototype up close. If you don't get it see the schematic below.

The breadboard prototype up close. If you don't get it see the schematic below.

The schematic:

This circuit uses a 7805 voltage regulator to power an LED that is switched on and off by  a tilt switch. The circuit accepts anywhere from 7-12V DC input voltage. The power supply circuitry is stolen from this tutorial: http://itp.nyu.edu/physcomp/Tutorials/ArduinoBreadboard .

The badly drawn schematic. It's functional not beautiful.

The badly drawn schematic. It's functional not beautiful.

The even more badly drawn computer generated protoype of the project. Fritzing still has some issues.

The even more badly drawn computer generated prototype of the project. Fritzing still has some serious issues.

You may notice in the fritzing vero board diagram above that the tilt switch is not green and both the tilt switch and the LED are wired off the board. This is to allow for a flexible setup when attaching this thing to a bike.

Laying out and soldering the veroboard circuit

I’m roughly following the layout I made in Fritzing as it has been checked with the schematic automatically (a Fritzing feature). I will however compress it slightly as you will see. Feel free to come up with your own creative layouts. Or to use multiple LEDs to indicate different turn directions. I don’t have two tilt switches so I can’t build one of those.

Let’s start by laying out our basic components:

The basic layout of the components on the veroboard.

The layout of the power components on the veroboard.

As I said above, you can lay out these components in any way you wish. As long as you follow the schematic accurately. Then solder them to the board using a good quality soldering iron. Make sure you have a window open or some other form of ventilation as solder fumes are dangerous to your health.

The parts soldered down. I know I'm no soldering ninja.

The parts soldered down. I know I'm no soldering ninja.

The next step is to solder the LED to the board. Make sure it is around the right way i.e. the short lead soldered to the capacitor’s copper rail if you follow my layout.

Make sure you solder the LED with a lot of spare wire so you can bend it to whatever position you want.

Make sure you solder the LED with a lot of spare wire so you can bend it to whatever position you want.

Now is a good time to test your circuit. Do this by soldering some power wires to the board and connecting the LED to the resistor using a scrap of wire as shown below.

Solder some black and red power wires to the board in the position shown.

Solder some black and red power wires to the board in the position shown.

Connect the red and black power wires to a 7-12V power source and connect the resistor to the LED using a piece of wire. If the LED lights up, the circuit works..

Connect the red and black power wires to a 7-12V power source and connect the resistor to the LED using a piece of wire. If the LED lights up, the circuit works..

So all good so far. if you can’t get the LED to light up, check your circuit with the schematic and check that you’ve soldered everything in correctly. Also, check to see that you have the power connected correctly.

Now solder the tilt switch to a small bit of veroboard.

The tilt switch soldered in.

The tilt switch soldered in.

Once again, I'm not a soldering ninja.

Once again, I'm not a soldering ninja.

 Cutting the board

Now it’s time for the high pitched, noisy and dangerous part. I’m not planning on having a book sized piece of board hanging off the back of my bike so I’m going to need the cut the board. I’ll be using a dremel to do this. You’ll need something to clamp the board to so it is secure when you’re cutting.

My drilling/cutting setup.

My drilling/cutting setup.

Oh and you’ll need a pair of safety glasses if you dremel is prone to coming apart at high-speed like mine is. They’re essential for safety. And for looking extremely silly.

Yeah.

Yeah.

You want to cut the board carefully as you could damage components with one wayward swipe (my nice blue LED now has a nice big scratch). You also don’t want to damage the copper rails on the board because they’re what makes the whole thing work.

The tilt switch cut out.

The tilt switch cut out.

The main board cut out.

The main board cut out. Notice the excessive amount of dust.

So now we have the two modules cut out, all we need to do is wire them up. This is the last bit of soldering to do.

The wires soldered to the tilt switch board.

The wires soldered to the tilt switch board.

The wires soldered to the main board.

The wires soldered to the main board.

Now all that is left to do before fitting the unit to a bicycle is one last test.

Yep, it definitely works!

Yep, it definitely works!

Here’s where the power circuit integrated into the board is useful. This project accepts any voltage from 7-12V so you can use any battery that is within that voltage. I’ll personally be using an RC plane battery as it is light, fits underneath my seat and will last for ages. Plus I don’t have to pay for new batteries each time it goes flat. The battery is rechargeable using a special high powered charger.

The high capacity lightweight RC battery.

The high capacity lightweight RC battery.

Well that’s about where the tutorial stops because everyone’s bike is different so it is hard to give you a one size fits all kind of installation guide. It’s generally pretty easy to do though. Here’s some photos of the Leanlight on my bike.

The finished project with the Rc battery stashed under the seat and the light hanging on my seatpost above my existing light. The wires for the tilt witch are strapped underneath my existing light to keep the whole project secure and vaguely neat.

The finished project with the RC battery stashed under the seat and the light hanging on my seatpost above my existing light. The wires for the tilt witch are strapped underneath my existing light to keep the whole project secure and vaguely neat. The RC battery connects easily to the project with some standard arduino style headers.

With the bike leaning as if I'm cornering.

With the bike leaning as if I'm cornering. It's a lot brighter than it looks. Trust me.

With the bike standing straight up.

With the bike standing straight up just as if I'm riding along normally.

That’s the simple operation of the project. Cyclists lean when they corner and this light detects this and turns on a blue warning lights telling motorists what they’re about to do. I’m going to see how my cycling group reacts to this next week when I show up with this. It’s going to be interesting. I’m more than happy to make them for people in Canberra and they would cost under $10.

Oh yeah, and thanks for all the pageviews today Ladyada!

Advertisements

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.

Sharks and Sticky Tape

Okay so to get started with I had to rewire the ethereten to the breadboard because I had to disconnect it when the etherten failed. I realized that I’ll probably use my etherten a lot even after I finish this server so I used some sticky tape to secure the pins in place in order. This means I can unplug the board easily.

Sticky tape

The slightly more secure wiring

The second cool thing that I want to show you before we delve into the server’s code is this awesome old shark pen that I found in my room. It’s got an awesome LED that lights up all different colors automatically.

Here’s a short demonstration showing what I mean:

shark light

A very cool pen

So that basically solves the problem of making my server look awesome at night. And the best thing is that it doesn’t need any PWM or any other fancy stuff because it has it’s own internal chip and acts just like a normal LED in circuit so I can just plug it straight into digital pin 8.

Code

Set it up

Let’s start with the arduino configuration (setup) code:

void setup(){

  /*Analog pin configurations*/
pinMode(A0, INPUT); //TILT SENSOR

/* LED number display control*/
pinMode(A1, OUTPUT);//DIGIT CONTROL
pinMode(A2, OUTPUT);//DIGIT CONTROL
pinMode(A3, OUTPUT);//DIGIT CONTROL
pinMode(A4, OUTPUT);//DIGIT CONTROL
pinMode(A5, INPUT);//DIGIT CONTROL

  /*Digital pin configurations*/  
pinMode(1, OUTPUT);//SEGMENTS
pinMode(2, OUTPUT);//SEGMENTS
pinMode(3, OUTPUT);//SEGMENTS
pinMode(4, OUTPUT);//SEGMENTS
pinMode(5, OUTPUT);//SEGMENTS
pinMode(6, OUTPUT);//SEGMENTS
pinMode(7, OUTPUT);//SEGMENTS

/*Digital pin 8 is not in use at the moment being left spare 
so it can serve as an ethernet
host for other arduino devices in my room. 
Or to turn on and off the cool LED that I found in an old pen.*/
pinMode(9, OUTPUT);//PIEZO
pinMode(8,OUTPUT); //awesome shark pen.
}

So that stuff basically tells the chip what each pin on the chip is going to do. I also added what is connected to each chip for easy reference when writing the code.

HTML

This part was pretty easy to do as I have experience in web development. Here’s what the output of the server looks like:

Screenshot of the server

Screenshot of the server's HTML output

As you can see I went for a very “hacker” kind of look because the thing is 8 bit and primitive. I’m not going to claim I can play flash games on an arduino like this guy: http://www.instructables.com/id/Arduino-Flash-game-streamer/

I mean all he did was use iframe HTML tags. Meh.

And here’s the code that powers the server output:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Ardu Server</title>
	<style type=text/css>
	body{
		font-family: Courier;
		color: green;
		background-color: black;
		font-size: 30px;
	}
		h1{
		font-family: Courier;
		color: green;
		background-color: black;
		font-size: 60px;
	}
	</style>
</head>
	<body>
		<h1>Welcome to ardu serve v1.0</h1>
		<p>Server has not been stolen recently</p>
		<p>Lighting is on</p>
		<p>Temp = 36.15 degrees celsius</p>

	</body>
</html>

But to simplify things when we are putting our HTML into our arduino code I deleted all the indents. There’s not much point repeating that here.

I tried to unindent my code and it didn’t quite work as planned. Don’t just try cramming the webpage into on a line because the Arduino IDE only allows certain number of characters in a line before it cuts them off. I’m not about to write client.println() for every line in my HTML. So I guess I might have to go and do it like this guy.

// HTTP Request message
PROGMEM prog_char content_404[] = "HTTP/1.1 404 Not Found\nServer: arduino\nContent-Type: text/html\n\n<html><head><title>You Fail</title></head><body><h1>Looks like Lochie Ferrier has failed in his duty to maintain the arduserver</h1></body>";
PGM_P page_404[] PROGMEM = { content_404 }; // table with 404 page

// HTML Header for pages
PROGMEM prog_char content_main_header[] = "HTTP/1.0 200 OK\nServer: arduino\nCache-Control: no-store, no-cache, must-revalidate\nPragma: no-cache\nConnection: close\nContent-Type: text/html\n";
PROGMEM prog_char content_main_top[] = "<html><head><title>Arduino Web Server</title><style type=\"text/css\">table{border-collapse:collapse;}td{padding:0.25em 0.5em;border:0.5em solid #C8C8C8;}</style></head><body><h1>Lochie Ferrier's arduserver</h1>";
PROGMEM prog_char content_main_menu[] = "<table width=\"500\"><tr><td align=\"center\"><a href=\"/\">Home</a></td><td align=\"center\"><a href=\"page2\">Page 2</a></td><td align=\"center\"><a href=\"page3\">Page 3</a></td><td align=\"center\"><a href=\"page4\">Page 4</a></td></tr></table>";
PROGMEM prog_char content_main_footer[] = "http://www.lochieferrier.com</body></html>";
PGM_P contents_main[] PROGMEM = { content_main_header, content_main_top, content_main_menu, content_main_footer }; // table with 404 page
#define CONT_HEADER 0
#define CONT_TOP 1
#define CONT_MENU 2
#define CONT_FOOTER 3

// Page 1
PROGMEM prog_char http_uri1[] = "/";
PROGMEM prog_char content_title1[] = "<h2>Page 1</h2>";
PROGMEM prog_char content_page1[] = "<hr /><h3>Content of Page 1</h3><p>Nothing... yet.</p><br /><input type=\"text\" name=\"prova\">";

Basically he stores the webpages as part of the chip’s program memory. He has a five page system that even has get and post functions. When it gets a request it does some freaky deaky stuff that I don’t understand and gets the requested webpage along with a template (headers etc) and spits it out to the user. This was the original server infrastructure that I was going with but I wanted to try and build my own but now I think I’m just going to try and extend his masterpiece. Here’s the full version:

http://www.arduino.cc/playground/Code/WebServer

That guy is a god.

And I’ve still got to test that the circuit is even working……

Chips

Okay so seeing as I gave away my ebay arduino to my electronics teacher and my etherten is kind of going to be occupied I’ve started looking around for some new silicon.

Here’s the first cool one:

Chipkit uno32

Chipkit uno32

PIC32 board that's compatible with all things Arduino. Enough said.

This handy little board costs the same as a regular arduino, has a lot mor outputs and costs $32. That’s pretty good. But it’s worth mentioning that this board doesn’t run a full PIC32. It only runs a limited one that doesn’t have Ethernet, USB hosting or CAN. So you get 32bit and a lot of inputs but not much else. http://www.digilentinc.com/Products/Detail.cfm?NavPath=2,892,893&Prod=CHIPKIT-UNO32

Specs:

  • Microchip® PIC32MX320F128 processor
    • 80 Mhz 32-bit MIPS
    • 128K Flash, 16K SRAM
  • Compatible with existing Arduino™ code examples, reference materials and other resources
  • Can also be programmed using Microchip’s MPLAB® IDE (along with a PICkit 3 and our PICkit3 Programming Cable Kit, seen below)
  • Arduino™ “Uno” form factor
  • Compatible with Arduino™ shields
  • 42 available I/O
  • User LED
  • Connects to a PC using a USB A -> mini B cable (not included)

The good news is that this thing has a big brother that is predictably named the Chipkit max32

Chipkit max32

Chipkit max32

This one has ethernet and a lot of outputs.

How is this one worth $20 more? It has ethernet and USB hosting and everything else you need. And Arduino compatibility. This thing could run a disco with ease. I want one. http://www.digilentinc.com/Products/Detail.cfm?NavPath=2,892,894&Prod=CHIPKIT-MAX32

Specs:

  • Microchip® PIC32MX795F512 processor
    • 80 Mhz 32-bit MIPS
    • 512K Flash, 128K RAM
    • USB 2.0 OTG controller
    • 10/100 Ethernet MAC
    • Dual CAN controllers
  • Provides additional memory and advanced communications peripherals
  • Compatible with existing Arduino code examples, reference materials and other resources
  • Can also be programmed using Microchip’s MPLAB® IDE (along with a PICkit 3 and our PICkit3 Programming Cable Kit, seen below)
  • Arduino™ “Mega” form factor
  • Compatible with Arduino™ shields
  • 83 available I/O
  • User LED
  • Connects to a PC using a USB A -> mini B cable (not included)

So those are the digilent pic32 boards.

I’ll show you some more tomorrow that I have been pondering over like the mbed, cool ebay boards, chumby, beagle and the Cerebot 32MX7.

 

I haven’t really had time to check all this over because I did all this in half an hour so don’t kill me for spelling or factual errors.

Hook me up.

Here’s what I started with.

I've got to wire the thing on the left to the thing on the right

I started by wiring up the positive and negative to some rails

Then I wired the temperature sensor to analog pin 5, ground and 5V

A piezo wired to digital pin 9 for PWM and 5V.

The last of the sensors. The tilt switch is wired to analog pin 0 and 5V.

How to wire up a number display

Now for the fun stuff. To wire up the number display and the transistors that determine which digits are showing I used this diagram that I made ages ago.

Here’s basically all I need to know.

There are 16 pins on the number display. The ones below need to be wired to the C leg of transistors. In this case I just used good old BC547s.

Pin 1 is gnd no1

Pin 4 is gnd no 2

pin 5 is gnd no 3

pin 14 is gnd no 4

When I say ground I mean that when these pins are connected to ground the digit that they correspond to (i.e. pin 4 turns on the second digit) turns on. By using transistors we can control this and have numbers and other stuff display on the digits.

So for example if we want to control when we want the first digit to light up we do it like this.

B to number display pin 1

C to analog pin 1

E to ground

When we switch on analog pin 1 in our program our first number lights up. Simple.

(oh yeah and if this way of wiring these displays isn’t right then sorry but I just figured out this way from experimenting.

The transistors all wired up mad scientist style.

The finished product

So that's pretty much all the circuitry I need to do for this project.

I know it looks messy and I could have just used a number shield or shift registers but I like it like this. It kind of adds a mad scientist look to my room and makes me look a bit like this guy:

Flint from cloudy with a chance of meatballs

Flint from “Cloudy with a Chance of Meatballs”. Credit to the guys who made the movie.

Next up, debugging the circuit using serial.

Progress

Sorry.

First up I’ll say sorry for not keeping you guys up to date with my server project for a couple of days. My school has this silly athletic qualification and testing system which is designed to rank me for races in an athletics carnival that I won’t be at.

The new UI

The new UI

A lot of wire!!

A diagram of the UI

The plan.

Okay so basically I’ve redesigned (again) the UI for the server. I figured out that I actually did have enough pins to include a four number 7 segment display after all. The other electronics includes a piezo for alarms and errors as well as a tilt switch to detect whether it has been touched and a temperature sensor for doing weather logging. So that’s basically all I’ve got for the electronics apart from the etherten.

Enclosure

An old power supply from the dump

An old computer power supply enclosure from the dump

I was digging around a bit last night for an enclosure and came across an old computer supply enclosure. It’s perfect because it has a fan that works and looks pretty cool. It’s AC socket also provides a perfect slot for the 4 number 7 segment display to fit into. The etherten does need the fan because it gets pretty hot so I’ll just hook it up to the 5V on the etherten. Also, when I turned off the lights with the etherten inside the enclosure, it glows a cool blue color from the etherten’s onboard LED. Awesome.

Programming

I think I’ve finally got a good idea of what I want the server to do. I want it to be able to show and log temperature to the SD card, serve files remotely, and display messages and errors on the 7 segment display. To do this I think I’m going to have a loop that includes a check to see whether it has received any HTTP requests and a variable that triggers a different 7 segment display message each time around. It would look a bit like this conceptually (very roughly).

loop(
HTTP check(
if it gets one it prints the webpage requested
)
lots of ifs depending on the variable
if var=1(
display temp on display
)
if var=2(
display history on display
)
delay(1000)
and increase the variable (also when it gets to a certain number bring it back to 1)
)

This kind of program structure allows for easy expansion and makes sure that webpages are served quickly.

So that’s about all for now. Next up is an in-depth look at how I wire number displays.

The user interface

Getting the LCD to work…

LCD

The backlight works. Great. I can proceed further.

Okay so then I hooked up all the wires…

The wiring

Note that this image doesn’t show the right wiring exactly. I actually had to add a few more after I took a photo.

And I didn’t get much further than that. I have tried and tried again with this LCD and have not gotten it to work. I think I’ll have to put this off and play with it at a later date. I have double and triple-checked the wiring and it is all correct. It’s a pain and I think the problem is that I got it from a chinese ebay store. It’s the only thing in the box of parts that I got that doesn’t work.

Oh well.

Change of plan

Moving right along now…

So with the LCD scrapped I decided to implement a simple communication system for letting me know when people are online, the server’s status etc.

I went back to good old LEDs for this. I was going to use this funky  7 segment display (seen in the background of the photo below) until I discovered I didn’t have enough pins left because the ethernet had gobbled them up. I could use a multiplexer but that is just adding complexity and I like to keep it simple stupid (KISS).

Okay so here’s the basic electronics that the server has onboard. I didn’t put the wiring in because that would only confuse things for you guys.

  1. It’s got 3 LEDs – red for fail, green for good and yellow for connected or notifications (or SD card).
  2. An LM35 temperature sensor ( the transistor look-alike)  for logging weather.
  3. A green tilt sensor to detect whether the server has been stolen or manhandled.
  4. A button to turn it on or to dismiss a warning. There’s another on the protoboard.
  5. An IR receiver to read signals sent from my remote control.
  6. A piezo buzzer so I can annoy my parents from anywhere in the world.

So that’s pretty much all I need to get started on the code on Thursday. I won’t be able to work on it on Wednesday because I’m teaching kiddies how to build robots 🙂