Good micro processor

Thread Starter

navyguy

Joined Sep 27, 2019
108
This came up before and I recall the thread. Here it is. I know this stuff can be a little confusing and I am well aware as we age things do not sink in quite as quick as they once did. Believe me you can get this done with an Arduino Uno.

Here is an example:
Code:
#include <Servo.h>

Servo myservo1;  // create servo object to control a servo1
Servo myservo2;  // create servo object to control a servo2
Servo myservo3;  // create servo object to control a servo3
// twelve servo objects can be created on most boards but here we use only 3 servo motors.

int pos1 = 0;    // variable to store the servo1 position
int pos2 = 0;    // variable to store the servo2 position
int pos3 = 0     // variable to store the servo3 position

void setup() {
  myservo1.attach(9);  // attaches the servo1 on pin 9 to the servo object
  myservo2.attach(10);  // attaches the servo2 on pin 10 to the servo object
  myservo1.attach(11);  // attaches the servo3 on pin 11 to the servo object
}

void loop() {
  for (pos1 = 0; pos1 <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo.write(pos1);              // tell servo to go to position in variable 'pos1'

   for (pos2 = 0; pos2 <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo.write(pos2);              // tell servo to go to position in variable 'pos2'

for (pos3 = 0; pos3 <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo.write(pos3);              // tell servo to go to position in variable 'pos3'

    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for (pos1 = 180; pos1 >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
    myservo.write(pos1);              // tell servo to go to position in variable 'pos1'

  for (pos2 = 180; pos2 >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
    myservo.write(pos2);              // tell servo to go to position in variable 'pos2'
 
for (pos3 = 180; pos3 >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
    myservo.write(pos3);              // tell servo to go to position in variable 'pos3'

    delay(15);                       // waits 15ms for the servo to reach the position
  }
}
Try running that code and I am willing to bet all 3 servos will respond about equally, any lag between servo 1 & 3 won't be noticeable. All of this was covered back in April the same way. All the above code does is run the servos 180 degrees and back over and over again. Written for an Arduino Uno and originally for a single servo. I do not have three servos to actually try it out and if anyone sees a problem with it feel free to critique it.

Ron
Hi Ron,

I tried running the program. Its hung up on 'pos' not declared in this scope. Ill keep working on it.
Thanks
 

strantor

Joined Oct 3, 2010
5,543
ok sorry. Not sure how I missed that but every time I read up on the comments I feel like I’m trying to drink from a fire hydrant.
thamls again
I missed it too. Actually I am tempted to swear it wasn't there. Posts with videos tend to jump out
 

trebla

Joined Jun 29, 2019
364
Instead of variable "pos" in servo controlling for() statements use pos1, pos2 and pos3 variables respectively to current for() statement. Also in line 15 change myservo1 to myservo3.

Edit: in servo.write function calls add numbers 1,2 and 3 after myservo name, for example myservo1.write or myservo2.write respecrively to current for() loop.
 
Last edited:

Reloadron

Joined Jan 15, 2015
5,935
Check out the Halloween-L group on Facebook. You’ll find many projects animating skeletons or other props using an Arduino and RC servos.

The Arduino and Adafruit shield is an EXCELLENT choice for your project. You just need to read more about how people are using it in Halloween props.

I’ve mentioned my project several times, so I thought I’d post a video. This animatronic uses an Arduino and 11 RC servos. And in addition to the movement, it controls an MP3 shield to make the animatronic talk. And the Arduino has an Ethernet shield so multiple characters collaborate and have conversations, sing in multipart harmony, etc...

So I’m confident an Arduino will work for you.

That is pretty cool. :)

Ron
 

Reloadron

Joined Jan 15, 2015
5,935
OK, my bad on my code sample. I have it fixed and it runs on an Arduino Uno. I took the time to look at it on a scope. The code is pretty basic and I used plenty of remarks along the way trying to explain what is going on.
Code:
#include <Servo.h>

Servo myservo1;  // create servo object to control a servo1
Servo myservo2;  // create servo object to control a servo2
Servo myservo3;  // create servo object to control a servo3
// twelve servo objects can be created on most boards but here we use only 3 servo motors.

int pos1 = 0;    // variable to store the servo1 position
int pos2 = 0;    // variable to store the servo2 position
int pos3 = 0;    // variable to store the servo3 position

void setup() {
  myservo1.attach(9);   // attaches the servo1 on pin 9 to the servo object
  myservo2.attach(10);  // attaches the servo2 on pin 10 to the servo object
  myservo3.attach(11);  // attaches the servo3 on pin 11 to the servo object
}

void loop() {
  for (pos1 = 0; pos1 <= 180; pos1 += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo1.write(pos1);              // tell servo to go to position in variable 'pos1'
  }     
   for (pos2 = 0; pos2 <= 180; pos2 += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo1.write(pos2);              // tell servo to go to position in variable 'pos2'
   }
    for (pos3 = 0; pos3 <= 180; pos3 += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo3.write(pos3);              // tell servo to go to position in variable 'pos3'
  }
    delay(15);                       // waits 15ms for the servos to reach the position
  
  for (pos1 = 180; pos1 >= 0; pos1 -= 1) { // goes from 180 degrees to 0 degrees
    myservo1.write(pos1);              // tell servo to go to position in variable 'pos1'
  }
  for (pos2 = 180; pos2 >= 0; pos2 -= 1) { // goes from 180 degrees to 0 degrees
    myservo2.write(pos2);              // tell servo to go to position in variable 'pos2'
  }
  for (pos3 = 180; pos3 >= 0; pos3 -= 1) { // goes from 180 degrees to 0 degrees
    myservo3.write(pos3);              // tell servo to go to position in variable 'pos3'
  }
    delay(15);                       // waits 15ms for the servos to reach the position
 
}
Ron
 

Thread Starter

navyguy

Joined Sep 27, 2019
108
OK, my bad on my code sample. I have it fixed and it runs on an Arduino Uno. I took the time to look at it on a scope. The code is pretty basic and I used plenty of remarks along the way trying to explain what is going on.
Code:
#include <Servo.h>

Servo myservo1;  // create servo object to control a servo1
Servo myservo2;  // create servo object to control a servo2
Servo myservo3;  // create servo object to control a servo3
// twelve servo objects can be created on most boards but here we use only 3 servo motors.

int pos1 = 0;    // variable to store the servo1 position
int pos2 = 0;    // variable to store the servo2 position
int pos3 = 0;    // variable to store the servo3 position

void setup() {
  myservo1.attach(9);   // attaches the servo1 on pin 9 to the servo object
  myservo2.attach(10);  // attaches the servo2 on pin 10 to the servo object
  myservo3.attach(11);  // attaches the servo3 on pin 11 to the servo object
}

void loop() {
  for (pos1 = 0; pos1 <= 180; pos1 += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo1.write(pos1);              // tell servo to go to position in variable 'pos1'
  }    
   for (pos2 = 0; pos2 <= 180; pos2 += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo1.write(pos2);              // tell servo to go to position in variable 'pos2'
   }
    for (pos3 = 0; pos3 <= 180; pos3 += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo3.write(pos3);              // tell servo to go to position in variable 'pos3'
  }
    delay(15);                       // waits 15ms for the servos to reach the position
 
  for (pos1 = 180; pos1 >= 0; pos1 -= 1) { // goes from 180 degrees to 0 degrees
    myservo1.write(pos1);              // tell servo to go to position in variable 'pos1'
  }
  for (pos2 = 180; pos2 >= 0; pos2 -= 1) { // goes from 180 degrees to 0 degrees
    myservo2.write(pos2);              // tell servo to go to position in variable 'pos2'
  }
  for (pos3 = 180; pos3 >= 0; pos3 -= 1) { // goes from 180 degrees to 0 degrees
    myservo3.write(pos3);              // tell servo to go to position in variable 'pos3'
  }
    delay(15);                       // waits 15ms for the servos to reach the position

}
Ron

Ron,

Your the best. Thank you so much!!!
 

Thread Starter

navyguy

Joined Sep 27, 2019
108
Ron,

Your the best. Thank you so much!!!
Hi Ron,

youll love this.
I uploaded your program onto my arduino and my 3 servos and it did exactly what you said it would do.
Unfortunately the program ran for only about 5 minutes and then the servos went crazy. They all started chattering away. I tried everything to isolate the problem without any luck. I switched to another arduino and different servos. Same problem. I tried reloading your program but again the servos all chattering like crazy. I uploaded my old program and then everything started working fine.
I cant imagine for the life of me how your program coulod work fine for several minutes and stop. Any ideas?
Again I cant thank you and everyone else for all their help.
 

trebla

Joined Jun 29, 2019
364
Are you powering servos from Arduino? Servos tend to draw lot of current. It is good idea to power servos from different 5V and 2-3 A power source.
 

trebla

Joined Jun 29, 2019
364
Try modify your for() loops for each servo, adding a delay inside each loop like this ( for first servo):
C:
for (pos1 = 180; pos1 >= 0; pos1 -= 1) { // goes from 180 degrees to 0 degrees
    myservo1.write(pos1);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
}
 

jpanhalt

Joined Jan 18, 2008
11,088
Chattering servos in my experience can result from too high a refresh rate or a sloppy signal with digital servos (small dead band). By sloppy signal, I mean something like the simple 555 servo drivers.

Can you put a scope on the servo signal.
 

Reloadron

Joined Jan 15, 2015
5,935
You can try trebla's suggestion. I can't imagine why it ran fine and then began chattering? It's just a simple routine which runs over and over again so why it would suddenly burp I am not sure. I only have one little servo to experiment with so I just checked things using a scope and ran it a few min. That said it did pretty much demonstrate that any lag between lines is negligible. The Arduino Uno is used in animatronic projects frequently and it or any similar uC should do fine for your intended application.

Ron
 

Thread Starter

navyguy

Joined Sep 27, 2019
108
You can try trebla's suggestion. I can't imagine why it ran fine and then began chattering? It's just a simple routine which runs over and over again so why it would suddenly burp I am not sure. I only have one little servo to experiment with so I just checked things using a scope and ran it a few min. That said it did pretty much demonstrate that any lag between lines is negligible. The Arduino Uno is used in animatronic projects frequently and it or any similar uC should do fine for your intended application.

Ron
Exactly why I’m so blown away. Could only happen to me lol.
I swear it ran through the entire program several times. Then it all went south on me.
 

Thread Starter

navyguy

Joined Sep 27, 2019
108
Are you powering servos from Arduino? Servos tend to draw lot of current. It is good idea to power servos from different 5V and 2-3 A power source.
One of the first things I suspected was servos not getting enough current so I tried powering it from a 12 volt power supply. But again, logically, why are the servos working perfectly from an older program I had used before?
 

Thread Starter

navyguy

Joined Sep 27, 2019
108
Are you powering servos from Arduino? Servos tend to draw lot of current. It is good idea to power servos from different 5V and 2-3 A power source.
Looking at my 12 volt power supply, it’s only delivering 1000 ma. (1 amp).
But it was never a problem before. If you think 2 to 3 amps is what I should be using then I’ll look for a different power supply.
Thanks
 
Top