HELP - BLDC, ESC and Arduino nano

Hello,

I’m new to this forum and the world of Arduino.

I’m trying to control a BLDC hub motor using arduino and ESC.
The parts I use are:
Motor -

ESC-

and arduino nano.

I have set the connection between ESC and the nano like in the attached pic and the code is something I found on the internet, (pretty simple. When I read the actual class method, it set the default values to 1000-2000 when 1500 is natural point and then basically the idea is to send value over 1500 for forward and under 1500 for backward).

My problem is that the motor is NOT moving in both directions on the same run.

One interesting issue I’ve found is, if I set the speed below 200 (esc.setSpeed(150):wink: and then I shutting down the ESC and starting again, it will CHANGE direction! It happen everytime I shut down and start.

If the value is over 200 then it keep moving the same direction after restart. I couldn’t figure out why it does that.

I’ve also uploaded the data sheet for the ESC.

I’ll appreciate any help as I’m trying to solve this for two weeks already…

The code is
#include <Servo.h>
#include “ESC.h”

/* This example shows how to use an ESC controller that can go

  • forward and backard
    */

ESC esc(ESC::MODE_FORWARD_BACKWARD);

void setup()
{
esc.attach(12);

}
void loop()
{
esc.setSpeed(0);
esc.setDirection(ESC::FORWARD);
esc.setSpeed(150);
delay(3000);
esc.setSpeed(0);
esc.setDirection(ESC::BACKWARD);
esc.setSpeed(150);
delay(3000);

}

Can you please provide a link to where you got the ESC library ?

Hi,

Here is the link to the library

There is a dup post by mistake as I wanted to add the attachment..

If you click on "Report to moderator" you can ask for the 2 threads to be merged.

I have looked at the library and don't see the point of it. Why not simply use the normal Servo library ?

You are correct. It is just a shell for the servo.

The fact is when I tried also with the servo class I didn’t managed to make it go both ways.

Can you maybe help with the code?

Can you maybe help with the code?

Sorry, no.

Have you looked at the manual for the ESC ?

It looks like you are going to have a hard time using the Arduino to set it up the way that you want. Your best bet would probably to buy a programming cards for it then you could use the Arduino to control it.

From the datasheet the default mode of that ESC needs the motor to be stopped between forward and reverse movement. Going straight from forward to reverse applies the brake.

If you do it with Servo then something like writeMicroseconds(2000), writeMicroseconds(0) (to brake to a stop) followed by writeMicroseconds(1500) might work. Any further writes less than 1500 should run in reverse.

Probably the easiest way to get the sequence right would be just to use the Knob example from the IDE and test exactly what moves are needed.

Steve

Update -

I’ve managed to program the ESC with the KEY button. Changed the code to add a delay for the ESC to read the neutral position in between forward and reverse and now it works :slight_smile:

I just need to better calibrate the stop as it stop at once…

New code:
#include <Servo.h>
#include “ESC.h”

/* This example shows how to use an ESC controller that can go

  • forward and backard
    */

ESC esc(ESC::MODE_FORWARD_BACKWARD);

void setup()
{
esc.attach(12);
esc.setSpeed(0);
delay(1000);
}

void loop()
{

esc.setDirection(ESC::FORWARD);
esc.setSpeed(180);
delay(2000);
esc.setSpeed(0);
delay(1000);
esc.setDirection(ESC::BACKWARD);
esc.setSpeed(180);
delay(2000);
}

Thanks