Friday, December 21, 2007

Using a parallel interface LCD with Arduino















Hitachi HD44780-compatible LCD's are very cheap and readily available from many electronics suppliers, ebay, even from junk that you may find at tag sales. They are also relatively easy to use with microcontrollers, especially when using libraries that reduce the code to a few lines. There are two such libraries available for the Arduino. One is the 8 bit library and one is the 4 bit version. Both libraries end up performing the same basic function, but the 4 bit version requires much fewer digital outputs from the Arduino. This is a huge benefit if you intend to do more than just display messages on an LCD. I wired up the LCD using an IDE cable that I had leftover form and old computer. I just cut it in half, bared the wires, labeled them according to which LCD pin they corresponded with, and tined them with solder to ease inserting them into the breadboard. The labeling was done according to the spec sheet for the particular LCD that I have and the wiring was done according the page describing the 8 bit library. The only difference in the wiring for the 4 bit library is that the R/W lead was connected to ground and data bits 0-3 were not connected at all. When you download the 4 bit library there is an example program included. I modified the example code a bit to suit my tastes. The code is included after the video. Eventually I'll bother narrating these videos. Not there yet.


//example use of LCD4Bit library

#include
//create object to control an LCD.
//number of lines in display=2
LCD4Bit lcd = LCD4Bit(2);

void setup() {
pinMode(13, OUTPUT); //we'll use the debug LED to output a heartbeat

lcd.init();
}

void loop() {
digitalWrite(13, HIGH); //light the debug LED

lcd.clear(); //clear LCD
lcd.printIn("All your base"); //print "All your base"
delay(1000); //wait 1 second
digitalWrite(13, LOW); //turn off the debug LED

//print some dots individually at end of first line of text
for (int i=0; i<6; i++)
{
lcd.print('.');
delay(100);
}
//print something on the display's second line.

lcd.cursorTo(2, 0); //send cursor to the beginning of line 2
lcd.printIn("Are belong to us"); //print "are belong to us"
delay(1000); //wait for 1 second
lcd.leftScroll(20, 100); //scroll entire display 20 chars to left, delaying 50ms each inc
}

Monday, December 17, 2007

Adding Libraries to Arduino - 0010

I'm not sure if the way that libraries are setup has drastically changed since Arduino - 0004 or what, but the tutorial for using an 8 bit LCD display by using the "LiquidCrystal" library needs to be corrected. In this tutorial it says to download the zip file and then paste the "LiquidCrystal" folder into the "arduino-0004\lib\targets\libraries" folder. I assumed maybe that there was a corresponding "arduino-0010\lib\targets\libraries" folder in the latest version of the IDE. I was wrong. There is only a "arduino-0010\lib" folder. I therefore created subfolders to match the file path given, resulting in "arduino-0010\lib\targets\libraries". This did nothing for me. I then tried to just paste the library into the "arduino-0010\lib" folder but this too did not result in the library being visible in the Sketch>Import Library menu. Knowing that there were libraries already working in the Arduino IDE I did a search for *.h and found the import libraries to all be saved in the "arduino-0010\hardware\libraries" folder. I pasted the library into that folder, and presto, it worked! OK, so that's not entirely true. The Arduino IDE listed it in the Import Library menu however it gave a weird error at the bottom of the window. I then tried the 4 bit version and it shows up without an error. That's fine with me as the 4 bit requires fewer wires. I'll have to get it wired up and put up a post soon. Anyway, to sum up what I've found regarding loading libraries into the Arduino IDE(version 0010); paste them into "arduino-0010\hardware\libraries".

Saturday, December 15, 2007

Arduino POV


I´ve been wanting to make a POV(Persistance of vision) device like the one that Ladyada sells on her site for a while now because I think that they are pretty cool. For those unfamiliar with POV devices, they use the fact that images or lights remain in your vision for a small amount of time after you first see them to make a moving column of lights write text by flashing them at a specific sequence. I found the code on the Arduino playground and just changed the test at the end of the program to say ¨NOT A BOMB¨. A little bit of a dig at the Boston police department. My device looked a whole lot more like a bomb than those that caused the ridonculous bomb scare in beantown. Anywho, the code can be seen below. I´ll try to get the pictures that Lee and I took at work the other day and post that ASAP.

