Error codes in my compiling, cannot understand....

Hi everyone. I think I finally have my program finished…ALMOST. It’s two programs, two units, talking over VirtualWire. The first, no hitches. The second, which looks EXACTLY like this:

// Include VirtualWire library
#include <VirtualWire.h>
//And don't forget the Servo
#include <Servo.h>
 
Servo thisservo; //Servo object

// Pins definition
const int servo_pin = 13; //to control the servo
const int transmit_pin = 12;
const int receive_pin = 11;
const int led_pin = 10;
const int delayer = 1; //determines delay
int pos; //"position" integer
char received; //the received character
long waitdelay = 5000; //how long to wait to avoid "double feeding"

uint8_t buf[2]; //set to minimum length, to accomadate "terminator"
 
void setup()
{
   // Init
   delay(1000);
   Serial.begin(9600); // Debugging only
   Serial.println("setup");
 
   // Initialise the IO and ISR
   vw_set_rx_pin(receive_pin);
   vw_setup(2000); // Transmission rate
 
   // Start the receiver PLL
   vw_rx_start();
 
   // set Servo pin
   thisservo.attach(servo_pin);
   
   // set LED pin
   pinMode(led_pin, OUTPUT);

}

void loop()
{
  uint8_t buf[VW_MAX_MESSAGE_LEN];
  uint8_t buflen = VW_MAX_MESSAGE_LEN;
  
  //check for message received
  if (vw_get_message(buf, &buflen))
  {
    //flash a light, flash a light
    digitalWrite(led_pin, HIGH);
    Serial.print("Ack:");
    
    //Servo runs, only if "1" is received
    if (vw_get_message(buf,&buflen)) {
     if (buf[0] == '1')
     {
      for(pos = 0; pos < 90; pos += 1)  // goes from 0 degrees to 90 degrees
      {                                  // in steps of 1 degree
        thisservo.write(pos);              // tell servo to go to position in variable 'pos'
        delay(delayer);                       // waits for the servo to reach the position
      }
      for(pos = 90; pos>=1; pos-=1)     // goes from 90 degrees to 0 degrees
      {                               
        thisservo.write(pos);              // tell servo to go to position in variable 'pos'
        delay(delayer);                       // waits for the servo to reach the position
      }
      delay (waitdelay);  //waits to avoid "double feeding")
     }
//if "0" is received, nothing happens
  }

  }
}

suddenly has issues. Here’s the errors…separated for your convenience (are you supposed to put “errors” as code here?)

Servo\Servo.cpp.o: In function __vector_11': C:\Program Files (x86)\Arduino\libraries\Servo/Servo.cpp:105: multiple definition of __vector_11’

VirtualWire\VirtualWire.cpp.o:C:\Program Files (x86)\Arduino\libraries\VirtualWire/VirtualWire.cpp:588: first defined here

Thank you,
~Ra’akone

I think the VirtualWire library and the Servo library are using the same timer interrupt. They will not work together. You may have to find a replacement for one or both libraries.

This thread is about a similar problem.
http://forum.arduino.cc/index.php?topic=283764.0
See Robin2's post for a solution.

Ok, any alternatives to "servo.h" that use a different timer interrupt? I ask about that one first, so that way I'll only have to change one file instead of two.

I just started using an adafruit Trinket based on the ATtiny. They wrote a software servo library for it.... maybe try that or something similar?

Raakone:
Ok, any alternatives to "servo.h" that use a different timer interrupt? I ask about that one first, so that way I'll only have to change one file instead of two.

You could try the servoTimer2 library. I got my copy here

@Henry_Best's link is a bit mangled - but I think it is to a Thread with a problem with SoftwareSerial

...R

Thanks. The download site seems to be termporarily semi-disabled. But I looked for info elsewhere, apparently instead of "angle", I have to think in "miliseconds"....is there some kind of conversion guide? Or does it mean it goes from "zero" to "full" for that number of miliseconds?

No the servo doesn’t move for that amount of time; the time is the length of the pulse that the servo responds to.

