I am new to arduino, and am making a quadcopter. I use the Arduino Mega 2560, a 15A ESC Turnigy multistar, and ST2210 engines. The problem I have is that I tried to initialize the motors by first sending a pulse of 0 microseconds and then a 1000. I don't know why the ESC beeps twice, and it does not happens always. Sometimes it works well when I start the engine (1100 microseconds), but what worries me is that the engine twice, has started suddenly without notice dismounting everything. I even disconnected the power to the arduino, i kept the engine. The code I use is as follows:
#include <Servo.h>
#define PINMOTOR 10
#define POLSMINIM 1000
#define POLSMAXIM 1600
#define PAS 10
int polsmotor = 1000;
int lectura;
Servo motor;
void setup()
{
Serial.begin(9600);
motor.attach(PINMOTOR);
Serial.println(" Pitja \"a\" per a inicialitzar el motor");
while(Serial.read() != 'a');
inicialitzarmotor();
Serial.println(" Pitja \"a\" per aaugmentar la potencia, \"z\" per a disminuir-la, i \"s\" per a parar el motor.");
}
void loop()
{
motor.writeMicroseconds(polsmotor);
delay(100);
if(Serial.available() > 0)
{
lectura = Serial.read();
switch (lectura)
{
case 'a':
polsmotor += PAS;
break;
case 'z':
polsmotor -= PAS;
break;
case 's':
polsmotor = 1000;
break;
}
polsmotor = constrain(polsmotor, POLSMINIM, POLSMAXIM);
Serial.println(polsmotor);
}
}
void inicialitzarmotor()
{
long t=millis();
while((millis()-t)<1000) motor.writeMicroseconds(0);
motor.writeMicroseconds(1000);
}
Does anyone know the problem is and how to fix it?
Thanks in advance.
Sorry, I'm from Spain and it is google tranlater. Now I've changed. I've tried to search the specifications of my model of ESC, but I haven't found it. I found only the specifications of general turnigy ESC:
These speed controllers "pretend" they are servos. You need to talk to them like they are servos. Also, the initialization routines vary from one to the next. Even the ones of the same model. (I know, I do a lot of these) Meaning, the instructions are only a guide. They don't always follow them.
You need to do the setup by hand using an RC transmitter & receiver. Choose battery type, number of cells, etc. Once you've set up its parameters, you can use it to run your motors. Running motors is just 1ms - 2ms pulses less than 20ms apart.
Thanks but I don't have any RC transmitter or receiver. I just have the arduino mega, and a blutooth module. Can I make the motors work without the transmiter or receiver? I know they're expensive.
Just about any cheap transmitter will bind to it. I've even got them to talk to transmitters from cheap toys.
Or you could just borrow one from a friend, you only need it once to do the initial setup.
Or…
two buttons…
No.. Better idea. Get a 3 position toggle switch. Center tap to ground outer taps goto input pinA & input PinB. When you are set to A send 1ms pulses, when set to B send 2 ms pulses. You can use that setup to work through the initialization process.
if that document you linked to is relevant for your ESC then the initialization should be as follows (sorry I can't cut ans paste from the link)
with the ESC unpowered
myServo.write(0); // assuming this is what they mean by throttle stick to the bottom
power up the ESC
wait until the ESC makes all the right noises
then start driving your motor
I think you should have some arrangement to press a button on the Arduino to tell it the initialization process is complete in case you are slow at connecting the power to the ESC.
You also probably should have an LED on the Arduino to signal that the servo is at the 0 position because it doesn't do that the instant you switch on the Arduino.
Thanks! I've tried this and it works:
ESC unpowered
servo.writeMicroseconds(0);
power ESC
The ESC didn't make any noise at this step, so I sent 1000 microseconds. Then, the ESC made one beep, and I could start my motor.