/*
????????????????????????????????????????????
persistence of vision typography with arduino
michael zoellner - march 2006
http://i.document.m05.de

connect anodes (+) of 5 leds to digital ports of the arduino board
and put 20-50 ohm resistors from the cathode (-) to ground.

the letters are lookup tables consisting arrays width the dot status in y rows.
????????????????????????????????????????????
*/


// defining the alphabet
int _[] = {0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0};
int A[] = {0,1,1,1,1, 1,0,1,0,0, 0,1,1,1,1};
int B[] = {1,1,1,1,1, 1,0,1,0,1, 0,1,0,1,0};
int C[] = {0,1,1,1,0, 1,0,0,0,1, 1,0,0,0,1};
int D[] = {1,1,1,1,1, 1,0,0,0,1, 0,1,1,1,0};
int E[] = {1,1,1,1,1, 1,0,1,0,1, 1,0,1,0,1};
int F[] = {1,1,1,1,1, 1,0,1,0,0, 1,0,1,0,0};
int G[] = {0,1,1,1,0, 1,0,1,0,1, 0,0,1,1,0};
int H[] = {1,1,1,1,1, 0,0,1,0,0, 1,1,1,1,1};
int I[] = {0,0,0,0,1, 1,0,1,1,1, 0,0,0,0,1};
int J[] = {1,0,0,0,0, 1,0,0,0,1, 1,1,1,1,1};
int K[] = {1,1,1,1,1, 0,0,1,0,0, 0,1,0,1,1};
int L[] = {1,1,1,1,1, 0,0,0,0,1, 0,0,0,0,1};
int M[] = {1,1,1,1,1, 0,1,1,0,0, 0,1,1,1,1};
int N[] = {1,1,1,1,1, 1,0,0,0,0, 0,1,1,1,1};
int O[] = {0,1,1,1,0, 1,0,0,0,1, 0,1,1,1,0};
int P[] = {1,1,1,1,1, 1,0,1,0,0, 0,1,0,0,0};
int Q[] = {0,1,1,1,1, 1,0,0,1,1, 0,1,1,1,1};
int R[] = {1,1,1,1,1, 1,0,1,0,0, 0,1,0,1,1};
int S[] = {0,1,0,0,1, 1,0,1,0,1, 1,0,0,1,0};
int T[] = {1,0,0,0,0, 1,1,1,1,1, 1,0,0,0,0};
int U[] = {1,1,1,1,1, 0,0,0,0,1, 1,1,1,1,1};
int V[] = {1,1,1,1,0, 0,0,0,0,1, 1,1,1,1,0};
int W[] = {1,1,1,1,0, 0,0,1,1,0, 1,1,1,1,0};
int X[] = {1,1,0,1,1, 0,0,1,0,0, 1,1,0,1,1};
int Y[] = {1,1,0,0,0, 0,0,1,0,0, 1,1,1,1,1};
int Z[] = {1,0,0,1,1, 1,0,1,0,1, 1,1,0,0,1};
int colon[] = {0,0,0,0,0, 0,1,0,1,0, 0,0,0,0,0};

int letterSpace;
int dotTime;

void setup()
{
// setting the ports of the leds to OUTPUT
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);

// defining the space between the letters (ms)
letterSpace = 6;
// defining the time dots appear (ms)
dotTime = 3;

}

void printLetter(int letter[])
{
int y;

// printing the first y row of the letter
for (y=0; y<5; y++)
{
digitalWrite(y+2, letter[y]);
}
delay(dotTime);

// printing the second y row of the letter
for (y=0; y<5; y++)
{
digitalWrite(y+2, letter[y+5]);
}
delay(dotTime);

// printing the third y row of the letter
for (y=0; y<5; y++)
{
digitalWrite(y+2, letter[y+10]);
}
delay(dotTime);

// printing the sspace between the letters
for (y=0; y<5; y++)
{
digitalWrite(y+2, 0);
}
delay(letterSpace);
}

void loop()
{
// printing some letters
printLetter(N);
printLetter(O);
printLetter(T);
printLetter(_);
printLetter(A);
printLetter(_);
printLetter(B);
printLetter(O);
printLetter(M);
printLetter(B);
printLetter(_);

}

