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
Wave Shield and Servo won't work together
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
-
- Posts: 12151
- Joined: Thu Apr 06, 2006 4:21 pm
Re: Wave Shield and Servo won't work together
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
also
see the Code button? use it
-
- Posts: 2
- Joined: Mon Nov 02, 2009 6:24 pm
Re: Wave Shield and Servo won't work together
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
I can drive the servo no problem using the examples that come with the IDE
tks again
Noel
-
- Posts: 12151
- Joined: Thu Apr 06, 2006 4:21 pm
Re: Wave Shield and Servo won't work together
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.
-
- Posts: 1
- Joined: Fri Mar 05, 2010 1:00 pm
- kasm
- Posts: 6
- Joined: Mon Mar 25, 2013 11:30 am
Re: Wave Shield and Servo won't work together
Has anyone found a servo software library that is for Arduino 1.0 + or what changes need to be made to this library?
Thanks!
Thanks!
- bratan
- Posts: 49
- Joined: Sun Mar 25, 2012 2:08 pm
Re: Wave Shield and Servo won't work together
I know this is really old topic, but you can easily get SoftwareServer library working again by changing one line in SoftwareServo.h:
Replace:
with
I can confirm that it works with Wave Sheild! :)
Replace:
Code: Select all
#include <WProgram.h>
Code: Select all
#include <Arduino.h>
- adafruit_support_bill
- Posts: 88093
- Joined: Sat Feb 07, 2009 10:11 am
Re: Wave Shield and Servo won't work together
Good to know. Thanks for posting your findings.
- bratan
- Posts: 49
- Joined: Sun Mar 25, 2012 2:08 pm
Re: Wave Shield and Servo won't work together
One more thing. While SoftwareServo library works, after playing with it, I can't say that I like it at all. It requires you to manually refresh servos at least ones every 50ms, which can be a pain, and produces some weird results...
I figured out a way to "hack" original Servo library by changing some definitions to use Timer2 instead of Timer1.
Catch is I'm using ATmega1284p chip, so it might be different for 328p, but I think you can just replace _userTimer1 to _useTimer2 under "everything else" part at the end of the file.
Here's section I modified (commented out old values)
Oh and if you are having trouble finding Servo library (it's not in MyDocuments/Arduino/libraries), it's installed in your Arduino installation folder in libraries/Servo/src/avr
I figured out a way to "hack" original Servo library by changing some definitions to use Timer2 instead of Timer1.
Catch is I'm using ATmega1284p chip, so it might be different for 328p, but I think you can just replace _userTimer1 to _useTimer2 under "everything else" part at the end of the file.
Here's section I modified (commented out old values)
Code: Select all
#elif defined(__AVR_ATmega128__) || defined(__AVR_ATmega1281__) || defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega2561__)
#define _useTimer3
#define _useTimer2
//#define _useTimer1
//typedef enum { _timer3, _timer1, _Nbr_16timers } timer16_Sequence_t;
typedef enum { _timer3, _timer2, _Nbr_16timers } timer16_Sequence_t;
- bratan
- Posts: 49
- Joined: Sun Mar 25, 2012 2:08 pm
Re: Wave Shield and Servo won't work together
And here's result :)
https://www.youtube.com/watch?v=X6fTkxecwjI
https://www.youtube.com/watch?v=X6fTkxecwjI
- adafruit_support_bill
- Posts: 88093
- Joined: Sat Feb 07, 2009 10:11 am
Re: Wave Shield and Servo won't work together
Thanks. There used to be a ServoTimer2 library, but it wasn't maintained &hasn't worked since IDE 1.0.
Please be positive and constructive with your questions and comments.