# Servo and RF

**URL:** <https://forum.arduino.cc/t/servo-and-rf/603432>\
**Category:** Programming\
**Created:** [July 25, 2019, 9:07pm UTC](https://forum.arduino.cc/t/servo-and-rf/603432 "2019-07-25T21:07:03Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Petrouil](https://avatars.discourse-cdn.com/v4/letter/p/3da27b/32.png) [@Petrouil](https://forum.arduino.cc/u/Petrouil)\
**Post date:** [July 25, 2019, 9:07pm UTC](https://forum.arduino.cc/t/servo-and-rf/603432/1 "2019-07-25T21:07:03Z")

</div>

Hello, I have a problem!! 😕  
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:

```cpp
#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 :🙂

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [July 25, 2019, 9:17pm UTC](https://forum.arduino.cc/t/servo-and-rf/603432/2 "2019-07-25T21:17:10Z")

</div>

Please post the full error message

---

<div class="post-metadata">

**Author:** ![Petrouil](https://avatars.discourse-cdn.com/v4/letter/p/3da27b/32.png) [@Petrouil](https://forum.arduino.cc/u/Petrouil)\
**Post date:** [July 25, 2019, 9:54pm UTC](https://forum.arduino.cc/t/servo-and-rf/603432/3 "2019-07-25T21:54:56Z")

</div>

> UKHeliBob:  
> Please post the full error message

That the full error message.  
There is nothing more.

---

<div class="post-metadata">

**Author:** ![johnwasser](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/johnwasser/32/214270_2.png) [@johnwasser](https://forum.arduino.cc/u/johnwasser)\
**Post date:** [July 26, 2019, 2:04am UTC](https://forum.arduino.cc/t/servo-and-rf/603432/4 "2019-07-26T02:04:49Z")

</div>

```cpp
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

---

<div class="post-metadata">

**Author:** ![Petrouil](https://avatars.discourse-cdn.com/v4/letter/p/3da27b/32.png) [@Petrouil](https://forum.arduino.cc/u/Petrouil)\
**Post date:** [July 26, 2019, 6:43am UTC](https://forum.arduino.cc/t/servo-and-rf/603432/5 "2019-07-26T06:43:17Z")

</div>

> 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?

---

<div class="post-metadata">

**Author:** ![johnwasser](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/johnwasser/32/214270_2.png) [@johnwasser](https://forum.arduino.cc/u/johnwasser)\
**Post date:** [July 26, 2019, 1:17pm UTC](https://forum.arduino.cc/t/servo-and-rf/603432/6 "2019-07-26T13:17:39Z")

</div>

> 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?

---

<div class="post-metadata">

**Author:** ![Petrouil](https://avatars.discourse-cdn.com/v4/letter/p/3da27b/32.png) [@Petrouil](https://forum.arduino.cc/u/Petrouil)\
**Post date:** [July 27, 2019, 12:44pm UTC](https://forum.arduino.cc/t/servo-and-rf/603432/7 "2019-07-27T12:44:25Z")

</div>

> 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

---

<div class="post-metadata">

**Author:** ![johnwasser](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/johnwasser/32/214270_2.png) [@johnwasser](https://forum.arduino.cc/u/johnwasser)\
**Post date:** [July 27, 2019, 4:32pm UTC](https://forum.arduino.cc/t/servo-and-rf/603432/8 "2019-07-27T16:32:22Z")

</div>

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:

```cpp
#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.

---

<div class="post-metadata">

**Author:** ![Petrouil](https://avatars.discourse-cdn.com/v4/letter/p/3da27b/32.png) [@Petrouil](https://forum.arduino.cc/u/Petrouil)\
**Post date:** [July 28, 2019, 9:46am UTC](https://forum.arduino.cc/t/servo-and-rf/603432/9 "2019-07-28T09:46:11Z")

</div>

> 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:
> 
> ```arduino
> #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!!

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 5, 2021, 11:57pm UTC](https://forum.arduino.cc/t/servo-and-rf/603432/10 "2021-05-05T23:57:02Z")

</div>

Closed on May 5, 2021, 11:57pm UTC


