Virtual Wire don't work with Servo Library.

Hi, thank you for those of you who answered me earlier. Now, I want to know how to make Servo library work with VirtualWire, or RadioHead Library without needs of processors. Thank You

---Older Messages---

Hi,

I think everything works fine but it said error compiling, could you please help me solve this? Thank You!

#include <VirtualWire.h>

//declaration of integers
int valUp = 0;
int valForward = 0;
int valSide = 0;
int valGForward =0;
int valGSide = 0;
int valWL=0;
int valWR=0;
int WL =8;
int WR=7;
int sideServo = 12;
int upServo = 11;
int downServo = 10;
int forwardServo =9;

#include <Servo.h>

Servo Side, Up, Down, Forward;

void setup() {
  // put your setup code here, to run once:
vw_setup(2000);
vw_set_rx_pin(1);
vw_rx_start();

Serial.begin(9600);
Side.attach(sideServo);
Up.attach(upServo);
Down.attach(downServo);
Forward.attach(forwardServo);
pinMode(WL, OUTPUT);
pinMode(WR,INPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
uint8_t buflen = VW_MAX_MESSAGE_LEN;
uint8_t buf[buflen];

vw_wait_rx();
vw_get_message(buf, &buflen);

if (buf[1] == '

Servo/avr/Servo.cpp.o: In function __vector_17': /Applications/Arduino.app/Contents/Java/libraries/Servo/src/avr/Servo.cpp:81: multiple definition of __vector_17'
VirtualWire/VirtualWire.cpp.o:/Users/Suphanat/Documents/Arduino/libraries/VirtualWire/VirtualWire.cpp:591: first defined here
/Applications/Arduino.app/Contents/Java/hardware/tools/avr/bin/../lib/gcc/avr/4.8.1/../../../../avr/bin/ld: Disabling relaxation: it will not work with multiple definitions
collect2: error: ld returned 1 exit status
Error compiling.
[/code]);
{
vw_wait_rx();
vw_get_message(buf, &buflen);
int valUp = map (buf[1], 0, 9, 60, 180);
vw_wait_rx();
vw_get_message(buf, &buflen);
int valForward = map (buf[1], 0, 9, 60, 180);
vw_wait_rx();
vw_get_message(buf, &buflen);
int valSide = map (buf[1], 0, 9, 60, 180);
vw_wait_rx();
vw_get_message(buf, &buflen);
int valGForward = map (buf[1], 0, 9, 60, 180);
vw_wait_rx();
vw_get_message(buf, &buflen);
int valGSide = buf[1];
int valWL=0;
int valWR=0;

if (valGSide == 5)
{
 valWL= 9;
 valWR= 9;
}
else if (valGSide <5)
{
 valWR =9;
 valWL = 9-(valGSide2);
}
else if (valGSide >5)
{
 valWL =9;
 valWR = 9-(valGSide
2);
}
else
{
 valWL = 0;
 valWR = 0;
}
 
valWL = map (valWL,0,9,0,255);
valWR = map (valWR,0,9,0,255);

Side.write(valSide);
Up.write(valUp);
Down.write(valUp);
Forward.write(valForward);
digitalWrite(WL, valWL);
digitalWrite(WR, valWR);

}
}


Servo/avr/Servo.cpp.o: In function `__vector_17':
/Applications/Arduino.app/Contents/Java/libraries/Servo/src/avr/Servo.cpp:81: multiple definition of `__vector_17'
VirtualWire/VirtualWire.cpp.o:/Users/Suphanat/Documents/Arduino/libraries/VirtualWire/VirtualWire.cpp:591: first defined here
/Applications/Arduino.app/Contents/Java/hardware/tools/avr/bin/../lib/gcc/avr/4.8.1/../../../../avr/bin/ld: Disabling relaxation: it will not work with multiple definitions
collect2: error: ld returned 1 exit status
Error compiling.
[/code]

Your problem is a clash between the "Servo" library and the "VirtualWire" library.

I'm not sure how you would make both libraries work together. You might need to use a different library for either the servo or the communications.
Perhaps you could use the "Radiohead" library instead of "VirtualWire", if you're doing RF communications.

Even this generates the same error, with no other code:-

// Libraries:-
#include <Servo.h>
#include <VirtualWire.h>
void setup(){}
void loop(){}

RadioHead and VirtualWire use a periodic interrupt to sample the data stream. Any other interrupts disrupt the timing. If those interrupts are rare, or interleaved with the radio interrupts (i.e. not called while the radio is receiving), you can get away with it. I'm sometimes using a dedicated processor for radio, for this reason.

Issue is that both libraries try to use the same hardware timer.

One library would have to be modified to use a different timer. I think I've seen a servo library that used timer 2 instead of timer 1?

Do not start multiple threads about the same topic. Instead, reply to the first thread you created.

DrAzzy:
Issue is that both libraries try to use the same hardware timer.

It might be. But even when different timers are used, there are ISR's that depend on there being no other interrupts that delay the execution. Radio and IR use timers to set up sampling times, so they fall into that category. If another interrupt is in progress when the timer expires, the handler will be late, and so the read of the data stream will be late. The timing is disrupted, so it can not read a packet. Yes, even with different timers. I suppose servo is the same, but I haven't tested it. It would make sense.

aarg:
RadioHead and VirtualWire use a periodic interrupt to sample the data stream. Any other interrupts disrupt the timing. If those interrupts are rare, or interleaved with the radio interrupts (i.e. not called while the radio is receiving), you can get away with it. I'm sometimes using a dedicated processor for radio, for this reason.

Thanks for clarifying that aarg. I suggested Radiohead as a possible alternative, bit didn't know for sure if it would actually work.

@Suphanat_Is, you shouldn't go back and edit your original post with information gained in later replies. It's very confusing.
There was no mention of "Radiohead" in your original post when I replied. If you gain new information, or have additional questions, always add them in a reply, to avoid confusion.