servo.write() behaving unexpectedly

First off, I'm using Servo2, it was necessary to use the older version because VirtualWire doesn't play nice with Servo.

I couldn't find the original version, so I found the one that had a few extra lines to make it Mega compatible, and commented out those lines. (If anyone has the ORIGINAL servo 2, let me know, for testing purposes).

Here's my code:

#include <VirtualWire.h> 
#include <Servo2.h>
Servo myservo;
int pos = 90;
int RXPin = 4;
int servoPin = 9;
void setup()
{
  myservo.attach(servoPin);
  Serial.begin(9600);    

  // Initialise the IO and ISR
  vw_set_ptt_inverted(true);    // Required for RX Link Module
  vw_setup(2000);                   // Bits per sec
  vw_set_rx_pin(RXPin);           // We will be receiving on pin 4,  ie the RX pin from the module connects to this pin.
  vw_rx_start();                      // Start the RF receiver
}

void loop()
{
  uint8_t buf[VW_MAX_MESSAGE_LEN];
  uint8_t buflen = VW_MAX_MESSAGE_LEN;

  if (vw_get_message(buf, &buflen)) // check to see if anything has been received
  {
    if (buf[0] == 'L'){
      pos = 60;
    }
    if (buf[0] == 'R'){
      pos = 120;
    }
    if (buf[0] == 'S'){
      pos = 90;
    }

    myservo.write(pos);
    delay(200);
    Serial.println(buf[0]);   
  }
}

Now when I comment out "myservo.write(pos);" the if statement evaluates just as it should, every time it's run there is data read from the receiver, it properly determines if it read L, R, or S, and adjusts variable "pos" accordingly.

When I uncomment "myservo.write(pos);" the first if statement evaluates false, and I have no idea why.

It is worth mentioning that when I press the reset button, when the program first loads it'll run all the way through correctly JUST ONCE.

The Serial.println(buf[0]) is just there for debugging.

Can anyone shed some light on why myservo.write is causing this problem? (And if anyone has the original Servo2 library, can they link it for me please?)

There is a link to the old servo library here:
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1266553734/33#33

Thanks for the reply PaulS. I redownloaded and replaced the Servo2 library, and the problem persists. The code runs through once, then the first if statement evaluates false so long as the servo code is in place.

Is there a load on the servo? Could you detach the servo before reading, and attach it again after reading?

Ah! I thought about that too. When the arduino is connected to USB power the servo drains enough power to shut off the hub. I've tried it with and without, only difference is where I have to power it from.

I noticed that both libraries use OCR1A, it's my understanding that that's the timer used for PWM. Could this be the problem?

I don't think it's a good idea to power the servo from the USB port. But, what I was wondering was what the servo is moving. If it's possible that whatever it is that it is moving wouldn't move too far, you might try using Servo::detach() before the virtual wire stuff, and Servo::attach() again after the virtual wire stuff.

I plug the arduino into the wall to run the servo.

The servo hasn't been put under a load yet, according to the serial debugging I've done, the arduino just never receives a second wave of information.

I tried the detach idea already, but I think i'll give it another go.

See why I'm so dumbfounded? xD

Thanks again for your help, I'll work some more with detach and post my findings.

UPDATE:

Ok, I tried using detach, both inline and as a function.

Both ways had the same end result. However when I hardcoded values for the servo to move to, it had no problems moving.

Seems like the issue is really traced back to VirtualWire. I don't know why moving the servo has any effect on it, but it seems to be the case. Is there any alternative to VirtualWire that has error checking etc? I tried just using Serial, and I found I got a lot of garbage in my transmissions.