1500 microseconds is the centre, which would be 90 in degrees; 1000 is 0 degrees and 2000 is 180.

Behind the scenes, if you ask for 90 degrees with servo.write(90), it sends a 1500us pulse as if you had coded a servo.writeMicroseconds(1500) yourself.

The pulse is repeated automatically by Arduino, in a 20ms (50Hz) cycle, to “remind” the servo where it ought to be. So if a load is trying to move the servo, it gets a “nudge” back to the right place on a 20ms cycle… see attached 'scope shot. This 20ms repeat is normal in the world of servos.

servo attached.jpg

Thanks, and I just noticed from your signature...."do not power servos from Arduino 5v"....even a simple single one? Should I get the AC adaptor? Or do things get more complicated here?

Well it’s a matter of current.

We’ve probably all run a small servo with no load, straight from the Arduino 5V, with no apparent harm. I think- not sure, you’ll need to check- that the 5V pin can provide 500mA. But as soon as you have a load, you’re heading towards an Amp for a servo. Forum wisdom is to budget 1A per servo, so base your supply on that.

If when you do use an external supply, hook its -ve to the Arduino ground as shown below, else the Arduino signal to the servo has no “0” to measure against.

servo power.png

Ok. Just trying to “migrate” the code to the new reality of using the timer. Still getting error messages, how do I properly “declare” the servo to be used now?

// Include VirtualWire library
#include <VirtualWire.h>
//And don't forget the ServoTimer2
#include <ServoTimer2.h>
 
Servo thisservo; //Servo object

// Pins definition
const int servo_pin = 13; //to control the servo
const int transmit_pin = 12;
const int receive_pin = 11;
const int led_pin = 10;
const int delayer = 1; //determines delay
int pos; //"position" integer
char received; //the received character
long waitdelay = 5000; //how long to wait to avoid "double feeding"

uint8_t buf[2]; //set to minimum length, to accomadate "terminator"
 
void setup()
{
   // Init
   delay(1000);
   Serial.begin(9600); // Debugging only
   Serial.println("setup");
 
   // Initialise the IO and ISR
   vw_set_rx_pin(receive_pin);
   vw_setup(2000); // Transmission rate
 
   // Start the receiver PLL
   vw_rx_start();
 
   // set Servo pin
   thisservo.attach(servo_pin);
   
   // set LED pin
   pinMode(led_pin, OUTPUT);

}

void loop()
{
  uint8_t buf[VW_MAX_MESSAGE_LEN];
  uint8_t buflen = VW_MAX_MESSAGE_LEN;
  
  //check for message received
  if (vw_get_message(buf, &buflen))
  {
    //flash a light, flash a light
    digitalWrite(led_pin, HIGH);
    Serial.print("Ack:");
    
    //Servo runs, only if "1" is received
    if (vw_get_message(buf,&buflen)) {
     if (buf[0] == '1')
     {
      for(pos = 1000; pos < 2000; pos += 100)  // goes from 0 degrees to 19-- degrees
      {                                  // in steps
        thisservo.write(pos);              // tell servo to go to position in variable 'pos'
        delay(delayer);                       // waits for the servo to reach the position
      }
      for(pos = 2000; pos>=1100; pos-= 100)     // goes from 180 degrees to 0 degrees
      {                               
        thisservo.write(pos);              // tell servo to go to position in variable 'pos'
        delay(delayer);                       // waits for the servo to reach the position
      }
      delay (waitdelay);  //waits to avoid "double feeding")
     }
//if "0" is received, nothing happens
  }

  }
}

Thanks,
~Ra’akone

Still getting error messages

And they are?

how do I properly "declare" the servo to be used now?

The ServoTimer2 library defines a class. What is that class called? THAT is the type to be used to create the servo instance.

Raakone:
how do I properly "declare" the servo to be used now?

? ? ? ServoTimer2 ? ? ?

Not very hard to guess ?

...R

Edit to remove the unintended smileys - apparently 3 question marks = 1 smiley
Apologies if any offence was inadvertently cause.

Updated, now with the full code. I just changed a line, but seeing as all the code fits into a convenient “code window” I left it all here.

