Arduino Code

Might want to try the Arduino fourms. Tons of posts, hard to “get into” (at least I haven’t), but may be worth it!

Alan KM6VV

I am using the Mega, which means I should be able to get the robot off the ground the way I have it programmed. Code as such for a simple startup:

[code]
#include <Servo.h>
#define sn 18 //Number of servos.
#define pn 2 //Starting pin number.
Servo s[sn] ;

void setup(){
//These setup and then force robot to get upright.
for( int i =0; i < sn; i++){
s*.attach(pn+i, 1000, 2000);
}
delay(1000);
for( int j=0; j < 6; j++){
s[j].writeMicroseconds(1500);
}
delay(2000);
for( int k=6; k < 18; k++){
s[k].writeMicroseconds(1500);
}
}
void loop(){
delay(1000);
for( int k=0; k < 18; k++){
s[k].writeMicroseconds(1500);
}
} [/code]

Looked on Arduino’s forum, not much help to be found. Plus it won’t create an account for me.
Either way, those delay(ms) don’t work.
Code tested with LEDs, works fine.

I swear the damn thing is taunting me. Lol :stuck_out_tongue:*

Access to the arduino forum is currently bad, probably due to high volumes of activities. You can do a google advanced search of the forum to get specific info. Below are the results of a search for “mega servo”.

google.com/search?q=mega+ser … afe=images

Before I get to far into this. How do you have your servos connected and what power are you giving them? Often times, when someone says it should get off the ground, it turns out to be that they are expecting some small wall wart to power it and the processor resets or the like… But assuming reasonable power…

I Could be wrong, but I believe that when an instance of the servo class is created it is initialized to the default pulse width (ie 1500). So once you do an Attach the servo will spring to it’s default location, which more or less makes your first loop pointless. If it were me, to debug it I would add some debug print outs to see where I am in the code. Something like:

[code] #include <Servo.h>
#define sn 18 //Number of servos.
#define pn 2 //Starting pin number.
Servo s[sn] ;

void setup(){
  Serial.begin(38400);
  //These setup and then force robot to get upright.
  Serial.println("Before Attach");
  for( int i =0; i < sn; i++){
    s*.attach(pn+i, 1000, 2000);
  }
  Serial.println("After Attach");
  delay(1000);
  Serial.println("Before First Loop");
  for( int j=0; j < 6; j++){
    s[j].writeMicroseconds(1500);
  }
  Serial.println("After First");
  delay(2000);
  Serial.println("B2");
  for( int k=6; k < 18; k++){
    s[k].writeMicroseconds(1500);
  }
Serial.println("A2");
}
void loop(){
  Serial.println("Loop");
  delay(1000);
  for( int k=0; k < 18; k++){
    s[k].writeMicroseconds(1500);
  }
} [/code]

This way you can see when things are happening. So for the most part I suspect that all of the servos will try to move on the attach loop and then nothing else will change.

Kurt*

For clarification: Servos are powered by a 2s LiPo connected to a regulator. Ground is of course tied to the arduino. Arduino IS run off of a separate power supply. I used basically the same setup someone else did to power a similar hexapod, mine if anything is lighter and has better power supply. Haven’t had a chance to check out whats going on with the serial debug yet, we just got a 3d printer! :smiley: I’ll post soon.