Go Down

Topic: [Help] Controlling 2 Servomotors, GPS + LCD with Arduino Uno (Read 1 time) previous topic - next topic

TorakFirenze

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:

Code: [Select]

Serial.begin(115200);
uart_gps.begin(4800); 
LCD.begin(9600);



Some of the code in my main loop looks as follows:
Code: [Select]

   
    //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

wildbill

Looks like a timer conflict between the servo & software serial libraries. Another user with the same issue:library conflict

Robin2

You may be able to solve the problem with the ServoTimer2 library  I got my copy here.

Alternatively you might be able to use a different Software serial library. I wrote a very simple one here (it's not actually a library).

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

TorakFirenze

Looks like a timer conflict between the servo & software serial libraries. Another user with the same issue:library conflict
Hi Wildbill,
Thanks for your response!  I also figured it might have been some hardware conflict, but I didn't realise an LCD or a GPS would use the timer on the Arduino, can you explain where this might occur?  I guess the Arduino must read data from the GPS on a clock edge or something and that's why there's a timer conflict or...? 
It is reassuring - in a way - to know others have faced the same issue, it means my code potentially isn't terrible! :)

You may be able to solve the problem with the ServoTimer2 library  I got my copy here.

Alternatively you might be able to use a different Software serial library. I wrote a very simple one here (it's not actually a library).

...R
Hi Robin2,

I will definitely try these out, and see if I can figure out how to use them effectively before giving up with my Uno!  Thank you!

If there are any other suggestions, I am completely open to hear them! ^^

Go Up