Libraries and causing compiler problems

I'm writing a sketch that receives information via RFM96 and acts on it by turning a servo.
The pieces work independently but when I cooking them into the same sketch they don't compile.
Here are the included libraries:

#include <SPI.h>
#include <RH_RF69.h>
#include <RHReliableDatagram.h>

#include <Servo.h>

I can compile with either #include <RH_RF69.h> or #include <RH_RF69.h> commented out and I only get errors related to the lack of the relevant library. But when both are uncommented and I compile (verbose off) I get the following error message:


 Arduino: 1.8.19 (Linux), Board: "Arduino Nano, ATmega328P (Old Bootloader)"

libraries/Servo/avr/Servo.cpp.o (symbol from plugin): In function `ServoCount':
(.text+0x0): multiple definition of `__vector_11'
libraries/RadioHead_master/RH_ASK.cpp.o (symbol from plugin):(.text+0x0): first defined here
collect2: error: ld returned 1 exit status
exit status 1
Error compiling for board Arduino Nano.

This feels like I'm making a rookie mistake. Someone with actual compiler experience would look at it and say, "Oh you, you have to set option foo to value bar and you'll be good to go."

The libraries are relying on the same timer / interrupt vector.
You are on a Nano so not many timers to play with unfortunately, may be use the ServoTimer2 library and see if it resolves the conflict

Thanks for this. It seemed like the right answer but when I installed the library and ran some test code, it failed. I think I may not have installed the library right but the code compiles.

Using the Servo library, this runs as expected.
But, in the code below. if I comment out Servo and uncomment ServoTimer2, then it compiles and runs, using the delays and println statements.

Sidenote, when using the Servo library, the println statements are kind of dodgy, dropping characters or not printing at all. I assume this is somehow related to interrupt handling conflicts. As is abundantly obvious, I know almost nothing about working with interrupts.

Again, thanks for you help. Additional comments or possible solutions are above and beyond (but greatly appreciated :grinning:).

//#include <ServoTimer2.h>
#include <Servo.h>

//ServoTimer2 myservo;
Servo myservo;

void setup() {
  myservo.attach(9);
  Serial.begin(115200);
}

void loop() {
  Serial.println("start loop");
  myservo.write(45);
  delay(5000);
  Serial.println("45");
  myservo.write(135);
  Serial.println("135");
  delay(5000);
  myservo.write(0);
  Serial.println("end loop");
}

How did you install it?

I downloaded the library and example files from the code page of the git repository as a zip file. Then in the IDE I opened the library manager and installed from .zip using the file I just downloaded. Everything seemed to work -- library manager saw the library, the sketch compiled with the #include and uploaded to the nano. The code ran, including the Serial.println("foo") but the servo didn't move.

I've since found some code for driving the servo directly with digital writes and delays. It's sloppy but, if I can cook it into the rest of the code, it will get the job done.

Sure that works too it means you’ll have to ensure the loop spins quickly and nothing is blocking

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.