Running brushed ESC with arduino

Hi guys,
I’m currently working on a little project that will have my kids ride on car being able to be controlled by me with one hand using the thumb joystick.

The first stage is complete, i have used an r/c esc and transmitter to control the car,
Now i want to use arduino- which opens me up to a heap of different control methods.

Ive connected the esc to the arduino and used a pot along with the servo library file to test what signals control the ESC.

So far i have found that from 600-1500 microsecond pulses are reverse signals, 1500 being the neutral. And 1500-2000 is forward.

So all works fine so far except the ESC has a safety system in place that wont allow you to go from forward to reverse.
So basically once the pulse has gone over 1500, any subsequent pulse under 1500 has no effect.

The way to get around it is to go under 1400 then back up to 1500 for a brief pause- then the motor will reverse.

This happens every time a pulse over 1500 is sent.

Im not the best with coding so im wondering if there could be a simple if/then/else statement put in there somewhere to get around this…

The following is the code i have used:

#include <Servo.h>
Servo ESC; // create servo object to control the ESC
int potValue; // value from the analog pin
void setup() {
// Attach the ESC on pin 9
ESC.attach(9);(pin)
Serial.begin(9600);
ESC.writeMicroseconds(1000);
}
void loop() {
potValue = analogRead(A0); // reads the value of the potentiometer (value between 0 and 1023)
potValue = map(potValue, 0, 1023, 610,2000); // scale it to use it with the servo library (value between 0 and 180)
ESC.writeMicroseconds(potValue); // Send the signal to the ESC
Serial.println(potValue);
delay(50);
}

ARDUINOBOARD-Layout1.pdf (9.87 KB)

I wouldn’t call it exactly simple but first let’s see if I’ve understood your requirement.

If the last write to the servo was >1500 (forward) and the new value you want to write is <=1500 (reverse)

  • before writing that value you need to initialise reverse mode
  • to do that you write a value < 1400 pause write exactly 1500 and pause again
    (if you’ve been doing it manually you won’t know how long the pauses need to be so try 1/2 second)
  • then you can write the reverse value <= 1500 that you wanted to originally.

Presumably once you’ve gone through the ‘initialise reverse mode’ rigmarole you can carry on sending various values <=1500 as you wish?

Are you sure there is no problem going from reverse (<=1500) back to forward again? That’s at least as bad for the ESC/motor as going from forward to reverse.

If that’s right you will need to remember the last thing you wrote to the motor. Pseudocode might be something like:
// I don’t like using the same variable for different things so the output of your map shouldn’t be potValue
// I’ve called it writeValue

if lastWrite > 1500 and writeValue <=1500
{
initReverse()
}
then write (writeValue)
set lastWrite = writeValue

// function definition
initReverse()
{
write(1000)
delay(500)
write(1500)
delay(500)
}

Or something like that.

Good luck - Steve

Thanks mate, yeah im sure there isnt a problem going from reverse to forward, as im using a potentiometer to vary the pulse signal and tested it out many times.
I would imagine it would be as damaging either way.

Im not sure the delay that is required but just through experimenting i found that if i brought it down to 1450 then back up to 1500 then it will reverse when i go back down below 1500.

But i think youre right in maybe i have to make a forward and reverse routine and if its reverse then i can bring it down to 1450 and back up to 1500 before reading the pot value again.

What ESC are you using and have you checked its documentation? Some ESCs have different modes that you can set. It's possible that something other than the default mode would be easier to manage.

Steve

Hi,
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".
OR
http://forum.arduino.cc/index.php/topic,148850.0.html.
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom... :slight_smile: