Nick,
Thanks for the interrupt explanation.
I gave this a try and while the servo works, I can no longer read the GPS.
// gps code adapted from http://www.sparkfun.com/tutorials/173
// servo code adapted from http://arduino.cc/it/Tutorial/Sweep
// boolean debug = true;
// setup gps
// #include <SoftwareSerial.h>
// SoftwareSerial uart_gps(RXPIN, TXPIN);
#include <TinyGPS.h>
#define RXPIN 2
#define TXPIN 3
#define GPSBAUD 4800
TinyGPS gps;
float latitude, longitude;
// setup steering servo
#include <Servo.h>
Servo steeringServo; // 1000 us < input < 2000 us
void setup() {
Serial.begin(GPSBAUD);
// start steering servo
steeringServo.attach(8);
}
void loop() {
// read gps
while(Serial.available())
{
int c = Serial.read();
if(gps.encode(c))
{
gps.f_get_position(&latitude, &longitude);
}
}
// it takes 20 readings before latitude and longitude readings work
Serial.print("Current Lat/Long: ");
Serial.print(latitude,6);
Serial.print(", ");
Serial.println(longitude,6);
Serial.println("");
// send steering angle
steeringServo.writeMicroseconds(1500);
}
In my experience, in order for the servo to hold a particular angle, it needs to be constantly receiving a PWM signal. However, if I am manually generating the PWM signal, then any time the Arduino runs other code (e.g, updating the gps or running the obstacle avoidance algorithm), it stops sending the PWM signal. Is there a work around for this?
If I picked up a mega (http://arduino.cc/en/Main/ArduinoBoardMega2560), with multiple serial ports, perhaps the GPS and Servo wouldn't fight over one. I read about other folks having success with getting the Sparkfun GPS shield to work on the mega (Arduino Forum), but I don't understand how UNO shields can work on Megas--it seems like the board layouts are different. Are Uno shields compatible with Mega boards? Might a Mega solve my problem?