Servos and Brushless freezing up occasionally

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.

I added a 100ms delay between loops to see if that helps at all, but it doesn't.

A 100ms delay between loops will help crash your plane faster... you should code this without any delay() at all in the loop().


if(ch1 != 0){ // This is actually ch3How does this comment help us understands the code... ?


servopos = map(ch1, 1050, 1950, 0, 180);
    servopos2 = map(ch1, 1050, 1950, 180, 0);

are you 100% sure that ch1 will always be between 1050 and 1950? The map() function does not constrain the result within the bounds you pass, it just calculate the affine function (the line) going through 2 points and maps your input value to that line. So you might end up with angles below 0 or above 180. What happens then to your motors ?

-> there is a constrain() function you could add after mapping


servopos3 is calculated but not used... feels weird
—> don’t do operations that are useless. For example don’t read the pulsein() of something unused that function is blocking listening for (in your case you set the timeout) up to 25ms x 4 = 100ms at the beginning of the loop... and fine tune the timeout (if you expect a front to last in the range of 1 to 2ms and be very cyclical then there is probably no need to wait 25ms to see one)

Use nRF24L01+ wireless transceivers and you won't need any of that pulseIn() nonsense. And the plane will be able to send data to the base unit. Simple nRF24L01+ Tutorial

Your interruptions suggest a power problem. Give the Arduino its own power supply - at least for testing.

...R

Please post details of all components (what servos, motor, ESC?) and a wiring diagram. Servos generally won't run on 3S voltage (12.6V fully charged) and that's also a bit high for running an Arduino so it would be useful to know EXACTLY how you have all these things connected.

If, for example, you have the 3 servos connected to the Arduino 5V pin then that's your problem.

Steve

Post Removed.

danlessor:
How do I make links work? On most forums they work automatically... As a forum software programmer, I must say get with the times Arduino.cc.... this lack of user friendliness is unacceptable.

You could always try reading the instructions in "How to use this forum - please read" at the top of every forum.

BTW there's no way I can tell from that picture how the power is distributed to the various components. That's why I asked for a wiring diagram.

Steve

Post Removed.

Post Removed.

It’s the naked truth though

The mods don’t own the tool from what I gather - the feedback needs to be sent to the Arduino org and there is a forum for that, it’s not here

And the only way to get things posted nicely is to read a bit the doc... and learn the tags if you post like me from mobile because the toolbar does not work there...

That won’t kill you :slight_smile:

I have no hard feeling about anything - just expressing my views, I’m totally fine with people who don’t agree - it’s a free world.

Post Removed.

danlessor:
As a creator of forums, I do not support the sticky feature as no 1 thread created by a user should be more important than another. Forums with mods who lock and sticky threads are often corrupt and egalitarian--

Blimey ...

Another one who prefers a grievance to assistance.

...R

I went ahead and removed my posts as I don't feel like this is the place for me.

Thank you for those who attempted to provide assistance.

danlessor:
I went ahead and removed my posts as I don't feel like this is the place for me.

Well, that's a pretty obvious ban.

Nothing to see here folks.

Totally agree on the ban there. Now no one else can learn from that.