Wave Shield and Servo won't work together
Moderators: adafruit_support_bill, adafruit

Wave Shield and Servo won't work together

by ndillane on Mon Nov 02, 2009 5:26 pm

I have been playing around with adafruits wave shield and have it working and playing wav files no problem. However I am trying to drive a servo at the same time but when I include servo.h in my sketch I get this compile error


/var/folders/rW/rWvoTHZWF+iF1HuGiixILU+++TI/-Tmp-/build5300156778023286889.tmp/S
ervo/Servo.cpp.o: In function `__vector_11':

/Applications/Arduino.app/Contents/Resources/Java/hardware/libraries/Servo/Servo
.cpp:104: multiple definition of `__vector_11'

/var/folders/rW/rWvoTHZWF+iF1HuGiixILU+++TI/-Tmp-/build5300156778023286889.tmp/A
F_Wave/wave.cpp.o:/Applications/Arduino.app/Contents/Resources/Java/hardware/lib
raries/AF_Wave/wave.cpp:33: first defined here


MY CODE IS BELOW
#include <AF_Wave.h>
#include <avr/pgmspace.h>
#include <Servo.h> //If I comment this out error goes away
#include "util.h"
#include "wave.h"

AF_Wave card;
File f;
Wavefile wave; // only one!

#define redled 9
int relayPin = 6; // Relay connected to digital pin 6
uint16_t samplerate;

void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("Wave test!");
// initialize the digital pin as an output:
pinMode(relayPin, OUTPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(redled, OUTPUT);

if (!card.init_card()) {
putstring_nl("Card init. failed!"); return;
}
if (!card.open_partition()) {
putstring_nl("No partition!"); return;
}
if (!card.open_filesys()) {
putstring_nl("Couldn't open filesys"); return;
}

if (!card.open_rootdir()) {
putstring_nl("Couldn't open dir"); return;
}

putstring_nl("Files found:");
ls();
}

void ls() {
char name[13];
int ret;

card.reset_dir();
putstring_nl("Files found:");
while (1) {
ret = card.get_next_name_in_dir(name);
if (!ret) {
card.reset_dir();
return;
}
Serial.println(name);
}
}

uint8_t tracknum = 0;

void loop() {
uint8_t i, r;
char c, name[15];


card.reset_dir();
// scroll through the files in the directory
for (i=0; i<tracknum+1; i++) {
r = card.get_next_name_in_dir(name);
if (!r) {
// ran out of tracks! start over
tracknum = 0;
return;
}
}
putstring("\n\rPlaying "); Serial.print(name);
// reset the directory so we can find the file
card.reset_dir();
playcomplete(name);
tracknum++;
}

void playcomplete(char *name) {
uint16_t potval;
uint32_t newsamplerate;

playfile(name);
samplerate = wave.dwSamplesPerSec;
while (wave.isplaying) {
// you can do stuff here!

// my relay code start
// digitalWrite(relayPin, HIGH); // set the LED on
// delay(500); // wait for a second
// digitalWrite(relayPin, LOW); // set the LED off
// delay(500); // wait for a second
// my relay code end

delay(500);
}
card.close_file(f);
}

void playfile(char *name) {
f = card.open_file(name);
if (!f) {
putstring_nl(" Couldn't open file"); return;
}
if (!wave.create(f)) {
putstring_nl(" Not a valid WAV"); return;
}
// ok time to play!
wave.play();
}


I am a bit of a newbie I'm afraid but will welcome advice

thank you for your time
Noel
ndillane
 
Posts: 2
Joined: Mon Nov 02, 2009 5:24 pm

Re: Wave Shield and Servo won't work together

by adafruit on Mon Nov 02, 2009 5:50 pm

sounds like theres a timer conflict. youll want to use a software servo library, there is at least one out ther

also

see the Code button? use it
User avatar
adafruit
 
Posts: 11669
Joined: Thu Apr 06, 2006 3:21 pm
Location: nyc

Re: Wave Shield and Servo won't work together

by ndillane on Fri Nov 06, 2009 5:44 pm

I don't really understand your response - What do you mean use a servo software library ? Am n't I already doing that by using #include <Servo.h>

I can drive the servo no problem using the examples that come with the IDE

tks again
Noel
ndillane
 
Posts: 2
Joined: Mon Nov 02, 2009 5:24 pm

Re: Wave Shield and Servo won't work together

by adafruit on Fri Nov 06, 2009 5:48 pm

the servo library is trying to use timer 1 which the waveshield needs. you will have to find a servo library that does not use timer 1. we dont know where that is, perhaps someone else does or you can spend time searching online. someone has likely written one.
User avatar
adafruit
 
Posts: 11669
Joined: Thu Apr 06, 2006 3:21 pm
Location: nyc

Re: Wave Shield and Servo won't work together

by tarikbrie on Fri Mar 05, 2010 12:08 pm

This Servo library should solve the problem:

http://www.arduino.cc/playground/ComponentLib/Servo
tarikbrie
 
Posts: 1
Joined: Fri Mar 05, 2010 12:00 pm

Re: Wave Shield and Servo won't work together

by kasm on Sun May 05, 2013 2:53 pm

Has anyone found a servo software library that is for Arduino 1.0 + or what changes need to be made to this library?
Thanks!
kasm
 
Posts: 6
Joined: Mon Mar 25, 2013 10:30 am