Drive a brushless motor with an Arduino and ESC

Hello,

for my project (trying to build a small car and later on a ship) I want to drive a powerful (brushless)motor via the Arduino. In order to do so, I need an ESC. As my father was a bit into Model cars and stuff, he has some ESCs and Brushless motors lying around that I can use.

I started off trying to find information on how to use the parts I have to get the motor working. In my understanding I have to send values to the ESC just like with a servo motor. I read as well that the cabling was the same (to the ESC). So I went ahead and connected everything as the following:

Motor (two cables, not brushless) to ESC (thick wires). ESC to battery (LiPo Battery, also two thick wires). Three thin chords from the ESC: white in the PWN pin on my Arduino, black in ground and red into the 5V.
This was all a couple weeks ago. With my Graupner SC-2001 ESC and a motor which I have no information about, I remember that The motor would either spin on full speed or not at all, but only if connected to the Arduino.
I think I used this example sketch:

#include <PWMServo.h>

PWMServo myservo;  // create servo object to control a servo

int pos = 0;    // variable to store the servo position

void setup() {
  myservo.attach(SERVO_PIN_A);  // attaches the servo on pin 9 to the servo object
  //myservo.attach(SERVO_PIN_A, 1000, 2000); // some motors need min/max setting
}


void loop() {
  for(pos = 0; pos < 180; pos += 1) { // goes from 0 degrees to 180 degrees, 1 degree steps
    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
  }
}

So today I tried the same thing again. Well, and there it goes: I started the program and the connection was bad so I fixed it. The moment the connection was good, the motor started (in contrast to what I remember,) spin slower, maybe even speed up and slow down, but then it started to smell bad and a bit of smoke came out of the motor.
Afterwards, I feel like the dumbest person, not having asked anyone earlier, but well it is how it is. I hope I did not destroy anything other than the motor. I still want to test the motor though, but not by completely ruining it. Is it safe to connect the old 2,4GHz remote and then try to test the motor?

My question is: How can I control a motor with an Arduino? I still have a Modelcraft Hurricane Pro ESC in combination with a Modelcraft Hurricane 12 T brushless motor. I do not, however, want to damage these parts as well.

If you need any more information like pictures, I definitely can provide those.

Thank you for your answers and ideas. I do appreciate them!

Have you tried to use a brushed motor with a brushless ESC? Game over if so, completely and utterly
incompatible, something fries rapidly if you do that.

So far I have not, but thank you for pointing that out.
I have only used the ESC in combination with the whole set I got it from (so like from a RC car, plane, etc.)

Thanks!

One easy way to cook a brushless ESC/motor is to have one of the three wires not properly connected.
This confuses the controller and it puts full current into the other windings without the motor turning...
Full current is enough to destroy motor and ESC if there is no back EMF from the rotor spinning.

Thanks for your reply.

I am sorry, I might have been imprecise. The motor I probably fried, is not a brushless one. It only has two wires connected to the esc.
Also I am pretty sure, I had good connections then. But of course, can't guarantee that.

Hmmm, brushed ESCs ought to be more fool proof unless you physically stall the motor.

I'm not sure if it is causing the problem but just for interest why are you using the old PWMServo library rather than the more modern Servo.h ? That sketch seems to be an out-of-date version of the current Sweep example included with the IDE. Exactly which pin did you have it connected to? I believe that library only works with pin9 or 10 (on Uno/Nano).

OTOH smoke out of the motor does sound like you have a more serious problem somewhere.

Steve

Ehm...
Good question, not sure why. Probably did not see it.

I had it connected to Digital Pin 9.

Yes I am a little bit confused, too. Especially because you would think the ESC would be damaged, not the motor. In different forum, someone suggested that the motor might just be old (it actually is) and has short circuited somehow. Does that sound realistic to you?

Possible. ESCs are typically very very low on-resistance, 2 or 3 milliohms, so most of the heat
should go into the windings (which might be 50 to 200 milliohms).

Well, now it is getting interesting.

So I tried the old motor (the not brushless one) and its still working!

But it is getting tricky: In the other forum, someone told me I would have to calibrate the Modelcraft Hurricane Set (ESC + Motor). In order to do so I downloaded the data sheet, which says how to calibrate it.
So I went ahead and wrote some code so I could calibrate by pressing a button to make the Arduino write three different values on the servo pin (180, -180, 0). Then I put the ESC in calibration mode, which seemed to work (the LED lighted up, just like it was described in the manual), and pressed the button. This seemed to work as well. The LEDs showed me that the maximum (180) was received. I was then distracted and did not do anything, but when I looked back at the ESC it showed me some weird LED sign, indicating it finished the calibration?!
I thought this was no big deal, as I could just recalibrate the ESC. But no. I can't get it back in calibration mode.
I also tried the old RC on a 2,4 GHz band and that still worked. But I could not get the ESC back in calibration mode.
Then, I thought, well maybe it is somehow calibrated. So what I tried next is, to just run the Sweep program. Unfortunately nothing happened.
Someone in the other forum told me that this motor model needs to be controlled with a PWM frequency between 50Hz and 400 HZ. Standard for the Arduino Uno is apparently 490Hz. That, I thought, might be the problem. Well, now I am and of stuck with how to change the PWM frequency on pin 9 (and then 10 as those seem to have the same timer).
According to some websites you have to use this code

TCCR1B = TCCR1B & B11111000 | B00000011;

or, what I found alternatively is this:

TCCR1B = TCCR1B & B11111000 | 0x04;

in order to set the PWN frequency to something like 125HZ.

I would really appreciate any help! Thank you!

I would think that using a potentiometer would be easier to control input. Print out the values you are sending to the ESC so that you can get a feel for the values you will need when your program automated the process alter.

Why are you sending -180? That is not a valid value. It gets constrained to 0-180 by the servo library.

Someone in the other forum told me that this motor model needs to be controlled with a PWM frequency between 50Hz and 400 HZ. Standard for the Arduino Uno is apparently 490Hz.

You, they or both are confused.
The communication between the arduino and the ESC is a servo signal. The arduino and servo library know all about that and you do not need to do anything else to make that communication work once you have the calibration and any arming sequence figured out.

If this works properly with your RC receiver, you can make it work with the arduino.

Thank you for your answer.

vinceherman:
You, they or both are confused.

Yes, I am definitely confused by a lot of things with Arduino... Well, trying to figure it out is I guess the only way to step forward.

vinceherman:
I would think that using a potentiometer would be easier to control input. Print out the values you are sending to the ESC so that you can get a feel for the values you will need when your program automated the process alter.

Why are you sending -180? That is not a valid value. It gets constrained to 0-180 by the servo library.

Well, thank you for pointing that out - I did not have a clue.
So , next time I will be using values from 0 to 180. Does that make sense? (max = 180, neutral = 90 and back max = 0)

vinceherman:
The arduino and servo library know all about that and you do not need to do anything else to make that communication work once you have the calibration and any arming sequence figured out.

Sounds great. But what exactly is an arming sequence? Is that the same as the calibration?

vinceherman:
I would think that using a potentiometer would be easier to control input. Print out the values you are sending to the ESC so that you can get a feel for the values you will need when your program automated the process alter.

Last time a friend and I did that, but he somehow fried the ESC I think... That's why I did not want to try that again. I am gonna look into that though.

vinceherman:
If this works properly with your RC receiver, you can make it work with the arduino.

That would be awesome!
Thanks for your answers.

Hi,

so I got it to calibrate (I think): I now used three buttons in order to write the values to the pin.
I also found out that the value 0 and 1, does not work: When trying to add those as the lowest value, the ESC just does not accept it. Something over 90 seemed to work so these are my new values: 300, 200, 100, and they worked. The ESC allowed me to calibrate it with the Arduino.
Unfortunately though, it seems like something somewhere went wrong. When I tried the Sweep code (its up in my first post, and yes I changed the values to min 100 and max 300) the motor started spinning after the first time counting up from 100. It got faster (I think) up to about 180 or something and then just turned off. That was it. It did NOT turn on coming the other way, but it did again spin when coming up from 100 to about 180.
Does anyone have any explanations for that?
Don't quite understand what is going on (once again), but might just try calibrating again and again.

Thanks anyway for the help, I might be getting somewhere with this sooner or later...

Let's see the code that produced this behavior.

Is this still the old brushed motor or have you moved on to the brushless motor in your title?

Are you still using PWMServo?

Steve

Hi,

I am sorry for not replying to the new posts, but I have been on vacation.

I am now using the brushless motor. After having forgotten, what exactly I did with them, I tried the motor again and it seems to work like this:
Between 175 and 171 it spins backwards. 170 is off. 169 to 103 makes the motor go faster. However, I believe, every 7th and 8th value slows the motor just a bit down.

I'll play around with it, but at least it is working now.
Thanks for the help!