Go Down

Topic: How to configure an ESC with the ServoTimer2 library? (Read 207 times) previous topic - next topic

Marlon2106

Hi, my question is how can I boot a BLDC with an ESC's but using the ServoTimer2.h library. Thank you

Robin2

That library works the same as the standard servo library except that it only takes microsecond values - approx 1000 to 2000 corresponds to 0 to 180 degrees.

The exact sequence for arming your ESC will be in the user manual.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Marlon2106

#include <Servo.h>

int value = 0;

Servo ESC;

void setup() {
  // put your setup code here, to run once:

  ESC.attach(9);   
  Serial.begin(9600);   

}

void loop() {
 
 
  ESC.writeMicroseconds(value);
 
  if(Serial.available())
    value = Serial.parseInt();   

}


With this code the ESC is activated but when I change to servoTimer2 it is no longer activated, the code compiles me but it is not activated. Quito Microseconds and added Timer2 to Servo.

Robin2

You have value set to 0 and I suspect the standard stepper library is ignoring that and using a default value and, probably, the servoTimer2 library is not, or is using a different default value.

writeMicroseconds(0) is meaningless.

You have not said what the user manual describes for the arming process for your ESC.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Marlon2106

Usage on ESC simonk 30A, I'm new to this and I do not know how to calibrate it with arduino. The ESC did not come with its manual, I searched on the internet but I can not find how to program it with arduino.

Marlon2106

I was able to activate it, it was activated with a pulse of 2000. Now my problem is that I want to turn it on RF module and apparently the signal does not come or my code is wrong.
Could you check my code? Thank you.

transmitter:

#include <VirtualWire.h>

int value = 0;

void setup() {
  // put your setup code here, to run once:
    Serial.begin(9600); 
   

    // Se inicializa el RF
    vw_setup(2000); // velocidad: Bits per segundo
    vw_set_tx_pin(2); //Pin 2 como salida para el RF
}

void loop() {
  // put your main code here, to run repeatedly:
 
    if(Serial.available())
    value = Serial.parseInt();

    Serial.println(value);


    char buf[VW_MAX_MESSAGE_LEN];
    int dato1=value;
    String str="";

    str="i"+String(dato1);
    str.toCharArray(buf, sizeof(buf));
    vw_send((uint8_t *)buf, strlen(buf));
    vw_wait_tx();

    delay(200);
   

Receiver:

#include <ServoTimer2.h>
#include <VirtualWire_Config.h>
#include <VirtualWire.h>

int value=2000; // set values you need to zero
ServoTimer2 ESC; //Create as much as Servoobject you want.
         
void setup() {
  // put your setup code here, to run once:
   ESC.attach(9);    // attached to pin 9 I just do this with 1 Servo
   Serial.begin(9600);  // Debugging only
   

    // Se inicializa el RF
    vw_setup(2000);  // velocidad: Bits per segundo
    vw_set_rx_pin(2);    //Pin 2 como entrada del RF
    vw_rx_start();       // Se inicia como receptor

}

void loop() {
  // put your main code here, to run repeatedly:

  ESC.write(value);

    // Parse an Integer from Serial
 
    uint8_t buf[VW_MAX_MESSAGE_LEN];
    uint8_t buflen = VW_MAX_MESSAGE_LEN;
    int value;
   
    //verificamos si hay un dato valido en el RF
    if (vw_get_message(buf, &buflen))
    {
  int i;
  String DatoCadena="";
  if((char)buf[0]=='i')  //verificamos el inicio de trama
  {
 
  for (i = 0; i < buflen; i++)
  {
      DatoCadena.concat((char)buf);
  }
  value=DatoCadena.toInt();
 
    }

}
}


Muchas gracias por tu tiempo.

Robin2

Please modify your post and use the code button </>
Code: [Select]
so your code looks like this and is easy to copy to a text editor. See How to use the Forum Your code is too long for me to study quickly without copying to a text editor.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Go Up