Pages: [1]   Go Down
Author Topic: problem with SoftwareSerial and servo libraries  (Read 1558 times)
0 Members and 1 Guest are viewing this topic.
Maidenhead
Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


I am using Arduino UNo with  GPS data going into pin 3
and a servo connected to pin 9 - nothing else.

I am using 3 libraries
SoftwareSerial
Servo
TinyGPS

but my problem seems to be between SoftwareSerial and Servo

If I install the demo Servo code everything works fine.

I have simplified my code as much as pos - to show the problem
(No code at all in the loop, and no TinyGPS library)

If i include the line (see code below)
ss.begin(9600);

then i get random erratic movement from the servo on pin 9 every second - even though the
myservo.write(pos); is commented out.

(I need "ss.begin(9600)"  as I am using TinyGPS.)

If I comment out this code then I can get the servo to behave (but I cant then use TinyGPS which needs this line.)
ANy ideas anyone - I am completely stuck
SoftwareSerial seems to be sending something down pin 9??

ANdrew






Code:
#include <Servo.h>
 #include <SoftwareSerial.h>

SoftwareSerial ss(3, 4);

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

//next line cases the problems
//ss.begin(9600);
}
 
void loop()
{
    //pos = random(5);
    //myservo.write(pos);
    //delay(1200);
}
Logged

New Hampshire
Offline Offline
God Member
*****
Karma: 17
Posts: 781
There are 10 kinds of people, those who know binary, and those who don't.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

http://forums.adafruit.com/viewtopic.php?f=25&t=29695
Logged


Maidenhead
Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

many thanks for link - It confirms there is a problem but doesn't seem to come up with any workaround.
ANy ideas anyone?

Thanks all

Andrew
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 108
Posts: 5144
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The current SoftwareSerial library doesn't use timer 2 (it doesn't use any timer) and Servo uses timer 1 (and not 2), so the solution presented in the adafruit forum won't work. Do you use the IDE 1.0.1?

You say the single line of "ss.begin(9600);" is enough for the Servo to go wild? Is this only if the GPS is attached or also without the GPS? The ss.begin() method installs a pin change interrupt for the reception pin you specified. This interrupt routine is called every time an edge is detected on that pin. The routine is controlling the processor for the whole time a byte needs to be transferred. So if you have a busy serial line attached your processor is doing almost nothing else than receiving bits on that line. Try to change to the hardware serial because there the hardware is handling all that stuff interrupting the processor only for a very short time to store the received byte in the buffer.
Logged

Pages: [1]   Go Up
Jump to: