Go Down

Topic: Clash between Servo.h library and VirtualWire.h library (Read 134 times) previous topic - next topic

KarthickAshwath

I am making a project which controls a servo based on the data from the rf input.When I compile it (the program uses both the servo and virtual wire library) it shows the error:

Arduino: 1.6.4 (Windows 7), Board: "Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"

Servo\avr\Servo.cpp.o: In function `__vector_17':
F:\Program Files\Arduino\libraries\Servo\src\avr/Servo.cpp:81: multiple definition of `__vector_17'
VirtualWire\VirtualWire.cpp.o:C:\Users\Customer\Documents\Arduino\libraries\VirtualWire/VirtualWire.cpp:571: first defined here
f:/program files/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.8.1/../../../../avr/bin/ld.exe: Disabling relaxation: it will not work with multiple definitions
collect2.exe: error: ld returned 1 exit status
Error compiling.

  Without the virtual wire library included, it does not show any error.What could have happened?

Robin2

Try the ServoTimer2 library.

It is not unusual for Arduino libraries to fight with each other.

...R

KarthickAshwath

Are all the functions and commands same?I took that they are same for both the servo and servotimer2 library and got the following errors while compiling:



Arduino: 1.6.4 (Windows 7), Board: "Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"

In file included from rx.ino:3:0:
F:\Program Files\Arduino\libraries\ServoTimer2/ServoTimer2.h:41:17: error: conflicting declaration 'typedef uint8_t boolean'
 typedef uint8_t boolean;
                 ^
In file included from C:\Users\Customer\Documents\Arduino\libraries\VirtualWire/VirtualWire.h:146:0,
                 from rx.ino:1:
F:\Program Files\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:117:14: error: 'boolean' has a previous declaration as 'typedef bool boolean'
 typedef bool boolean;
              ^
rx:10: error: 'Servo' does not name a type
rx:11: error: 'Servo' does not name a type
rx:12: error: 'Servo' does not name a type
rx:13: error: 'Servo' does not name a type
rx.ino: In function 'void setup()':
rx:27: error: 'servo1' was not declared in this scope
rx:28: error: 'servo2' was not declared in this scope
rx:29: error: 'servo3' was not declared in this scope
rx:30: error: 'servo4' was not declared in this scope
rx.ino: In function 'void loop()':
rx:62: error: 'servo1' was not declared in this scope
rx:67: error: 'servo2' was not declared in this scope
rx:72: error: 'servo3' was not declared in this scope
rx:77: error: 'servo4' was not declared in this scope
'Servo' does not name a type

  This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.

KarthickAshwath

Here is the code that I used:


#include <VirtualWire.h>

#include <ServoTimer2.h>



char input = A0;
int motorpin1 = 13;
int motorpin2 = 12;
Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;
int x;
int reverse = 7;
int reverse2 = 6;




void setup() {
  // put your setup code here, to run once:
  pinMode(input,INPUT);
  pinMode(motorpin1,OUTPUT);
  pinMode(motorpin2,OUTPUT);
  pinMode(reverse,OUTPUT);
  servo1.attach(11);
  servo2.attach(10);
  servo3.attach(9);
  servo4.attach(8);
  pinMode(reverse2,OUTPUT);
  Serial.begin(9600);
 
 
}

void loop() {
  // put your main code here, to run repeatedly:
  int final = analogRead(input);
  if(final == 721)
  {
    digitalWrite(motorpin1,1);
    digitalWrite(motorpin2,1);
  }
  else if(final == 722)
  {
    digitalWrite(motorpin1,1);
    digitalWrite(reverse,1);
  }
  else if(final = 723)
  {
    digitalWrite(reverse2,1);
    digitalWrite(motorpin2,1);
  }
  else if(final = 724)
  {
    digitalWrite(reverse2,HIGH);
    digitalWrite(reverse,HIGH);
  }
  else if(final >= 0 && final <= 180)
  {
   servo1.write(final);
  }
   else if(final >= 181 && final <= 360)
  {
    x = map(final,181,360,0,180);
    servo2.write(final);
  }
   else if(final >= 361 && final <= 540)
  {
    x = map(final,361,540,0,180);
    servo3.write(x);
  }
   else if(final >= 541 && final <= 720)
  {
    x = map(final,541,720,0,180);
    servo4.write(x);
  }
 else{}
 


}

KarthickAshwath

If the libraries(servo and servo timer2) do not have the same functions,could you give me an example code?

JimboZA

There's an example folder in the library.

Looks to me as if these lines:

Code: [Select]
Servo servo1;
Servo servo2;
//etc


.... just need to become:

Code: [Select]
ServoTimer2 servo1;
ServoTimer2 servo2;
//etc


But I've never used it, so don't take my word for it without looking further.

Please use code tags: your code is so difficult to read... didn't you see the 8) in the middle that's supposed to be 8)?
Gone for good

KarthickAshwath

Sorry.I am a beginner.I do not know how the emoticon came there.I tried what you told me,but it did not work.No offence intended.

KarthickAshwath

Here is the error message that I get after doing what you told me.The number of error messages has decreased,but there is still one more.

Arduino: 1.6.4 (Windows 7), Board: "Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"

In file included from rx.ino:3:0:
F:\Program Files\Arduino\libraries\ServoTimer2/ServoTimer2.h:41:17: error: conflicting declaration 'typedef uint8_t boolean'
 typedef uint8_t boolean;
                 ^
In file included from C:\Users\Customer\Documents\Arduino\libraries\VirtualWire/VirtualWire.h:146:0,
                 from rx.ino:1:
F:\Program Files\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:117:14: error: 'boolean' has a previous declaration as 'typedef bool boolean'
 typedef bool boolean;
              ^
Error compiling.

  This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.

JimboZA

Did you look at the example in the library folder?

The emoticon comes from there being this line in the code:

Code: [Select]
servo4.attach(8);

.... and the browser takes the 8) to be the 8). So you should select your code and hit the </> icon above the  :)  to wrap it in [code][/code] tags so then your

Code: [Select]
code will
{
look
}
like this
Gone for good

Robin2

F:\Program Files\Arduino\libraries\ServoTimer2/ServoTimer2.h:41:17: error: conflicting declaration 'typedef uint8_t boolean'
 typedef uint8_t boolean;
                 ^
I think this problem is due to your use of Arduino IDE 1.6.4. Unfortunately the Arduino folks are not good at backwards compatibility. There is probably a fix, but I don't know what it is.

A simple solution is to use Arduino IDE 1.5.6 - you can easily have a few different versions of the IDE on your PC.

...R

Go Up