Tuesday, December 11, 2007

Arduino Knightrider


I finally got around to ordering an Arduino from Sparkfun.com. For those of you who don't know, Arduino is an open source platform for interfacing electronic devices with a microcontroller. More information can be found on arduino.cc. I've tried to used PIC microcontrollers in the past and found that the information available is more geared towards electronic professionals, and therefore over my head. The Arduino, on the other hand, is a collaborative project designed to be used by artists to make interactive art. If an artist can use it I sure as hell can :P The programming language is based on C, which is still a bit foreign to me, so I've resorted to asking my wife to help me since she is a computer programmer by trade. One of the first projects I've decided to make is an LED sweeper, similar to the lights on the front of Kit, the car from Knighrider. I wanted to make the lights fade in and out instead of just being on or off so I used pulse width modulation, which essentially pulses the lights really quickly; so quickly in fact that the human eye cannot easily detect it. You can control the percentage of time that the light is on by assigning a value between 0 and 255. 0 is off and 255 is on. With some help from wifey I wrote the following program to sweep 4 pairs of LEDs back and forth using pulse width modulation to make the LEDs increase in brightness and then decrease back to zero sequentially and then back down the line. A picture of the circuit can be found above and a video of the resulting sweep below the code.


/*
* Loopwithfade
* by mojomoney
*
* Lights multiple LEDs in sequence, then in reverse
* using pwm to fade, creating an incandescant effect.
* In this example 4 LEDs are used
*/
int delaytime = 3; // delay time between steps
int pwmincrement = 6; // value of increment to pwm value
int x; // number of times light sequence cycles
int i; // variable to keep the actual value
int ledpin1 = 9; // light connected to digital pin 9
int ledpin2 = 10; // light connected to digital pin 10
int ledpin3 = 11; // light connected to digital pin 11
int ledpin4 = 6; // light connected to digital pin 6
int value1; // intensity of led 1
int value2; // intensity of led 2
int value3; // intensity of led 3
int value4; // intensity of led 4

void setup()
{

}

void loop()

{ for(x = 0 ; x < 10; x++ ) // makes program cylce 10 times

{ for(i = 0 ; i <= 1530; i+=pwmincrement )

{ if (i<=255)

{
value1 = 255 - i; // fade led 1

value2 = i; // brighten led 2

analogWrite(ledpin1, value1); // sets value1 (range from 0 to 255)

analogWrite(ledpin2, value2); // sets value2 (range from 0 to 255)

delay(delaytime); // waits for 30 milliseconds to see dimming effect

}

else if (i<=510)

{

value2 = 510 - i; // fade led 2

value3 = i-255; // brighten led 3

analogWrite(ledpin2, value2); // sets value2 (range from 255 to 0)

analogWrite(ledpin3, value3); // sets value3 (range from 0 to 255)

delay(delaytime); // waits for 30 milli seconds to see the dimming effect

}

else if (i<=765)

{

value3 = 765 - i; // fade led 3

value4 = i-510; // brighten led 4

analogWrite(ledpin3, value3); // sets value3(range from 255 to 0)

analogWrite(ledpin4, value4); // sets value4(range from 0 to 255)

delay(delaytime); // waits for 30 milliseconds to see dimming effect

}

else if (i<=1020)

{

value4 = 1020 - i; // fade led 4

value3 = i - 765; //brighten led 3

analogWrite(ledpin4, value4); //sets value4(range from 255 to 0)

analogWrite(ledpin3, value3); // sets value3(range from 0 to 255)

delay(delaytime);

}

else if (i<=1275)

{

value3 = 1275 - i; // fade led 3

value2 = i - 1020; // brighten led 2

analogWrite(ledpin3, value3); // sets value3(range from 255 to 0)

analogWrite(ledpin2, value2); // sets value2(range from 0 to 255)

delay(delaytime);

}

else

{

value2 = 1530 - i; // fade led 2

value1 = i - 1275; // brighten led1

analogWrite(ledpin2, value2); // sets value2(range from 255 to 0)

analogWrite(ledpin1, value1); // sets value1(range from 0 to 255)

delay(delaytime);
}

}

}

}

Thursday, November 01, 2007