// Include VirtualWire library
#include <VirtualWire.h>
//And don't forget the ServoTimer2
#include <ServoTimer2.h>
 
ServoTimer2 thisservo; //Servo object THIS IS THE PART THAT HAS CHANGED!

// Pins definition
const int servo_pin = 13; //to control the servo
const int transmit_pin = 12;
const int receive_pin = 11;
const int led_pin = 10;
const int delayer = 1; //determines delay
int pos; //"position" integer
char received; //the received character
long waitdelay = 5000; //how long to wait to avoid "double feeding"

uint8_t buf[2]; //set to minimum length, to accomadate "terminator"
 
void setup()
{
   // Init
   delay(1000);
   Serial.begin(9600); // Debugging only
   Serial.println("setup");
 
   // Initialise the IO and ISR
   vw_set_rx_pin(receive_pin);
   vw_setup(2000); // Transmission rate
 
   // Start the receiver PLL
   vw_rx_start();
 
   // set Servo pin
   thisservo.attach(servo_pin);
   
   // set LED pin
   pinMode(led_pin, OUTPUT);

}

void loop()
{
  uint8_t buf[VW_MAX_MESSAGE_LEN];
  uint8_t buflen = VW_MAX_MESSAGE_LEN;
  
  //check for message received
  if (vw_get_message(buf, &buflen))
  {
    //flash a light, flash a light
    digitalWrite(led_pin, HIGH);
    Serial.print("Ack:");
    
    //Servo runs, only if "1" is received
    if (vw_get_message(buf,&buflen)) {
     if (buf[0] == '1')
     {
      for(pos = 1000; pos < 2000; pos += 100)  // goes from 0 degrees to 19-- degrees
      {                                  // in steps
        thisservo.write(pos);              // tell servo to go to position in variable 'pos'
        delay(delayer);                       // waits for the servo to reach the position
      }
      for(pos = 2000; pos>=1100; pos-= 100)     // goes from 180 degrees to 0 degrees
      {                               
        thisservo.write(pos);              // tell servo to go to position in variable 'pos'
        delay(delayer);                       // waits for the servo to reach the position
      }
      delay (waitdelay);  //waits to avoid "double feeding")
     }
//if "0" is received, nothing happens
  }

  }
}

And now things are better…EXCEPT…

C:\Program Files (x86)\Arduino\libraries\ServoTimer2\ServoTimer2.cpp:24:5: error: expected constructor, destructor, or type conversion before ‘(’ token

Am I clueless or what? laughs

Thanks for all your help so far!

Raakone:
And now things are better...EXCEPT...

Except you did not post the updated code that is causing the problem.

...R

updated, with code added!

Raakone:
updated, with code added!

Maybe. But because you changed the earlier version we now cannot look at the two and see the changes.

When you change your code post the whole thing again. Don't replace an earlier version.

AND ... does everything work properly now?
If not, what is actually happening?

...R

I get this error message...

C:\Program Files (x86)\Arduino\libraries\ServoTimer2\ServoTimer2.cpp:24:5: error: expected constructor, destructor, or type conversion before '(' token

Maybe. But because you changed the earlier version we now cannot look at the two and see the changes.

Au contraire. The newer one is at the bottom of page 1, early one is slightly further up. The difference is I incorrectly used the term "Servo" (based on what I used to use) instead of "ServoTimer2" (since I was using a different class now!) But it's now referring to the ServoTimer2.cpp file instead of my file.

Raakone:
Au contraire.

Never mind the clever French. It is much easier for me to follow the Forum for many different people if you post things in chronological order rather than back-tracking.

I can't see anything wrong with your code that would cause that error and I don't recall having any problem with that Library myself.

You will need to dig into the Library code and see what there is in or about line 24 that is causing the error. Can you post the library code as an attachment - I presume yours is different from mine if mine is not giving an error.

...R

I downloaded ServoTimer2 from the link provided earlier and your sketch compiled fine for UNO and MEGA on Arduino 1.0.6. The compiler error you are getting must be something about your installation.