Steady "on" while controlling ESC with Servo Lib.


I am trying to control a brushed speed controller using the Servo library. Using the sweep example, and following other tutorials, I came up with this slimmed-down code. The problem is, I don’t know what parts of the code control what. When I increase the delay, it takes longer to ramp up. When I change what I think is the max speed, it seems like the pulses to the motor are longer. Why do I need the part where it counts up from the min to max speed? Is there any way to set the motor to “on at full power” or just “on at half power?”

#include <Servo.h>

Servo ESC;  //name the servo object ESC

int pos = 0;
int minspeed = 0; //set the minimum speed
int maxspeed = 180; //set maximum speed

void setup()
  ESC.attach(9); //attach the ESC to pin 9 

void loop() 
  for (pos = minspeed; pos < maxspeed; pos += 1) //from the lowest speed to the highest speed in steps of 1?
    ESC.write(pos); //turn on the ESC??
    delay(5); // No idea...

ESC.write(180); //full power
ESC.write(90); //half power

Note that motor output is likely not linearly related to ESC throttle command.

ESC.write(180); //full power
ESC.write(90); //half power

Makes sense. The thing I am most frustrated about is that I can't get just an on or off.

Instead, the motor ramps up and down and is jerky. Is it the delay? Is it the "for?"

Is there any way to do that? I just want the motor to be on full power, from the beginning, all the time.

OK, so writing 90 gives half power and 180 gives full power. Writing a 0 would turn it off. All the numbers in between write speeds in between those.

Now you have a for loop that was originally intended to slowly move a servo from 0 to 180. It writes, one after another, 1, 2, 3, 4, 5 etc. to the servo. It writes those numbers to your ESC. So it ramps up in speed. If you just want to turn it full-on or full-off then just write a 0 or a 180 to it.

I would not expect the motor response to be jerky. Can you describe that some more?
Oh, something that often catches people out. There is often an arming sequence with ESCs. Without this arming sequence, the ESC will not 'arm' itself and start sending power to the motor.
The sequence is often power up at zero throttle. (some times the ESC will beep here)
Go to full throttle for some small amount of time. (some times the ESC will beep here)
Go to zero throttle for some amount of time. (some times the ESC will beep here)
Now the ESC will respond to all throttle commands.

Your sweep sketch did just this, so it works. If you modify the code, the ESC might not arm.
So you might need a way to do this. Maybe in setup, run through the arming sequence. Maybe give the user some way to trigger the arming sequence.