I'm using an Uno to control the motor, this is the code :
Code: Select all
#include <Servo.h>//Using servo library to control ESC
Servo ESC; //Creating a servo class with name as esc
int throttle = 0; //Variable for the throttle setting.
#include <PSUSB.h>
// Satisfy the IDE, which needs to see the include statment in the ino too.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#endif
#include <SPI.h>
USB Usb;
/* You can create the instance of the class in two ways */
PSUSB PS(&Usb); // This will just create the instance
//PSUSB PS(&Usb,0x00,0x15,0x83,0x3D,0x0A,0x57); // This will also store the bluetooth address - this can be obtained from the dongle when running the sketch
bool printAngle;
uint8_t state = 0;
void setup()
{
Serial.begin(115200);
while (!Serial);
Serial.println("Connect ESC");
delay(2500); //Allow the user...........time to connect the battery to the ESC.
ESC.attach(8,600,2250);
throttle = 180;
Serial.println("Setting throttle to max");
ESC.write(throttle);
delay(2500);
throttle = 0; //Set the throttle to zero
Serial.println("Setting throttle to min");
ESC.write(throttle); //Set the ESC signal to the zero position.
delay(2500); // allow a delay for the ESC to signal that it is done.
throttle = 90; //Set throttle to the neutral position.
Serial.println("Setting throttle to neutral");
ESC.write(throttle);
delay(2500);
Serial.println("Done");
delay(2500);
#if !defined(__MIPSEL__)
while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
#endif
if (Usb.Init() == -1) {
Serial.print(F("\r\nOSC did not start"));
while (1); //halt
}
;Serial.println("PSUSB Library Started");
;delay(1500);
}
void loop()
{
int val;
Usb.Task();
//Serial.println(F("\tLeftHatY: "));
//Serial.println(PS.getAnalogHat(LeftHatY));
val=PS.getAnalogHat(LeftHatY);
val= 180-map(val,0,255,1,180); //mapping val to minimum and maximum(Change if needed)
if (val<4) val=4;
Serial.println(val);
ESC.write(val);//using val as the signal to esc
}
Previously this setup was working (i've tried since with 3 different units of the same ESC with same result), but i'd left it on the bench since September and now it just beeps.
If it was working before that means my PWM settings are correct, what else could it be?
Do ESCs lose their programming after a while, should i find my card and check that?
Image attached to show wiring.
Thanks for any help, Gary :)