DIY Data Cable for Garmin eTrex

I have to start out by saying that I am terribly disappointed in Garmin for the exclusion of a data cable with there base eTrex GPS device, as well as the ridiculously overpriced cables that they sell to those who neglected to notice that none was included. I was almost one of those people. Not to mention that it seems as if there should be a way to program waypoints by entering coordinates. Even if doing so involved a tedious menu where you had to use the up and down buttons to increment/decrement the numbers until you got the value you wanted. Then at least you wouldn't absolutely need a $40 data cable. Okay, end of rant.
Upon doing some research I found that other people were a bit peeved at this as well and many had taken it upon themselves to fabricate there own data cables. One such man even made an injection mold and manufactures a few styles of connectors. He then sends up to two of these connectors to anyone that requests them for whatever price that they pledge to pay. They then send him that amount after they receive the connector, but only if they are satisfied with them. Seems like a pretty novel approach to commerce. Also on his site he other peoples' DIY eTrex plugs. A few of which were the inspiration for my own.
My plug is simply a piece of plastic shim stock cut to the width of the eTrex socket, with enough length such that I could hot glue the wires to it to secure them. Also, it is notched to fit the little boss protruding from the eTrex socket, and added notched where the pins need to be in order to contact the pins on the eTrex. To make the pins I soldered some leads that I had snipped off of some resistors and LEDs while making a light for my Jack-o-lantern to the appropriate wires of a serial cable. The pinout and another excellent cable build can be found here. I then bent the leads around the shim and put a mark behind the location where the eTrex pins were located. I used the marks to locate holes that I made by poking a shirt-pin through the shim. Then I bent the leads to poke up through the holes with an arch in them to ensure that they put pressure on the eTrex pins. After the leads were thus located I globbed some hot glue on the wires to hold them in place. I'll try to think of a more elegant way of fastening the wires later. For now the big glob of hot glue will have to suffice.

Thursday, October 04, 2007

IKEA Wall Hook Installation

Wifey and I decided to replace the ugly coat tree that we had in our living room by installing wall hooks behind the front door where the coats would be out of the way but easily accessibly while coming and going. We found the BLECKA, I know the name is a but odd but it is IKEA afterall, hooks and decided that they fit the aesthetic that we were shooting for and I went about mounting them to the wall. In order to ensure that they don't simply pull out of the drywall the way that our towel racks did in the bathroom, I decided to actually use some drywall anchors. I got the ones that IKEA sells which are the standard type that you drill a hole and pound them into said hole. In my experience these tend to work miserably as they are made from uber-flimsy plastic and the typically bend/break before you get them pounded in flush with the wall. Luckily I had seen my dad use a different type of drywall anchor recently and it looked much better so I decided that I'd give them a shot. This type is also made of plastic, but it is a much more rigid plastic and instead of being pounded into a pilot hole, they are screwed in. The threads are a course helical sort of thread that seems to grab drywall extremely well. The instruction don't say to, but I recommend using a nail to both make a pilot hole and to ensure that there is no stud in the location that you want the anchor to go. The pilot hole just helps to get the anchor started and if you attempt to install the anchor where there is a stud it will bottom out and snap the head off long before you get it sunk flush to the drywall. Don't worry about using in anchor where there is a stud, as you can screw into the stud and get a much better grip anyhow. Also don't try to hammer the anchor into the drywall as this will most likely lead to breaking the anchor or you pounding your thumb with a hammer. If you lack a nail to make a pilot hole you can also use the Phillips head screwdriver that you will need to turn the anchors to make a pilot hole by simply pressing the tip into the drywall. If you lack the strength to do this you are either my wife, or an extreme wuss and need to lift some weights before I throw you into a locker and you have to pound in the door until somebody hears you and lets you out. Yeah, why don't you go find as nail... I'll just wait here while you get that. Anyway, these anchors worked much better for me and the IKEA BLECKA hooks look and function pretty nicely. Sorry that the pictures aren't much to look at but I have some serious lighting issues in the living room.

Thursday, May 10, 2007

Compost Bin Build

