October 2009 project
Tuesday, 8. September 2009 4:48
Introduction
The date of the first project is set. It will be Friday, October 16. We will convene at 6 PM. We will start by helping people get setup and hope to be building by 7 PM. The date had to be moved from our original scheduled date of October 2 due to a scheduling conflict.
Our first project will be an Arduino based one. We will use the popular microcontroller to turn on and off a bunch of different colors of LEDs. Turning a few LEDs on and off won’t change the world, but this is just the first project. The Arduino basically does one of three things most of the time. It lights up indicators, activates mechanical controls and reads sensors. We will start out with the simplest case and build up from there. This project will be fairly simple, and is largely designed to introduce people to the controller.
We have a few specific goals.
-
1. Make sure everyone has their computers setup to program the Arduino
2. Introduce people to wiring circuits with breadboards
3. Get everyone thinking about what these devices can do
4. Have some fun
Parts list for October project
-
Arduino – See article on Choosing an Arduino
breadboard (630 points or larger)
22 gauge wires for breadboard
cable between arduino and computer
power supply for arduino(may be your USB cable)
shift register 74HC595
computer(Mac OSX, Linux, or Windows)
LEDs and resistors, if you want to bring them. We should have a few for each person..
Instructions
Phase 1, flash a single LED.
Our first project will be about controlling LEDs with our Arduinos. There are many ways of controlling LEDs and we will build circuits using 2 of these techniques. We will also discuss other methods and talk about why you might want to use them. First, a couple of references are in order. Look here to get some background on the two methods we will learn.
http://www.arduino.cc/en/Tutorial/BlinkingLED
http://www.arduino.cc/en/Tutorial/ShiftOut
The Arduino is a microcontroller designed to be easy to use and inexpensive. The Arduino starts with an Atmel microcontroller and adds just enough circuitry around it to make it easy to use, but not enough to make it cost much. The designers were working with art students and wanted something cheap enough to make experimentation practical. If you want to know more about the history of the project, ask at the meetings or search online.
This is our first project and one of our goals is to help people get their computers setup to program the Arduinos. I will go over the steps to do that on a Linux system, since that is what I primarily use. The process is very similar with OSX or Windows.
We should prepare the hardware first. Some Arduino boards come with an LED already installed for pin 13. Some have a resistor there, but no LED. You need to look at your manual and figure out how your pin 13 is wired. If you see 2 LEDs on your Arduino board, then one is probably the power LED and the other is probably wired to pin 13 with a 1K resistor. If you need to add the LED, I suggest we connect it on the breadboard, since we will be using the breadboard soon, anyway. Breadboards usually have buses that run up and down the sides labeled + and -. The idea is that you connect ground to the -(minus) one and some fixed voltage like 5V to the +(plus) one. Then, you will have a close by connection for either one anywhere on the breadboard. So, run a wire from a pin labeled GND on the Arduino to some pin on the – bus. Depending on your breadboard, all the column labeled – is tied together, or maybe the top half and the bottom half are separate. Now plug your LED into two nearby rows on the breadboard, noting which one gets the shorter lead. Add a little jumper from that row to connect with your ground bus. If you already have a resistor on pin 13 of your Arduino, then just run a wire from the pin labeled pin 13 on your arduino to your breadboard. Otherwise, use a resistor for this connection, since you don’t have one built in. If you don’t know, then use a resistor. Extra resistance will make the LED dimmer, but if you go without the resistor, the LED will light up real bright and burn out in a flash. One end of this wire or resistor connects with pin 13 of the Arduino and the other end goes to the same row that had the longer lead of the LED.

