1
votes

I am working on an Arduino Mega 2560 project involving infrared signal processing and controlling servos. But the following simple sketch produces an error, saying that some field is multiple times defined.

Libraries involved: Servo and IRremote.

Code for reproducing the error:

#include <Servo.h>
#include <IRremote.h>

void setup() { }

void loop() { }

Error description:

libraries\IRremote\IRremote.cpp.o (symbol from plugin): In function `MATCH(int, int)':

(.text+0x0): multiple definition of `__vector_32'

libraries\Servo\avr\Servo.cpp.o (symbol from plugin):(.text+0x0): first defined here

c:/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.9.2/../../../../avr/bin/ld.exe: Disabling relaxation: it will not work with multiple definitions

collect2.exe: error: ld returned 1 exit status

exit status 1
Error compiling for board Arduino/Genuino Mega or Mega 2560.

How do I solve this issue?

UPDATE/SOLUTION:

The servo library has the following definition in ServoTimers.h:

typedef enum { _timer5, _timer1, _timer3, _timer4, _Nbr_16timers } timer16_Sequence_t;

Basically, the first 12 servos are controlled by timer 5. If you need more servos, timer 1 is also consulted for servo 13-24, etc. Up to 48 servos can be controlled by the standard servo library on a Arduino Mega 2560 (12 per timer).

The IRremote library uses timer 2 for receiving IR signals. This basically does not conflict with the Servo library. But I already altered the IRremoteInt.h to use timer 3 instead of timer 2, since I also use ultrasonic sensors which are interrupt driven (on timer 2). That's the reason why I ran into the issue described above.

Since I am not using more than 12 servos for my project, I simply disabled the timers 1, 3, 4 in the Servo library, resulting in the following line (cp. to the original line above):

typedef enum { _timer5, _Nbr_16timers } timer16_Sequence_t;

This results in some more errors, since the enum is not complete anymore... If you want do the same, just comment out the lines of code that pop up as error when you try to compile the sketch. Then re-compile and everything should be fine.

Now everything working fine, ultrasonic sensors, servos and IR reception. Thanks.

1

1 Answers

2
votes

Servo.h and IRremote.h are both trying to use Timer1. They can't both have it, hence the error. You could try the ServoTimer2 library to run the servos off timer 2 but be sure you read the documentation for it as it doesn't work exactly like Servo.