4
\$\begingroup\$

I'm using an Arduino Uno. My motive is to control a servo via wireless transmission using RF. So for that I have to use both Virtual Wire.h and Servo.h. But when I am compiling it shows me errors that is not defined and other problems. When I studied on net it shows that both uses Timer1 so we have to change the timer of Servo. So there are some suggestions and fixes found on net that guided me to use a new library called ServoTimer2.h.

http://arduino.cc/forum/index.php/topic,21975.0.html

Now when i use this library it doesn't seem like its been included in the arduino library. Also the color of Servotimer2.h doesn't change also.

Errors showed while compiling

#include <VirtualWire.h>
#include <Servo.h>

void setup(){}

void loop(){}
Servo\Servo.cpp.o: In function `__vector_11':
C:\arduino-1.0.3\libraries\Servo/Servo.cpp:103: multiple definition of `__vector_11'
VirtualWire\VirtualWire.cpp.o:C:\arduino-1.0.3\libraries\VirtualWire/VirtualWire.cpp:568: first defined here
\$\endgroup\$
2
  • \$\begingroup\$ What happens when you remove one of the two includes? \$\endgroup\$
    – jippie
    Commented May 2, 2013 at 20:23
  • \$\begingroup\$ it works normally. Like the individuals are working perfectly but not together \$\endgroup\$
    – Aakash
    Commented May 2, 2013 at 20:41

1 Answer 1

3
\$\begingroup\$

On the compile problem

The problem is that both Servo.cpp and VirtualWire.cpp try to use the same interrupt vector. In the Servo.cpp source (line 103 as mentioned in the error you saw):

#if defined(_useTimer1)
SIGNAL (TIMER1_COMPA_vect)
{
  handle_interrupts(_timer1, &TCNT1, &OCR1A);
}
#endif

In VirtualWire.cpp lin 568, as mentioned in the error you saw:

// Assume Arduino Uno (328p or similar)    
SIGNAL(TIMER1_COMPA_vect)
#endif // __AVR_ATtiny85__    
{
    ... ISR code here ....

Arduino Uno has only a single 16-bit timer, and Servo.cpp library seems to want it. The problem is that VirtualWire library also wants to use the only 16-bit timer available. You could try rewriting one of the two libraries to use 8-bit timers, but you may lose features and functionality.

Using ServoTimer2

The ServoTimer2 library is meant to be a replacement for the servo library. This means you will need to download ServoTimer2 library, as it isn't a part of the standard Arduino distribution, put the ServoTimer2.h and ServoTimer2.cpp into ServoTimer2 directory in your Arduino libraries directory (for me the Arduino directory is /usr/share/arduino so, I put the servotimer2 files into /usr/share/arduino/libraries/ServoTimer2/), and then replace

#include "Servo.h"

with

#include "ServoTimer2.h"

In your sketch. The commands you use with ServoTimer2 library are supposed to be identical or similar to the commands used with the Servo library with one difference:

The usage and method naming is similar to the Arduino software servo library except that pulse widths are in microseconds not degrees.

So you should be able to keep most of your code. The only difference is that you'll declare your Servo object as ServoTimer2 instead of Servo or SoftwareServo.

\$\endgroup\$
2
  • \$\begingroup\$ In ServoTimer2 how do i give write command. Can i use servo.write(degree between 0 to 180) \$\endgroup\$
    – Aakash
    Commented May 2, 2013 at 21:13
  • \$\begingroup\$ Edited my answer, sorry. \$\endgroup\$ Commented May 2, 2013 at 23:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.