Problem running brushless motors with arduino nano

Hello!

I am trying to run 2 brushless motors with 2 30A ESCs. I have the ESCs connected to the pins 9 and 11 from the arduino nano for some reason I am not able to make it work without having to wait for a key to be pressed

Here are two codes. The first one works well but when I replace the lines 29 and 30 with a delay of 2 seconds only the ESC connected to the pin 11 works the one connected to the pin 9 does not work

This code works perfect:

/*ESC calibration sketch; author: ELECTRONOOBS */
#include <Servo.h>

#define MAX_SIGNAL 2000
#define MIN_SIGNAL 1000
#define MOTOR_PIN_9 9
#define MOTOR_PIN_11 11
int DELAY = 1000;

Servo motor_1;
Servo motor_2;

void setup() {
  Serial.begin(9600);
  delay(1500);
  Serial.println("Program begin...");
  delay(1000);
  Serial.println("This program will start the ESC.");

  motor_1.attach(MOTOR_PIN_9);
  motor_2.attach(MOTOR_PIN_11);

  Serial.print("Now writing maximum output: (");Serial.print(MAX_SIGNAL);Serial.print(" us in this case)");Serial.print("\n");
  Serial.println("Turn on power source, then wait 2 seconds and press any key.");
  motor_1.writeMicroseconds(MAX_SIGNAL);
  motor_2.writeMicroseconds(MAX_SIGNAL);
  Serial.println("ya corrio1");
  // Wait for input
  while (!Serial.available());
  Serial.read();

  // Send min output
  Serial.println("\n");
  Serial.println("\n");
  Serial.println("ya corrio2");
  Serial.print("Sending minimum output: (");Serial.print(MIN_SIGNAL);Serial.print(" us in this case)");Serial.print("\n");
  motor_1.writeMicroseconds(MIN_SIGNAL);
  motor_2.writeMicroseconds(MIN_SIGNAL);
  Serial.println("The ESC is calibrated");
  Serial.println("----");
  Serial.println("Now, type a values between 1000 and 2000 and press enter");
  Serial.println("and the motor will start rotating.");
  Serial.println("Send 1000 to stop the motor and 2000 for full throttle");

}

void loop() {
  motor_1.writeMicroseconds(1100);
  motor_2.writeMicroseconds(1100);
}

If I replace

  while (!Serial.available());
  Serial.read();

with

  delay(2000)

Only the motor connected to the pin 11 works.

Can someone help me understand why is that? I can not depend on pressing a key on the keyboard to have it working

Appreciate any suggestion on how can I run both motors without a problem

Thanks in advance!
Marco

delay() is blocking the complete microcontroller.

You should use non-blocking timing based on millis()

take a look at the blink without delay-example to learn how non-blocking timing works

@the Arduino-TEAM:
Finally ditch this endlessly crappy delay () command from the included examples and replace it with examples with non-blocking timing for all basic use cases
flash
oneshot timer
delays
create different ON/OFF-Time
best regards Stefan

StefanL38 obviously doesn't like the useful delay() command but doesn't explain how it has anything to do with your problem.

If you really don't have a ; on the end of the delay(2000) that won't help. And when you you say "doesn't work" do you mean that the motor_1 ESC is not initialised (i.e. no beeps, nothing?) or something else that you haven't explained?

Steve

Thanks guys for taking the time

Sorry for the typo on the post. I have the ; after the delay in the code, if not it doesn't even compile.

When I i say that it doesn't work what I mean that the esc is not armed so when on the loop I do

motor_1.writeMicroseconds(1100);

It doesnt spin. On the other hand the motor_2 does spin.

If I change the wiring an i connect the motor_1 to the pin 11 and the motor_2 to pin 11 so it is the other way around.

I hope this explains better the issue

Thanks in advance,
Marco

Still not completely clear to me because some details are missing. So my guessing is that you want to say

motor1 is connected to io-pin 9 does not spin
motor2 is conected to IO-pin 11 does SPIN

connecting the motors "inverted"
motor1 is connected to io-pin 11 does SPIN
motor2 is conected to IO-pin 9 does not soin

if this is the case then it is a problem inside the ESC.
Some ESCs can store calibration-values even if you switch power off.

So it might be that one ESC is calibrated completely wrong or vice versa what pusle-length is throttle off and full throttle
and would wait for throttle-off all the time.

So what results do you get if you do all four possible combinations?

ESC1-motor1 is connected to io-pin 9
ESC2 -motor2 is conected to IO-pin 11

ESC1-motor2 is connected to io-pin 9
ESC2 -motor1 is conected to IO-pin 11

ESC2-motor1 is connected to io-pin 9
ESC1 -motor2 is conected to IO-pin 11

ESC2-motor2 is connected to io-pin 11
ESC1 -motor1 is conected to IO-pin 9

and did you ever try a crosschecking by using a different IO-pin or a cross-checking with a servo if your IO-pin 9 /11 is creating a servo-signal at all?

best regards Stefan

Stefan thanks for taking the time to answer. I think I am not being clear enough.

The thing is this. If you check the code I shared at the beginning, if I do the while with read serial.read both ESCs are armed correctly and work correctly

If I replace the while with a delay to arm the ESCs directly without depending on the serial input jus one works. The one that works is the one connected to pin 11. If I connect any on the ESCs to pin 11 they work but I am no able to have both working at the same time.

I hope it helps

Thanks,
Marco

Hi,
Can you please post a picture of your project, including power supplies?

Can you please post a circuit diagram of your project, including power supplies, use a pen(cil) and paper and show an image of it would be fine.
Please do not use a Fritzy picture.

Tom... :grinning: :+1: :coffee: :australia:

Did you check IO-pin 9 with a servo if a servo-signal is created at all?

Did you modify your program to use IO-pin 4,5,6,7,8 instead of io-pin 9?
best regards Stefan