Multiple libraries sharing the same Interrupt [SOLVED]

I've just (unexpectedly) run into a last minute roadblock.

When adding some code which uses the Servo library I got compiler errors about "multiple definition of `__vector_17'".

It turns out that both the Servo.cpp and FatFS.cpp libraries use the same interrupt (TIMER1_COMPA_vect - this is a constant I guess?).

Could I safely try changing TIME1_COMPA_vect to TIMER0_COMPB_vect in one of the libraries?

Is there any other way this be worked around? Many people with similar problems just sacrifice one library or the other (it mostly seems to happen with trivial libraries) but in this case I can't sacrifice the SDCard functionality, nor the Servo functionality (nor have I managed to find an alternative Servo library so far).

Here : http://courses.cs.washington.edu/courses/csep567/10wi/lectures/Lecture7.pdf also states that TIMER1_COMPA_vect is actually interrupt vector 11. Why is the compiler talking about vector 17?

Hope somebody can help me :astonished:

Have you tried the ServoTimer2 library?

Thanks for the tip!!! I’ll try that out now :slight_smile:

Do you have a link to an Arduino 1.0+ compatible library? All the versions of ServoTimer2 I've found so far depend on WConstants.h, and changing this to Arduino.h just brings a whole jungle of further compilation errors :-/

All the versions of ServoTimer2 I've found so far depend on WConstants.h, and changing this to Arduino.h just brings a whole jungle of further compilation errors :-/

Show them, then. As far as I know, many other people have successfully used ServoTimer2.

As a mental note, and for others... here's another library : Arduino Playground - Servo

To get it to compile it is necessary to rewrite WProgram.h as Arduino.h in SoftwareServo.h, but other than that it appears to compile. Not tested with hardware yet.

ah, sorry. It took me a while to setup ServoTimer2 again... the compilation errors I was getting are :

In file included from /Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/Arduino.h:192,
                 from /Users/bensenior/Arduino/Src/libraries/ServoTimer2/ServoTimer2.cpp:6:
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/WString.h:116: error: declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, const char*)' conflicts with
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/WString.h:115: error: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, const String&)' here
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/WString.h:117: error: declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, char)' conflicts with
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/WString.h:116: error: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, const char*)' here
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/WString.h:118: error: declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, unsigned char)' conflicts with
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/WString.h:117: error: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, char)' here
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/WString.h:119: error: declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, int)' conflicts with
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/WString.h:118: error: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, unsigned char)' here
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/WString.h:120: error: declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, unsigned int)' conflicts with
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/WString.h:119: error: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, int)' here
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/WString.h:121: error: declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, long int)' conflicts with
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/WString.h:120: error: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, unsigned int)' here
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/WString.h:122: error: declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, long unsigned int)' conflicts with
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/WString.h:121: error: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, long int)' here
In file included from /Users/bensenior/WORK/CUSTOMERS/Sefol/PassiveDry/Src/libraries/ServoTimer2/ServoTimer2.cpp:6:
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/Arduino.h:196: error: declaration of C function 'uint16_t makeWord(byte, byte)' conflicts with
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/Arduino.h:195: error: previous declaration 'uint16_t makeWord(uint16_t)' here
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/Arduino.h:206: error: declaration of C function 'long int random(long int)' conflicts with
/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/include/stdlib.h:504: error: previous declaration 'long int random()' here
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/Arduino.h:207: error: declaration of C function 'long int random(long int, long int)' conflicts with
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/Arduino.h:206: error: previous declaration 'long int random(long int)' here

Did you leave the #include of Arduino.h in the extern C block? Arduino.h is not a C library.

You're a star Paul, I somehow didn't see that! Thanks :slight_smile:

Hi,

I am trying to use the Servo.h library, but I am also getting the “Vector_17” error upon compiling.

I read bensenior’s and PaulS’ posts. However, I am having trouble making the ServoTimer2 library work.

Could someone post a more “step-by-step”-like explanation about how I can do this, as I am very new to Arduino?

This is the list of errors I get when using Servo.h:

Arduino: 1.6.5 (Windows 7), Board: "Arduino Robot Control"

Servo\avr\Servo.cpp.o: In function `__vector_17':
C:\Program Files (x86)\Arduino\libraries\Servo\src\avr/Servo.cpp:81: multiple definition of `__vector_17'
Robot Control\Melody.cpp.o:C:\Program Files (x86)\Arduino\libraries\Robot_Control\src/Melody.cpp:7: first defined here
collect2.exe: error: ld returned 1 exit status
Error compiling.

  This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.

And this is the list of errors I get when I include ServoTimer2.h:

Arduino: 1.6.5 (Windows 7), Board: "Arduino Robot Control"

In file included from exponent.ino:30:0:
C:\Program Files (x86)\Arduino\libraries\ServoTimer2/ServoTimer2.h:41:17: error: conflicting declaration 'typedef uint8_t boolean'
 typedef uint8_t boolean;
                 ^
In file included from C:\Program Files (x86)\Arduino\libraries\Robot_Control\src/Arduino_LCD.h:23:0,
                 from C:\Program Files (x86)\Arduino\libraries\Robot_Control\src/ArduinoRobot.h:4,
                 from exponent.ino:25:
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:117:14: error: 'boolean' has a previous declaration as 'typedef bool boolean'
 typedef bool boolean;
              ^
Error compiling.

  This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.

If needed, my original code is:

#include <ArduinoRobot.h>
#include <Wire.h>
#include <SPI.h>
#include <Servo.h>

Servo myservo;

void setup() {
  // initialize the robot
  Robot.begin();
  Robot.beginTFT();

  myservo.attach(D2);
  // open the serial port to send the information of what you are reading
  Serial.begin(9600);  
}


void loop()
{

  int potent, scaledpos;

  potent = map(Robot.knobRead(), 0, 1023, -255, 255);
  scaledpos = (179.0/255.0)*(1.0*potent + 255.0) / 2.0;

  myservo.write(scaledpos);

}

Appreciate the help!

Zouje.