Servo and RF

Hello, I have a problem!! :confused:
I made a code that using an rf 433mhz can control an airplane.
So my problem is:
I made the code to print the values in the serial. The program worked perfectly until I tried to add a servo on the code. The code without the servo worked perfectly, but with servo, I got an error "error compiling for board arduino/genuino uno". I tried a lot of Arduinos but I still have the same problem. Pls help me.

The code with the servo that it didn't work:

#include <Servo.h>
#include <RH_ASK.h>
#include <SPI.h>

Servo myservo;

String str_x;
String str_y;
String str_out;

RH_ASK rf_driver;

void setup()
{
  myservo.attach(9);
  rf_driver.init();
  Serial.begin(9600);
}

void loop()
{
  uint8_t buf[7];
  uint8_t buflen = sizeof(buf);
  if (rf_driver.recv(buf, &buflen))
  {
    str_out = String((char*)buf);

    for (int i = 0; i < str_out.length(); i++) {
      if (str_out.substring(i, i + 1) == ",") {
        str_x = str_out.substring(0, i);
        str_y = str_out.substring(i + 1);
        break;
      }

    }

    Serial.print("X: ");
    Serial.print(str_x);
    Serial.print("    -    Y: ");
    Serial.println(str_y);
    myservo.write(str_x.toInt());
  }
}

The code without the servo that worked is the same code but without any command related with servo.

PS: the problem is in the receiver code

Thanks in advance ::slight_smile:

Please post the full error message

UKHeliBob:
Please post the full error message

That the full error message.
There is nothing more.

libraries/RadioHead/RH_ASK.cpp.o (symbol from plugin): In function `RH_ASK::maxMessageLength()':
(.text+0x0): multiple definition of `__vector_11'
libraries/Servo/avr/Servo.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/Genuino Uno.

That means the Servo library and the RadioHead library are both trying to use the same interrupt vector (I think that is Timer/Counter1 Overflow interrupt).

There is a preprocessor define "RH_ASK_ARDUINO_USE_TIMER2" which may allow you to switch the timer on RadioHead to not conflict with the Servo library. I think you have to define it in RH_ASK.h

johnwasser:
That means the Servo library and the RadioHead library are both trying to use the same interrupt vector (I think that is Timer/Counter1 Overflow interrupt).

There is a preprocessor define "RH_ASK_ARDUINO_USE_TIMER2" which may allow you to switch the timer on RadioHead to not conflict with the Servo library. I think you have to define it in RH_ASK.h

Thank you very much.
But do you know where can I find the solution for this program?

Petrouil:
Thank you very much.
But do you know where can I find the solution for this program?

Did you try the solution I mentioned?

johnwasser:
Did you try the solution I mentioned?

That's what I asked. How can I use your solution?
I mean, how can I use an other interrupt.
Sorry, if what I say, sounds bullshit but I don't know
neither Arduino nor English

Go to where you installed the RadioHead library. That should be a folder/directory inside the folder/directory named "libraries" inside the folder where all your sketches are stored.

Find the file named RH_ASK.h and open it in the text editor of your choice.

At the top of the file add the line:

#define RH_ASK_ARDUINO_USE_TIMER2

Save the edited file.

Try to compile your sketch again. You may have to close and re-open the Arduino IDE in order to force it to re-build the RadioHead library.

johnwasser:
Go to where you installed the RadioHead library. That should be a folder/directory inside the folder/directory named "libraries" inside the folder where all your sketches are stored.

Find the file named RH_ASK.h and open it in the text editor of your choice.

At the top of the file add the line:

#define RH_ASK_ARDUINO_USE_TIMER2

Save the edited file.

Try to compile your sketch again. You may have to close and re-open the Arduino IDE in order to force it to re-build the RadioHead library.

Thank you.
I can compile it now, but there is an other problem. When I connect the servo, it doesn't work. When the servo is unattached it works perfectly with the same code.

BTW. I don't want any more help because I just realize that those RFs can communicate only for 20 meters, and I was planning to attach them on an RC plane. So they are completely useless.
Thanks again for your help until now!!