difficulty combining movements of two servos

Hi folks,
I'm very new to Arduino and I'm trying to build a talking skull (been done a million times, I know). I have managed to integrate all the hardware and build a working circuit using a sound meter, arduino, mp3 player, PIR and two servos (one for the jaw movement and one for the head turn). The problem I am having is that the head turn servo movement (which I was able to slow down using the VarServoSpeed library) is being interrupted by my jaw movement such that the head turn servo cannot complete it's movement and just "shivers". I can slow the speed of the head turn servo by adding a "true" statement in the variables but that has the effect of forcing the jaw servo to wait for the head servo to complete it's movement, effectively acting like a "delay" command. How can I get both the jaw and the head to move at independent speeds and not interrupt each other? Attached below is my messy code (I'm still learning). Any help or guidance would be really great!

SkullTalk.ino (11.1 KB)

I'm not familiar with the VarSpeedServo library - it may be that it can only move one servo at a time.

Have a look at how the servo is moved in the demo Several Things at a Time. If you were to create another almost identical function for a second servo they would both work in parallel.

...R

I still see the code loaded with delay(). Get rid of them!

Thanks guys!
Robin2 I will give that a try; I have to admit, with only 2 weeks of arduino coding under my belt the stateMachine concept is difficult to grasp, let alone manipulate into my code. but I will try!
And Septillion, I will strive to get rid of the remaining delays (although for the MP3 it helps because I do want the whole system shut down when not performing).

Robin2 I have a question: the one servo is getting analog position data from the sound meter and moving accordingly to lip-sync with the sound coming from the MP3 player. I don't want to mess with that because it is working perfectly. So would the Millis() code from the BWOD sketch work with just the head turn servo? Or do I need to set up parameters for both? I'm confused as to how I could do that. Any help would be wonderful!

You must remove almost all delays in the main loop. The only delay which is acceptable is maybe a few microseconds for a sensor or stepper with special timing requirements and even then it is usually desirable to remove that.

Brianaala:
So would the Millis() code from the BWOD sketch work with just the head turn servo?

I don't think so. Both servos need to use a non-blocking process.

And I agree about the removal of ALL delay()s

...R

Thank you for all the help!!
So, if I were to assign both servos the macro but just leave the jaw servo at full speed; would that still allow it to get the angle parameters from the analog pins (for lip sync with the sound)? How would I write that?

Hi,
How are you powering the components, specifically the servos.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom... :slight_smile:

Brianaala:
So, if I were to assign both servos the macro but just leave the jaw servo at full speed;

In my example the servo is controlled within a function. A macro is a different thing.

And, yes, if you mean that the jaw servo is just controlled with a simple jawServo.write() then what you suggest should be fine.

...R