i command an esc with servo.h and writemicroseconds istruction.
the motor is in a 90mm edf fan and esc is a super simple 100a from rcs.
problem is that it takes 2 seconds for changing speed in any moment.
i use 800/900 for start the engine and less than 2000 for max speed. with 2000 microsec the esc go in programming mode
ive checked all the code and there's no delay.
#include <Servo.h>
// Arduino digital pins
#define BUTTON_PIN 2
#define LED_PIN 13
int potpinpan = 0; // analog pin used to connect the potentiometer
int potpintilt = 1;
int potpinesc = 2;
int valpan; // variable to read the value from the analog pin
int valtilt;
int valesc;
int mod = 11; //dividendo di controllo
int maxpanangle = 150;
int maxtiltangle = 110;
int maxesc = 179;
int minesc = 0;
int escpin = 2;
String comando;
Servo esc;
// Button hardware is setup so the button goes LOW when pressed
#define BUTTON_PRESSED LOW
#define BUTTON_NOT_PRESSED HIGH
void setup()
{
pinMode(BUTTON_PIN, INPUT);
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, LOW);
esc.attach(escpin);
Serial.begin(1200); // Hardware supports up to 2400, but 1200 gives longer range
}
void loop()
{
if(Serial.available())
valesc = Serial.parseInt(); // Parse an Integer from Serial
esc.writeMicroseconds(valesc);
if (valtilt<30) {
digitalWrite(LED_PIN, HIGH);
}
else {
digitalWrite(LED_PIN, LOW);
}
//delay(100);
}
You're using pins 0 and 1 to talk to pots but also of course they get used for the monitor... may not be the cause of your problem, but it's not right.
JimboZA:
You're using pins 0 and 1 to talk to pots but also of course they get used for the monitor... may not be the cause of your problem, but it's not right.
simple servo test code for use with the serial monitor. You can send commands and see if the speed change is delayed with this code.
// zoomkat 10-14-11 serial servo test
// use a microseconds value like 1500 in serial monitor
// for IDE 0022 and later
// Powering a servo from the arduino usually DOES NOT WORK.
String readString;
#include <Servo.h>
Servo myservo; // create servo object to control a servo
void setup() {
Serial.begin(9600);
myservo.writeMicroseconds(800); //set initial servo position if desired
myservo.attach(7); //the pin for the servo control
Serial.println("servo-test-22"); // so I can keep track of what is loaded
}
void loop() {
while (Serial.available()) {
char c = Serial.read(); //gets one byte from serial buffer
readString += c; //makes the string readString
delay(2); // allow buffer to fill with next character
}
if (readString.length() >0) {
Serial.println(readString); //so you can see the captured string
myservo.writeMicroseconds(readString.toInt()); //convert readString to number for servo
readString=""; //empty for next input
}
}