What I am trying to do is run the motor for period of 5 seconds and then shutdown but the motor runs much longer. How do you tell the ESC to stop? I've tried different write angles of 0 and 90 to avail. Any ideas?
I recall reading somewhere that an esc stops with a 1000us pulse. (That may be nonsense; I've never use an esc and wouldn't know one if I tripped over it, ymmv.)
Try a myservo.writeMicroseconds() with a variety of values around 1000 to see if it stops.
The throttle on a RC transmitter is not home position at gymbal center but home at the lower end of the gymbal travel.
The normal end-to-end range for a RC transmitter pulse width is from about 1000 microseconds (or 1 millisecond) to 2000 us (2 ms) for a 90 degree sweep of the servo motor. Many servos can be overdriven using a range 500-2500 us to give a 180 degree sweep, but the radio won't generally do it.
As per leandra_reis' suggestion, try setting the ESC to send pulses at 1000us. If that fails, try 500us.
The complete code would be a lot more useful as would details of what ESC/motor you're talking about.
Generally write(0) will stop the ESC/motor (or maybe write(90) if it's a reversible ESC). Just doing a detach() will not because it just no longer sends a signal. The ESC may or may not get round to stopping the motor when/if it notices that it's lost signal.
I'll try again. Please post the COMPLETE code. SOmething that compiles and runs. Odd lines of code with no context are useless.
I'll guess much of what you posted is in loop(). If so where in the code did you try the write(0) or write(90)? And what did you do to stop it looping straight round and starting the motor up again immediately after it had stopped?
# include <Servo.h>
Servo ESC; // declare ESC
int run_time = 1600; // run time of motor in milliseconds
void setup() {
// put your setup code here, to run once:
ESC.attach(6); // attach ESC input to pin 6 (PWM)
delay(1); // delay for stabilization
ESC.write(40); // initialize ESC
delay(1); // delay for stabilization
}
void loop() {
// put your main code here, to run repeatedly:
ESC.write(180); // fire up fan at full speed
delay(run_time); // fan runs <run_time> milliseconds
ESC.write(0); // turn fan off
delay(60000); // leave fan off for delay in milliseconds
}
Hook a 10k pot to an analog input pin.(5V,A0,Gnd) Map the result to -->> 0..180. Serial print() that value, then drop it into the ESC.write() method. Then, you will see what values give you what response. Leave out the delay()s.
So that's completely different from your original code snippets. What does this version actually do?
Where did you get the write(40) from as an intialisation value? And even if that makes sense a delay of 1 millisecond is nowhere near enough time for an ESC to initialise.
The initialize(40); piece of code was something that I grabbed from someone else's code. I was told it is a setting lower than a setting to start the motor turning. It is supposed to initialize (wake up) the ESC. What I am trying to do is have the fan go full blast for a short fixed time (like 1-2 seconds) then shut off completely. I did calibrate the ESC according to the manual but was unable to set any values. I could select programmable items (no problem) but I could not set the values. It did not give me the choices of 1-2-3 beeps to select a value. I wanted to set brake 'ON and 'cut-off.
So, what I am trying to do is have the fan go full blast for a short fixed time (like 1-2 seconds) then shut off completely. Any suggestions?
You keep saying what you WANT to do but, despite being asked, you never detail what it is that your current code actually does now. We're not looking over your shoulder so we can't tell what happens.
What the program is doing is the motor comes on...no problem. It then runs much longer (5-10 seconds) than the 2 seconds I have programmed and then slows down for another 5-10 seconds. then stops. I think the slow down is the ESC setting for a Soft-Cutoff which I can't seem to program a cut-off in the ESC. I'm working on that. I can select the programmable items but I am not offered the program values to select from the manual. I have a Skywalker 40A-UBEC controller.
I'm more concerned with the time the motor is running full blast before the cut-off. I have changed the values of the delay for running but it doesn't seem to change anything. It still runs 5-10 seconds when I want it to run 1-2 seconds.
#include <blinker.h>
#define ESC_PIN 6
blinker ESC(ESC_PIN,2,18); // The ESC square wave set to 2 ms every 18 ms
int run_time = 1600; // run time of motor in milliseconds
void setup(void) {
ESC.setOnOff(false); // Shut it off..
}
void loop(void) {
idle(); // Runs the background stuff.
ESC.setOnOff(true); // Fire it up.
sleep(run_time);
ESC.setOnOff(false); // Shut it off..
sleep(60000.0);
}
I'm not SURE it'll work. But I'm betting it will. You'll need to install LC_baseTools from the library manger to make it compile.
First off...thank you. I think that the library (LC_Basetools) will come in handy. Thank you for writing it. I tried the code and it didn't work...but I think it will provide a solution. I think the ESC requires it has a 1mS 50Hz pulse when it is initialized. Then, to turn it on, it should receive a 2mS 50Hz pulse to run. Then, it reverts to the original state of a 1mS 50Hz pulse. With your coding suggestion, I think I can now work up something. Thank you.
I think it will provide a solution. I think the ESC requires it has a 1mS 50Hz pulse when it is initialized. Then, to turn it on, it should receive a 2mS 50Hz pulse to run. Then, it reverts to the original state of a 1mS 50Hz pulse.
I saw it on a video about servo motors. I’m not saying it is fact but when I used the servo library and initialized the ESC, there was a 1mS 50Hz pulse. When I sent a signal to start the motor, a 2mS 50Hz pulse was sent to ESC. From my experience, albeit limited, it seems to be correct. Am I wrong? If I am, what signal to the ESC does start the motor? I know it’s not a high signal.