Problem occur when I combine two libraries in Arduino

Hello
I want to ask your help with problem that occur in the code for the first time,

“libraries\PCM\PCM.c.o (symbol from plugin): In function startPlayback': (.text+0x0): multiple definition of __vector_11’
libraries\Servo\avr\Servo.cpp.o (symbol from plugin):(.text+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
exit status 1
Error compiling for board Arduino Uno.”

This the code

#include <Servo.h>
#include 
#include <PCM.h>
#include 
 Servo Myservo;
const int trigPin = 8;
const int echoPin = 7;
 int pos=0;


 const unsigned char sample[] PROGMEM = {
126, 126, 126, 126, 127, 127, 127, 127,  };
**strong text**
void setup()
{
pinMode(trigPin, OUTPUT); 
pinMode(echoPin, INPUT); 
 Myservo.attach(4);
  startPlayback(sample, sizeof(sample));
}

void loop()
{

  int duration, distance;

digitalWrite(trigPin, HIGH);
delay(1);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
if (distance <= 5 && distance >= 0) {
startPlayback(sample, sizeof(sample));
} 
    Myservo.write(180);
}

I will be very happy if someone show me where are the problem but I read a lot but I could not understand.

I suspect both libraries are trying to use the same interrupt handler. Vector 11 though, is the Timer 1 Input Capture vector, according to the Uno’s data sheet, which seems an unusual choice.

However, the data sheet counts from 1, not zero. If the compiler counts from zero, then it’s the Timer 1 Compare Match A interrupt – which makes more sense.

Basically, these two libraries can’t be used together.

HTH

Cheers,
Norm.

2 Likes

Correct. Both your PWM based sample playback and your servo motor use the same timer to operate and want to hook the same interrupt function --they’re incompatible.

1 Like

Thank you so much Norman, I could now give up

Thank you so much Max for the explanation

Maybe it’s possible to amend one of the libraries to use the Timer 1 Compare Match B interrupt. That way there wouldn’t be a clash.

Which two libraries are you using?

Cheers,
Norm.

I used
#include <Servo.h> for the motor
#include <PCM.h> for the audio

but really thank you so much I used alternative solution (I used two Arduinos one for the motors)

1 Like

hello sir. I also have the same problem: I want to connect my servo+ waterlevel sensor (connect to firebase) code to my webcamserver code. it seems that both codes got config declaration in them which I think is the problem on why i cannot run it simultaneously.

image

pic showing the “config” I’m talking abt. Is there any other way?

Did you forget to attach the pic showing the config?

What errors are you getting?

Bear in mind I don’t use firebase, so I might not be able to help, but I’ll do my best.

Cheers,
Norm.

I got no error. but some of my function didnt work, i think because of the config declaration. May i know what is it actually

image

here is the second code containing “config”. (i can only upload 1 pic)

Do you know that you can copy code, then paste it here, as often as you wish. Plus it’s easier to read – most of the time – than an image?

Simply type three backticks, not single quotes, paste your code in, then another three backticks. Like this:

```
Here is my code ...
And here...
```

Much easier than grabbing screens etc.

What evidence leads you to this conclusion? Can you paste your code here, as detailed above, and also the platformio.ini file too. Thanks.

Cheers,
Norm.

Not yet, There is a solution for your problem by switching lib from using “Servo.h” To “PWMServo.h”.|

All you need to do is install pwmservo and #include <PWMServo.h> instead off #include <Servo.h> while keeping all your code as it is and this will solve your problem,
Happy crafting mate.