RBBB Arduino with LED connected on pin 13
The software to control an Arduino has several components. It consists of a cross compiler for the atmel chip, a library of functions and an IDE to make it easy to use. The real geeks might eschew the IDE(Integrated Development Environment or GUI). We will probably have a later project to show how to do everything without the IDE since there are several real geeks among us.
The Arduino software is available at:
http://arduino.cc/en/Main/Software
Go ahead and get it, but we have to check to see that a few prerequisites are in place first. The IDE is java based, and so we need to install a Java runtime. The Arduino site says you need to install Sun’s Java. You can do that if you wish, but I installed the version from the IcedTea project because it has a better license.
sudo apt-get install openjdk-6-jre
On a debian based system, you need to install two packages for the cross compiler and the library of routines. I understand that some systems do not install the avr binutils package. If you don’t see a dependancy named something like binutils-avr get installed, you will need to install it, too. On my Ubuntu system, I typed:
sudo apt-get install avr-libc gcc-avr
There was a bad version of the gcc cross compiler recently. Ubuntu version 8.10(Intrepid Ibex) had it. After installing the coplier, run the command inside the following quotes, “avr-gcc –version”. If you have version 4.3.0, then you will need to upgrade. Now, you need to decide where you want the files for the Arduino IDE to reside. In my case, I decided to put them directly under my home directory. So, I made that directory my current directory and unpacked the IDE. If the downloaded file is in another directory, you will have to specify the path to that directory and the file name. AT the time I wrote this article, version 17 was current. If newer versions have come out, please adjust the file name accordingly.
cd ~
tar -zxvf arduino-0017.tgz
Now, change into the directory you just created by taking apart the compressed tar file. In my case, it is arduino-0017. Then, we will run the IDE.
cd arduino-0017
./arduino
The first time we run the IDE, we want to look at the settings. Go to Tools/Serial Port and see that you have the right one selected. If you are using a real serial port, it will look like /dev/ttyS1. If you are using a USB cable, it will look like /dev/ttyUSB0. Setting that will tell the computer how to find your Arduino. Now, go to Tools/Board and set the type of processor you have. There are different speeds and amounts of memory your chip may have and the IDE needs to know your specifics so it can compile the code properly for your chip. In my case, I set it for “Arduino Duemilanove or Nano w/ATmega328″
Now, go to the web page of the first tutorial listed above. Copy the program and paste it into the Arduino IDE. Press the play button in the icon bar near the top of the IDE. The program should then compile. Now, we can upload it to the Arduino where it will automatically run. If you hover the mouse over the icon second from the right, it should say Upload to Arduino. Press that button. If you get a message about having trouble communicating with your Arduino, press the reset button on the Arduino and upload again. This problem almost never occurs with the true serial port Arduinos. You should now be running your program on the Arduino. We can now add more LEDs and modify the program. But, the biggest hurdles are all past us now.
Phase 2, flash a few LEDs.
The second phase is just a modest extension. We are going to add two more LEDs. We will use pins 9 and 10 of the Arduino for these new LEDs. We need to add resistors on those lines because the Arduino never has a resistor already installed on those lines. That built-in resistor is a special feature just used on pin 13 of some Arduinos. We will also use a shortcut that saves a wire for each LED. For the grounded side of the new LEDs, we will just plug them directly into the ground bus.

