Hello Wise Arduino brogrammers,
I am trying to build a RC plane, and I've got 3 servos and a brushless motor hooked up to my Ardunio. It's all hooked to a 3s battery. If I move the controls a lot, the board freezes up. Servos and motor just abruptly stop... after a few moments the board seems to start working again and I regain control.
This random freezing is obviously a no-go when building planes, so can anyone clue me in? I thought at first it was becasue my power supply wasn't high enough, but this 3s is providing plenty of power, and the board's lights don't flicker like they do when power runs low. I added a 100ms delay between loops to see if that helps at all, but it doesn't.
My code:
#include <Servo.h>
Servo esc_signal1;
Servo myservo1;
Servo myservo2;
Servo myservo3;
float ch1;
float ch2;
float ch3;
float ch4;
int servopos;
int servopos2;
int servopos3;
int servopos5;
void setup()
{
myservo1.attach(13); // Left side Servo which we will call Channel 1
myservo2.attach(10); // Center Servo AKA Channel 4
myservo3.attach(12); // Right side Servo AKA Channel 2
esc_signal1.attach(9); //Specify here the pin number on which the signal pin of ESC is connected.
esc_signal1.write(10); //ESC arm command. ESCs won't start unless input speed is less during initialization.
delay(3000); //ESC initialization delay.
}
void loop()
{
ch1 = pulseIn(5, HIGH, 25000);
ch2 = pulseIn(2, HIGH, 25000);
ch3 = pulseIn(6, HIGH, 25000); //This is the Motor
ch4 = pulseIn(4, HIGH, 25000);
delay(15);
if(ch1 != 0){ // This is actually ch3
servopos = map(ch1, 1050, 1950, 0, 180);
servopos2 = map(ch1, 1050, 1950, 180, 0);
myservo1.write(servopos); // Found on 13th PIN
myservo3.write(servopos2); // Found on 13th PIN
}
if(ch2 != 0){
servopos3 = map(ch2, 1050, 1950, 0, 180);
}
if(ch3 != 0){ // This is Ch1
int rotorspeed = map(ch3, 1050, 1950, 0, 90);
rotorspeed = rotorspeed + 40;
esc_signal1.write(rotorspeed);
Serial.println(ch3);
}
if(ch4 != 0){ // This is Ch4
servopos5 = map(ch4, 1050, 1950, 180, 0);
myservo2.write(servopos5);
}
delay(100);
}
Moderator edit: Post (probably) restored.