Tuesday, August 19, 2014

Programming Servos and LCD Shield

Reminder: Servos each have three wires.
In ours, black is ground, red is power, and white is signal.

Because we have two servos and not enough Arduino pins, we needed a breadboard for two of the three sets of 2 wires (for ground and power). We attached them to the breadboard for now and then ran two wires from each segment on the breadboard to the corresponding receptor on the ArduinoUno. The wires for signal will each be getting their own signal and there are plenty of signal receptors on the ArduinoUno so those could connect directly to the Arduino. In this case I am putting them into pins 8 and 9.
Again, this is all a prototype. A more permanent soldering job will be needed to attach everything later. For now, extra wires are used to connect the servos, Arduino, and breadboard.






Using breadboard for prototyping, we wired servos to the Arduino and programmed the Arduino to talk to servos. We're telling each servo to move together 180 degrees.

[video]

Code:
Sweep”, under Examples → Servo
...The writing in bold was added to the example since this prototype is using two servos and they will be moving together. Remember “//”signals a comment and is not read by the Arduino.

// Sweep
// by BARRAGAN <http://barraganstudio.com>
// This example code is in the public domain.


#include <Servo.h>
Servo myservo; // create servo object to control a servo
Servo myservo2; // a maximum of eight servo objects can be created
int pos = 0; // variable to store the servo position
void setup()
{
myservo.attach(9);
myservo2.attach(8); // 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);
myservo2.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);
myservo2.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}

We set up servos in bracket. Later, we will need to attach to foundation and epoxy solar cell to top bracket.


LCD screen-
The LCD screen lets us read what the Arduino is thinking for now. We are using the Adafruit LCD Shield. It is only for the prototype. We pop it on over the Arduino and use it to give us information about how much solar energy the solar cell is collecting. After we tell the Arduino to figure our the sun's position on its own, we'll pop off the LCD Shield to save energy.



No comments:

Post a Comment