Ian Henderson

Week 13 - Output Devices



Click for Lecture Video

Week 13 - Output Devices

16 April 2012 13:40 Monday

Assignment: add an output device to a microcontroller board and program it to do something.

I intend to set up a servo motor which I will run off of an Arduino board. First I will have to build the board. It took me three attempts to mill the board because the traces are so fine and on the first two trials the pulled up. By the 3rd trial my toolbits were slightly dulled, which makes them cut a tiny bit cleaner and kept the traces from pulling up. Unfortunately, I forgot to set the milling machine to cut out any extraneous copper, and so there is excess material on the board, which for me can be confusing. I borrowed Anna's board as a reference, and with a sharpie, I highlighted all the extraneous areas so I would not get confused while soldering. Now I will attempt to put the board together.

16 April 2012 15:06
I have now soldered all of the components onto the Arduino board which is to drive the servo motor. I am using an ATmega328 instead of an ATmega168, so I will have to modify my diver code accordingly.


I have hooked up the Arduino board and the FabISP. I have burned the bootloader. The LED is now blinking.

I have burned the sample program:

/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.
 
  This example code is in the public domain.
 */

void setup() {                
  // initialize the digital pin as an output.
  // Pin 13 has an LED connected on most Arduino boards:
  pinMode(13, OUTPUT);     
}

void loop() {
  digitalWrite(13, HIGH);   // set the LED on
  delay(1000);              // wait for a second
  digitalWrite(13, LOW);    // set the LED off
  delay(1000);              // wait for a second
}


Everything seems to be working OK. Now to figure out the servo motor part.

18 April 2012 14:23 Wednesday
After consulting with Anna and looking over the data sheet for the ATmega 328 and the helloArduino board, I was able to determine which pins the servo cables need to be connected to.


finished board

As you can see from the image, I needed to use special splitter cables to connect all the right pins, because VCC (power) and GND(ground) are at a separate 6pin connector site from the control connector which leads to pin9 on the ATmega328 chip.(it is called "pin9" only in arduino code. On the datasheet it is actually called "PB1")

After I plugged everything in, the servo motor moved, probably into its "neutral" position. Now I need to program it to do something. I will start with this sample code from the Arduino program, called "sweep":
// Sweep
// by BARRAGAN  
// This example code is in the public domain.


#include  
 
Servo myservo;  // create servo object to control a servo 
                // a maximum of eight servo objects can be created 
 
int pos = 0;    // variable to store the servo position 
 
void setup() 
{ 
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object 
} 
 
 
void loop() 
{ 
  for(pos = 0; pos < 180; pos += 1)  // goes from 0 degrees to 180 degrees 
  {                                  // in steps of 1 degree 
    myservo.write(pos);              // tell servo to go to position in variable 'pos' 
    delay(15);                       // waits 15ms for the servo to reach the position 
  } 
  for(pos = 180; pos>=1; pos-=1)     // goes from 180 degrees to 0 degrees 
  {                                
    myservo.write(pos);              // tell servo to go to position in variable 'pos' 
    delay(15);                       // waits 15ms for the servo to reach the position 
  } 
} 



arduino and fabISP connected

And it seems to work!

I played around with some of the variables to make it sweep at different rates and to different angles. Without a more in-depth understanding of code, I won't be able to do a whole lot more than this. I think the servo motor could be useful in combination with a motion or distance sensor, to make lifelike objects which open or contract in response to human presence.

It should also be possible to read back the position of the servo and use that data to do other things, such as causing an LED to grow brighter as the servo moves through its range of motion.

I once had an idea for a sculpture project which consisted of a metal flower with a glowing glass seed pod inside. The flower would bloom slowly as the viewer approached it, and the seed pod would glow in response to ambient noise. I would love to reprise this project and actually make it work.

18 April 2012 14:44 Wednesday
I think this covers my requirements for the class. I'm way behind on several other assignments, so as much as I'd like to continue tinkering, I don't think I've got that luxury at the moment.