Hi all,
First off, sorry for the first post asking for help - it's really the first time I've encountered a problem and haven't found an answer to it somewhere.
I'm a electrical + computer engineering student, final year, and I'm working on a project, as mentioned in the title, that involves 2 servo motors, a GPS (EM506), and a standard Sparkfun LCD (16x2).
I have got a controller that rotates each motor in one direction or another, at variable speeds, and that's all fine.
I can read data from my GPS perfectly.
I can write to my LCD with no problems.
The issues come in, when I try to do these together. I have used the standard SoftwareSerial library to set up a separate serial communication link for my GPS and my LCD, however, when I try to use these, my servo motor(s) bug out completely. They demonstrate ringing/oscillatory characteristics and I'm not entirely sure why. I have also made use of the built in Servo library, and Mikal Hart's renowned TinyGPS library.
My initialisation of all the serial stuff is as follows:
Serial.begin(115200);
uart_gps.begin(4800);
LCD.begin(9600);
Some of the code in my main loop looks as follows:
//print last latitude
lcdPosition(0,0);
LCD.print(Lat1);
//print last longitude
lcdPosition(254,192);
LCD.print(Long1);
uart_gps.listen();
for (unsigned long start = millis(); millis() - start < 1000;)
{
if (uart_gps.available() > 0)
{
int c = uart_gps.read();
if(gps.encode(c)) // if there is a new valid sentence...
{
getgps(gps); // then grab the data.
Lat1 = getLat(gps);
Long1 = getLong(gps);
Alt1 = getAlt(gps);
}
}
}
ServoControl(xspeed);
xspeed is an analog value read from the controller I have connected, and is sent to a function that moves the servo motor at a speed related to the xspeed value. I had to order the things the way they are, as if, for some reason, the LCD print commands came after the GPS commands, I couldn't even print GPS data to the serial monitor.
So as I said, everything works fine individually. The motor works fine by itself and I can control it at variable speeds. I can write to my LCD and get data from GPS fine too, but when I try to do it all at the same time, my motor starts ringing or oscillating from 0 to an arbitrary point continuously and I lose all control.
If anyone has any input or suggestions as to how to remedy this problem of an oscillating servo motor once serial communications are initialised for the GPS and LCD, I would be very appreciative!
I can provide more code/elaborate further on anything that was unclear. I have consulted some colleagues and they suggest it's an issue with the Uno itself - that it's ports are limited and I should just get a mega, though I thought I'd do some research to see if there's anything I have overlooked or anything I can do to remedy this before spending the extra money!
Regards
TF