The little lady and I have decided to try and reduce our carbon footprint and all that so I've decided to compost our kitchen waste. Not only will this be a step in reducing our carbon consumption, but it will also help me in my quest to have a healthy lawn while using only organic means. You can see from the photos that the lawn needs a lot of help. Anyhow, I've looked online for compost bin plans and decided to make a compost bin loosely based on the one I found on this site http://www.gardenorganic.org.uk/factsheets/gg24.php which I stumbled on while researching compost on www.journeytoforever.org. Since I had a pallet in the garage and a bunch of (pink)1x2's that I tore out of the porch while trying to kill ants, I decided to rip the boards from the pallet to 2 inch widths to match the 1x2's. Admittedly, not all of the boards came out to be 2 inches since pallets aren't precisely built so the boards vary in width greatly. Regardless, I wasn't shooting for perfection so it came out pretty well anyway. The only bad part was the fact that I didn't notice that the pink from the porch was facing outwards until after I screwed four of the boards on. I think that I'll have to pick up some paint and give it a coat or two to hide that. I'll post some more pictures after I get around to making more of these bins to stack on top of each other and get them all painted and such.

Tuesday, April 24, 2007

Firewood Crib Build: Part Uno

Mario had a big arse oak tree cut down so I was able to scavenge some nice firewood for the winter. The only problem is Idon't have a proper firewood crib to stack the wood in so that it will dry adequately to burn well by winter, and so that the pile won't topple over atop myself, or any innocent bystander. I have therefore decided to make a firewood crib from some 2x4's and a bed frame that I salvaged. I have just a rough picture in my head of how this project will come together, but I've already started cutting steel so hopefully it comesMy coworker together alright. So far I've cut up the bed frame and removed the casters and such by drilling
out the rivets that hold them on. It was a bit of a PITA to do so because my drill bits are apparently crap. That, and the automatic center runch that I got from Metro Tool flattened its point after the first two blows. Oh and "runch" was not a typo. That's actually what the cheap Chinese tool said on the package. That's how you know that it's a quality tool. I've also cut the arms that will connect the two angle iron beams together to form the base of the crib. It would be really nice if I had a cut-off saw to do this, or even if the battery was charged in my sawzall. Alas, neither was the case so the situation required the trusty ol' hacksaw. There are brackets already attached to one end of each of the beams on which the headboard would normally be fastened. This will be a handy way of attaching the 2x4's to one end of the base. The other end will require that I fabricate and weld a bracket on for the same purpose. For the bracket I'll just use the angle iron that I cut from the cross beams earlier. That's all for part one. Stay tuned for part 2 where I discuss the perils of drilling without properly fixturing the workpiece, and how much it hurts to be hit in the testicles by a rapidly spinning piece of angle iron.

Friday, April 06, 2007

From guns to cars: Using advanced polymers from firearms to fabricate parts for my RC car.


While I wait for some replacement parts to arrive from Tower Hobbies I've decided to fabricate some parts for my old RC10. I decided to use some plastic parts from work that are otherwise going to be thrown away. They are made out of a polymer called polyphtalamide which is a relatively new polymer that is most commonly used in the automotive industry. Lee and I decided to use it because of it's dimensional stability and stiffness. That, and we found that a high priced European rifle had used it in a similar application. Some people may consider that to be copying someone else's idea; we prefer to consider it "reverse engineering". Anyway, this stuff is pretty sweet so I've hacked up the parts with a Dremel and a utility knife and made a transmission brace and battery hold down bar. I'll probably end up fashioning the body out of gun parts if it remains back-ordered too long.

Remote Control Carnage

I recently dusted off the ammo box containing my old remote control car. I'm not sure what made me decide to get back into toying with it again since it has sat in that box for the past fifteen years or so. It didn't take me long to remember why I gave up the hobby. First off, I've lost many of the small but integral parts. I've fixed that for the most part through many trips to the hobby shop near work. So, now I've spent $100 or so to get it back in running shape; meaning that it goes forward, reverse and it turns. It still lacks a body to cover the innards and a cover for the exposed transmission gears. So I've chased the dog around the back yard three times. This last time I managed to break one of the steering blocks. Now, this part is very cheap to buy at about $2, however, it takes weeks to get a new one because the car is so old that most places don't keep parts in stock. I've ordered some parts now I have to wait for them to come. Stupid RC cars.