preface: I am a complete newb with much more equiptment than experience, so mention the dumb things! I wont take offense I swear
So I am using a sanguino, trying to control a servo, using RC input. I have massivly simplified my code to weed out the issues, and here is where I sit. I got the sanguino specific Servo library, and the sweep example works perfectly, both with a servo hooked up and when looking at the pulses on a scope. I had to edit the code as servo only works on pins 12 and 13, aside from that, it works swell!
// Sweep
// by BARRAGAN <http://barraganstudio.com>
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
int pos = 0; // variable to store the servo position
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop()
{
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
now my code I take the output from an RC remote, which is meant to drive a servo, and convert the pulse duration to a servo position, and set the servo to that position. I threw in a delay for my sanity. both the value of the pulse length and desired servo position are perfectly sensible (86-84 deg with the stick neutral) BUT the servo goes nuts, and the scope shows arbritary pulse lengths for any angle given. meaning a 84 deg write always produces the same output pulse, but it is NOT of the correct length, and its not a scale issue, as it jumps around from angle to angle. originally I was using longs, so i cast things to ints as they are in the EX, and there was 0 change in the behavior
//RC pass through
#include <Servo.h> //only works for pins 12 & 13 on sanguino
Servo LDrive;
Servo RDrive;
int ch0Pin = 15; //first channel
int ch1Pin = 16;
int ch2Pin = 17;
int ch3Pin = 18;
int ch4Pin = 19;
int ch5Pin = 20;
int LControllPin = 12; //to motor controlls
int RControllPin = 13;
unsigned long RCin[7]; //8 channel RC remote
void setup()
{
for (int ii = 0; ii < 8; ii++){
RCin[ii]=1500;}
pinMode(ch0Pin, INPUT);
pinMode(ch1Pin, INPUT);
pinMode(ch2Pin, INPUT);
pinMode(ch3Pin, INPUT);
pinMode(ch4Pin, INPUT);
pinMode(ch5Pin, INPUT);
LDrive.attach(LControllPin);
RDrive.attach(RControllPin);
Serial.begin(9600);
// prints initial value on chan 0 and says hi
Serial.println(RCin[0]);
Serial.println("Setup Complete");
}
void loop(){
int lServ = 90;
int rServ = 90;
RCupdate();
lServ = map(RCin[0], 1000, 2000, 0, 180); //maps left drive percent (signed) to servo degrees, assumes 90 deg = 1500 us pulse
rServ = map(RCin[2], 1000, 2000, 0, 180); //defaults set servo max min to 544 2400
int lsint = (int) lServ;
int rsint = (int) rServ;
LDrive.write(lsint);
RDrive.write(rsint); //86 deg real short pulse, 84 deg absurd short pulse grows and shrinks
Serial.println(rsint); //looks fine
Serial.println(rServ); //
delay(1000);
}
void RCupdate(){
RCin[0] = pulseIn(ch0Pin, HIGH); //throttle
// RCin[1] = pulseIn(ch1Pin, HIGH); //aile
RCin[2] = pulseIn(ch2Pin, HIGH); //elev
// RCin[3] = pulseIn(ch3Pin, HIGH);
// RCin[4] = pulseIn(ch4Pin, HIGH); //gear
// RCin[5] = pulseIn(ch5Pin, HIGH);
}
any advice? I may be shelving the damn boards and buying a MEGA and just hope its a compatibility thing