MegaServo + WAVHC Lib Conflict (WAV Shield and Servo working together)

My problem:
I need the use the Adafruit WAV shield and a servo at the same time, but the WAVHC library cannot be used with the standard Servo library because they both use Timer1.

I’ve read a lot of posts about people using ServoTimer2 with the WAVHC libarary, but I can’t get any of the ServoTimer2 examples to compile at all under Arduino 1.0 with all the usual library patches. This library seems to have a lot of conflicts with Arduino.h.

I read that the MegaServo library uses different timers so I was hoping it would be a work around.
http://arduino.cc/playground/Code/MegaServo

I’m getting an compiler error when I have a sketch that includes but the MegaServo library and WAVHC library.

“MegaServo/MegaServo.cpp.o: In function __vector_17': /Users/smjohn/Documents/Arduino/libraries/MegaServo/MegaServo.cpp:120: multiple definition of __vector_17’
WaveHC/WaveHC.cpp.o:/Users/smjohn/Documents/Arduino/libraries/WaveHC/WaveHC.cpp:41: first defined here”

I’m using an Arduino Mega, with servo on pin 9.

Using the MegaServo lib alone works fine.

#include <MegaServo.h>
 
MegaServo myservo;  // create servo object to control a servo 
                // a maximum of eight servo objects can be created 
 
int pos = 50;    // variable to store the servo position 
 
void setup() 
{ 
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object 
} 
 
void loop() 
{ 
  for(pos = 50; pos < 110; pos += 1)  // goes from 0 degrees to 180 degrees 
  {                                  // in steps of 1 degree 
    myservo.write(pos);              // tell servo to go to position in variable 'pos' 
    delay(15);                       // waits 15ms for the servo to reach the position 
  } 
  for(pos = 110; pos>=60; pos-=1)     // goes from 180 degrees to 0 degrees 
  {                                
    myservo.write(pos);              // tell servo to go to position in variable 'pos' 
    delay(15);                       // waits 15ms for the servo to reach the position 
  } 
  
   Serial.println(pos);
}

Anyone have any suggestions on how to resolve this conflict? It is a timer conflict? If yes, is there another way to get a servo to work with this WAV shield? I’ve tried writing to the servo pins directly (digitalWrite(servoPin, HIGH)), which allows me to use the WAVHC library at the same time. I would rather use an existing library to have more control over the servo. Is there a way to hack the standard servo library to not use Timer1?

Hi

I don't now about the MegaServo Library but it seems that it is used in the actual IDE as Servo library.
In that case the timer used by the library depends of the Servo index

in Servo::attach(...) function

  timer16_Sequence_t timer = SERVO_INDEX_TO_TIMER(servoIndex);

with in global definitions

#define SERVO_INDEX_TO_TIMER(_servo_nbr) ((timer16_Sequence_t)(_servo_nbr / SERVOS_PER_TIMER)) // returns the timer controlling this servo

and in Servo.h

#define SERVOS_PER_TIMER       12     // the maximum number of servos controlled by one timer

and finally, choice is done regarding the board

// Say which 16 bit timers can be used and in what order
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
#define _useTimer5
#define _useTimer1 
#define _useTimer3
#define _useTimer4 
typedef enum { _timer5, _timer1, _timer3, _timer4, _Nbr_16timers } timer16_Sequence_t ;

#elif defined(__AVR_ATmega32U4__)  
#define _useTimer3
#define _useTimer1 
typedef enum { _timer3, _timer1, _Nbr_16timers } timer16_Sequence_t ;

#elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
#define _useTimer3
#define _useTimer1
typedef enum { _timer3, _timer1, _Nbr_16timers } timer16_Sequence_t ;

#elif defined(__AVR_ATmega128__) ||defined(__AVR_ATmega1281__)||defined(__AVR_ATmega2561__)
#define _useTimer3
#define _useTimer1
typedef enum { _timer3, _timer1, _Nbr_16timers } timer16_Sequence_t ;

#else  // everything else
#define _useTimer1
typedef enum { _timer1, _Nbr_16timers } timer16_Sequence_t ;                  
#endif

Normally with Arduino Mega (1280 or 2560), timer used for servo 1 to 11 should be Timer5

So if I’m using the Servo library and using pin 9 on my Mega like in my sketch above:

myservo.attach(9);

Then the timer being used should be 5 not 1?

Basically any pins from 1-11 used for servos should be using timer 5 on the Arduino Mega?

I’ve tried using pin 9 with the Servo library together with the WAVHC library and get this compiler conflict.

This is the error:

“Servo/Servo.cpp.o: In function __vector_17': /Applications/Arduino.app/Contents/Resources/Java/libraries/Servo/Servo.cpp:103: multiple definition of __vector_17’
WaveHC/WaveHC.cpp.o:/Users/smjohn/Documents/Arduino/libraries/WaveHC/WaveHC.cpp:41: first defined here”

So far it seems the only route to get a servo working with the WAV shield is ServoTimer2.