Moving a servo with Arduino Duemilanove Board and adafruit w
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- tls5606
- Posts: 12
- Joined: Mon Oct 05, 2015 2:43 pm
Moving a servo with Arduino Duemilanove Board and adafruit w
I am brand brand new to micro controllers and shields, so please bare with me. I am trying to add to my haloween display using a Arduino Duemilanove Board and adafruit wave shield ver 1.1. I am trying to move a servo connected to a skjull jaw using the wave shield. I have seen one post online on how to wire this and the code. However the schematic he gave is very poorly drawn and hard to understand, with haloween so close i am hoping that someone here can help me out.
- adafruit_support_bill
- Posts: 88151
- Joined: Sat Feb 07, 2009 10:11 am
Re: Moving a servo with Arduino Duemilanove Board and adafru
The Arduino servo library and the wave shield libraries don't work together since they both use the same timer.
You can use the servo shield to drive the servos. It has no conflicts with the wave shield libraries.
https://www.adafruit.com/product/1411
You can use the servo shield to drive the servos. It has no conflicts with the wave shield libraries.
https://www.adafruit.com/product/1411
- tls5606
- Posts: 12
- Joined: Mon Oct 05, 2015 2:43 pm
Re: Moving a servo with Arduino Duemilanove Board and adafru
Here is the code i found online from a gentleman who made his work? i am missing something? all he used was the duemilanove and wave shield
Code: Select all
#include
#include
#include "util.h"
#include "wave.h"
#define DEBOUNCE 100
#define swPin 14
#define eyeleds 18
AF_Wave card;
File f;
Wavefile wave;
int inputPin = 8; // choose the input pin (for PIR sensor)
int servoPin = 16; // choose the input pin (for Servo)
int pirState = LOW; // we start, assuming no motion detected
int val = 0; // variable for reading the pin status for motion sensor
int minPulse = 600; // minimum servo position
int maxPulse = 2200; // maximum servo position
int BANNED = 1800; // servo turn rate increment (larger value, faster rate)
int refreshTime = 20; // time (ms) between pulses (50Hz)
int mouthchange = 6; //checks to see if mouth position needs to be changed
int randNumber; //random number variable to allow the choosing of which wav will be played
/** The Arduino will calculate these values for you **/
int centerServo; // center servo position
int pulseWidth; // servo pulse width
long lastPulse = 0; // recorded time (ms) of the last pulse
void setup() {
// set up serial port
Serial.begin(9600);
pinMode(inputPin, INPUT); // declare sensor as input for PIR
pinMode(eyeleds, OUTPUT); // declare sensor as output for eyes
// set up servo pin
pinMode(servoPin, OUTPUT); // Set servo pin 18 (analog 4) as an output pin
centerServo = maxPulse - ((maxPulse - minPulse)/2);
pulseWidth = centerServo; // Give the servo a starting point (or it floats)
// set up waveshield pins
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
// open memory card
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;
}
}
void loop()
{
val = digitalRead(inputPin);
if (val == HIGH)
{
if (pirState == LOW)
{
// we have just turned on
Serial.println("Motion!");
//Turn eyes on
digitalWrite(eyeleds, HIGH);
// Play a sound:
randNumber = 0;
randNumber = random(3);
if (randNumber >= 1)
{
randNumber = random(3);
randNumber = randNumber + 1;
Serial.println(randNumber);
if (randNumber == 1)
{
playcomplete("11.WAV");
}
else if (randNumber == 2)
{
playcomplete("2.WAV");
}
else if (randNumber == 3)
{
playcomplete("13.WAV");
}
else if (randNumber == 4)
{
playcomplete("1.WAV");
}
}
pirState = HIGH;
}
}
else
{
if (pirState == HIGH)
{
digitalWrite(eyeleds, LOW);
// we have just turned off
Serial.println("Motion ended!");
// We only want to print on the output change, not state
pirState = LOW;
}
}
}
void playcomplete(char *name)
{
char i;
uint8_t volume;
int v2;
playfile(name);
while (wave.isplaying)
{
volume = 0;
for (i=0; i<8; i++)
{
v2 = analogRead(1);
delay(5);
}
if (v2 > 440)
{
pulseWidth = 1800;
mouthchange = 1;
}
else
{
pulseWidth = 800;
mouthchange = 1;
}
digitalWrite(servoPin, HIGH); // start the pulse
delayMicroseconds(pulseWidth); // pulse width
digitalWrite(servoPin, LOW); // stop the pulse
}
card.close_file(f);
digitalWrite(eyeleds, LOW);
// we have just turned off
}
void playfile(char *name)
{
// stop any file already playing
if (wave.isplaying)
{
wave.stop();
card.close_file(f);
}
f = card.open_file(name);
if (f && wave.create(f))
{
wave.play();
}
here is the code from the one i found online, am I missing something he said all he used was a duemilanove board and a wave shield
#include
#include
#include "util.h"
#include "wave.h"
#define DEBOUNCE 100
#define swPin 14
#define eyeleds 18
AF_Wave card;
File f;
Wavefile wave;
int inputPin = 8; // choose the input pin (for PIR sensor)
int servoPin = 16; // choose the input pin (for Servo)
int pirState = LOW; // we start, assuming no motion detected
int val = 0; // variable for reading the pin status for motion sensor
int minPulse = 600; // minimum servo position
int maxPulse = 2200; // maximum servo position
int BANNED = 1800; // servo turn rate increment (larger value, faster rate)
int refreshTime = 20; // time (ms) between pulses (50Hz)
int mouthchange = 6; //checks to see if mouth position needs to be changed
int randNumber; //random number variable to allow the choosing of which wav will be played
/** The Arduino will calculate these values for you **/
int centerServo; // center servo position
int pulseWidth; // servo pulse width
long lastPulse = 0; // recorded time (ms) of the last pulse
void setup() {
// set up serial port
Serial.begin(9600);
pinMode(inputPin, INPUT); // declare sensor as input for PIR
pinMode(eyeleds, OUTPUT); // declare sensor as output for eyes
// set up servo pin
pinMode(servoPin, OUTPUT); // Set servo pin 18 (analog 4) as an output pin
centerServo = maxPulse - ((maxPulse - minPulse)/2);
pulseWidth = centerServo; // Give the servo a starting point (or it floats)
// set up waveshield pins
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
// open memory card
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;
}
}
void loop()
{
val = digitalRead(inputPin);
if (val == HIGH)
{
if (pirState == LOW)
{
// we have just turned on
Serial.println("Motion!");
//Turn eyes on
digitalWrite(eyeleds, HIGH);
// Play a sound:
randNumber = 0;
randNumber = random(3);
if (randNumber >= 1)
{
randNumber = random(3);
randNumber = randNumber + 1;
Serial.println(randNumber);
if (randNumber == 1)
{
playcomplete("11.WAV");
}
else if (randNumber == 2)
{
playcomplete("2.WAV");
}
else if (randNumber == 3)
{
playcomplete("13.WAV");
}
else if (randNumber == 4)
{
playcomplete("1.WAV");
}
}
pirState = HIGH;
}
}
else
{
if (pirState == HIGH)
{
digitalWrite(eyeleds, LOW);
// we have just turned off
Serial.println("Motion ended!");
// We only want to print on the output change, not state
pirState = LOW;
}
}
}
void playcomplete(char *name)
{
char i;
uint8_t volume;
int v2;
playfile(name);
while (wave.isplaying)
{
volume = 0;
for (i=0; i<8; i++)
{
v2 = analogRead(1);
delay(5);
}
if (v2 > 440)
{
pulseWidth = 1800;
mouthchange = 1;
}
else
{
pulseWidth = 800;
mouthchange = 1;
}
digitalWrite(servoPin, HIGH); // start the pulse
delayMicroseconds(pulseWidth); // pulse width
digitalWrite(servoPin, LOW); // stop the pulse
}
card.close_file(f);
digitalWrite(eyeleds, LOW);
// we have just turned off
}
void playfile(char *name)
{
// stop any file already playing
if (wave.isplaying)
{
wave.stop();
card.close_file(f);
}
f = card.open_file(name);
if (f && wave.create(f))
{
wave.play();
}
}
Last edited by adafruit_support_bill on Mon Oct 05, 2015 4:18 pm, edited 1 time in total.
Reason: p
Reason: p
- adafruit_support_bill
- Posts: 88151
- Joined: Sat Feb 07, 2009 10:11 am
Re: Moving a servo with Arduino Duemilanove Board and adafru
It looks like he is not using the servo library, but generating the pulse timings manually. Can you post a link to the tutorial you are following? I am not familiar with this code.
- tls5606
- Posts: 12
- Joined: Mon Oct 05, 2015 2:43 pm
Re: Moving a servo with Arduino Duemilanove Board and adafru
Here is the link for the project. I am sorry i thought i posted this awhile ago
http://www.instructables.com/id/Talking ... -Skeleton/
http://www.instructables.com/id/Talking ... -Skeleton/
- adafruit_support_bill
- Posts: 88151
- Joined: Sat Feb 07, 2009 10:11 am
Re: Moving a servo with Arduino Duemilanove Board and adafru
He didn't mention that circuit board in the materials list. But something like this should work: https://www.adafruit.com/product/589Here's how the motion sensor and servo are connected up. these diagrams are done this way because I hooked all the wires in the skull up to a small project circuit board and then used CAT-5 Network Cable to run it down to the arduino. The network cable allowed me to have more than enough wires to run everything I needed in one convenient package.
Servos are pretty simple. Connect the black or brown wire to GND. The red center wire to 5v and the white or yellow wire to your signal pin. (Analog 2 in this case). You can solder wires to the breakout holes next to the headers on the wave shield.
- babymonkeystuff
- Posts: 3
- Joined: Sun Dec 04, 2016 11:24 pm
Re: Moving a servo with Arduino Duemilanove Board and adafru
I made the same mistake of buying this wave board thinking that I could use it with my Arduino. You probably want to tell users, at least in the fine print that this board does not work with the Arduino.
- Franklin97355
- Posts: 23940
- Joined: Mon Apr 21, 2008 2:33 pm
Re: Moving a servo with Arduino Duemilanove Board and adafru
Are you talking of the wave shield? It works with the Arduino. Which boards do you have and what is not working?
- babymonkeystuff
- Posts: 3
- Joined: Sun Dec 04, 2016 11:24 pm
Re: Moving a servo with Arduino Duemilanove Board and adafru
Just like the person in the original post I bought the wave shield to make an animatronic talk. Just like the original person I am using the arduino servo board and in my case an uno. They stack fine with soldering. I can load the sketch that came with the wave and it talks. I load the servo sketch it moves the servo. But as soon as I have include wavexxx and include servo the sketch will not compile.
- Franklin97355
- Posts: 23940
- Joined: Mon Apr 21, 2008 2:33 pm
Re: Moving a servo with Arduino Duemilanove Board and adafru
What are the links to the boards you are using and what is the actual code you are trying to compile? Please use
Code: Select all
tags when posting code or logs to the forums by clicking the </> button above the reply box and pasting your code between the tags created.
- adafruit_support_bill
- Posts: 88151
- Joined: Sat Feb 07, 2009 10:11 am
Re: Moving a servo with Arduino Duemilanove Board and adafru
As the original response to the original post says:
"The Arduino servo library and the wave shield libraries don't work together since they both use the same timer."
This is a very early shield design and only works with the UNO. It is not compatible with most of the newer Arduino processors. And does not work with the Arduino servo library - or anything else that needs to use Timer-1
You can still control your servos using a Servo shield: https://www.adafruit.com/products/1411
The music-maker shield is a better choice of shound shield for new projects.
https://learn.adafruit.com/adafruit-mus ... s?view=all
"The Arduino servo library and the wave shield libraries don't work together since they both use the same timer."
This is a very early shield design and only works with the UNO. It is not compatible with most of the newer Arduino processors. And does not work with the Arduino servo library - or anything else that needs to use Timer-1
You can still control your servos using a Servo shield: https://www.adafruit.com/products/1411
The music-maker shield is a better choice of shound shield for new projects.
https://learn.adafruit.com/adafruit-mus ... s?view=all
- babymonkeystuff
- Posts: 3
- Joined: Sun Dec 04, 2016 11:24 pm
Re: Moving a servo with Arduino Duemilanove Board and adafru
your saying that I can use my Arduino Uno, Arduino servo shield and the adafruit music maker with the associated libraries without this type of conflicts.
or purchase the adafruit serveo shield, use it instead of the ardunio servo shield along with the Arduino Uno, adafruit wave shield and associated libraries again with no conflicts?
or purchase the adafruit serveo shield, use it instead of the ardunio servo shield along with the Arduino Uno, adafruit wave shield and associated libraries again with no conflicts?
- adafruit_support_bill
- Posts: 88151
- Joined: Sat Feb 07, 2009 10:11 am
Re: Moving a servo with Arduino Duemilanove Board and adafru
There are several workable combinations there:
The servo shield has its own on-board pulse generator, so it does not need to use any of the Arduino timers. It communicates via the i2c bus and has no conflicts with the Wave Shield. https://www.adafruit.com/products/1411
The Music Maker shield has it's own on-board stereo DAC and music file decoder, so it does not need to use any of the Arduino timers either. It does use bunch of Arduino pins in operation, but the remaining pins could be used for servos.
https://learn.adafruit.com/adafruit-mus ... s?view=all
And, of course, there are no conflicts between the Music Maker and the Servo Sheild. So htey could be used together.
The servo shield has its own on-board pulse generator, so it does not need to use any of the Arduino timers. It communicates via the i2c bus and has no conflicts with the Wave Shield. https://www.adafruit.com/products/1411
The Music Maker shield has it's own on-board stereo DAC and music file decoder, so it does not need to use any of the Arduino timers either. It does use bunch of Arduino pins in operation, but the remaining pins could be used for servos.
https://learn.adafruit.com/adafruit-mus ... s?view=all
And, of course, there are no conflicts between the Music Maker and the Servo Sheild. So htey could be used together.
Please be positive and constructive with your questions and comments.