Arduino hooked to LEDs on pins 9, 10, and 13
After installing those few extra components, we need to modify our program a little bit. We need to tell it what to do with pins 9 and 10.
/* Blink 3 LEDs sequentially
* ------------
*
* turns on and off 3 light emitting diodes(LED) connected to digital
* pins, in intervals of 2 seconds. Ideally we use pin 13 on the Arduino
* board because it has a resistor attached to it, needing only an LED.
* We also use pins 9 and 10, where resistors are definitely needed.
*
* Created 25 September 2009
*
* based on a program copylefted 2005 DojoDave
* http://arduino.berlios.de
*
* based on an original by H. Barragan for the Wiring i/o board
*/
int ledPin = 13; // LED connected to digital pin 13
int led2Pin = 10; // LED connected to digital pin 10
int led3Pin = 9; // LED connected to digital pin 9
void setup()
{
pinMode(ledPin, OUTPUT); // sets the digital pin as output
pinMode(led2Pin, OUTPUT); // sets the digital pin as output
pinMode(led3Pin, OUTPUT); // sets the digital pin as output
}
void loop()
{
digitalWrite(ledPin, HIGH); // sets the LED on
digitalWrite(led2Pin, HIGH); // sets the LED on
digitalWrite(led3Pin, HIGH); // sets the LED on
delay(1000); // waits for a second
digitalWrite(ledPin, LOW); // sets the LED off
digitalWrite(led2Pin, LOW); // sets the LED off
digitalWrite(led3Pin, LOW); // sets the LED off
delay(1000); // waits for a second
}
Run that and you should see the 3 LEDs blink on and off in sequence. A circuit similar to this is used for a lot of Arduino projects. The enhancements people make are in the programs they load into the Arduino. Without any changes to the hardware, let’s try a little(just a little) more interesting program.
/* Blink 3 LED in a simple pattern
* ------------
*
* turns on and off 3 light emitting diodes(LED) connected to digital
* pins, in a simple pattern. Ideally we use pin 13 on the Arduino
* board because it has a resistor attached to it, needing only an LED.
* We also use pins 9 and 10, where resistors are definitely needed.
*
* Created 25 September 2009
*
* based on a program copylefted 2005 DojoDave
* http://arduino.berlios.de
*
* based on an original by H. Barragan for the Wiring i/o board
*/
int ledPin = 13; // LED connected to digital pin 13
int led2Pin = 10; // LED connected to digital pin 10
int led3Pin = 9; // LED connected to digital pin 9
void setup()
{
pinMode(ledPin, OUTPUT); // sets the digital pin as output
pinMode(led2Pin, OUTPUT); // sets the digital pin as output
pinMode(led3Pin, OUTPUT); // sets the digital pin as output
}
void loop()
{
digitalWrite(ledPin, HIGH); // sets the LED on
delay(500); // waits for a second
digitalWrite(ledPin, LOW); // sets the LED off
delay(1000); // waits for a second
digitalWrite(led2Pin, HIGH); // sets the LED on
delay(500); // waits for a second
digitalWrite(led2Pin, LOW); // sets the LED off
delay(1000); // waits for a second
digitalWrite(led3Pin, HIGH); // sets the LED on
delay(500); // waits for a second
digitalWrite(led3Pin, LOW); // sets the LED off
delay(1000); // waits for a second
digitalWrite(ledPin, HIGH); // sets the LED on
digitalWrite(led2Pin, HIGH); // sets the LED on
delay(500); // waits for a second
digitalWrite(ledPin, LOW); // sets the LED off
digitalWrite(led2Pin, LOW); // sets the LED off
delay(1000); // waits for a second
digitalWrite(led2Pin, HIGH); // sets the LED on
digitalWrite(led3Pin, HIGH); // sets the LED on
delay(500); // waits for a second
digitalWrite(led2Pin, LOW); // sets the LED off
digitalWrite(led3Pin, LOW); // sets the LED off
delay(1000); // waits for a second
digitalWrite(ledPin, HIGH); // sets the LED on
digitalWrite(led2Pin, HIGH); // sets the LED on
digitalWrite(led3Pin, HIGH); // sets the LED on
delay(500); // waits for a second
digitalWrite(ledPin, LOW); // sets the LED off
digitalWrite(led2Pin, LOW); // sets the LED off
digitalWrite(led3Pin, LOW); // sets the LED off
delay(1000); // waits for a second
}
You should see how that can be expanded to do more interesting light effects. The problem is going to be that you will soon run out of pins on the Arduino. There are a number of ways that people expand the number of LEDs you can control with an Arduino. We will look at a simple one next.
Phase 3, flash a bunch of LEDs.
There is one part you were asked to get that we have not used yet. It is the 74HC595. This chip is a shift register. That means we can send an 8 bit value to it and it will do two things. It will remember the value as long as we keep power to the circuit and it will send each of those bits to one of it’s pins. For a 1, it sets the pin to high, or 5V. For a 0, it sets the pin to low, or 0V. That is exactly what we need to drive 8 LEDs. The Arduino homepage has a tutorial using the 74HC595 and we will next build the first example in that tutorial.
… More to come …
Further references:
Category:Projects | Comment (0) | Author: ralph