Win a $100 for compiling the right code

Hi everyone. I have already posted in this forum about my problem. I am not mathematically minded so I am bashing my head against a brick wall. I need your guys expert help to get this code right for me and possibly win $100 for your effort and bragging rights. This is the problem.

I have a Hornet 60a ESC, arduino and a brushless outrunner motor. Basically I need to increase and decrease the speed with a a android app via bluetooth. All my circuitry connections are right. I cannot arm the motor properly.

Now you see my dilemma. I need the code for the arduino and can anyone suggest a good app for this project.

Lets see who can get this right.

PM me your answers and good luck

Rule #1 in engineering is separating problems

Don't mix up Bluetooth or android and identify your core issue: is that the arming sequence not working? There are many arduino code out there doing that. What did you try?

Hi there, It is arming now but when I switch on the the arduino my motor starts running. The speed control is not that good and it stutters a bit. I can switch the motor off with my app and when i close the app it still is operating. Here is my code. Maybe there is a simple way and maybe mine is to complex. any help would be much appreciated

#include <Servo.h>

#include <SoftwareSerial.h>

int incomingByte = 0; // for incoming serial data
int armingTime;
int pin = 9;
int counter = 0;
int pulseTime = 1100; //microseconds
boolean highSpeed = true;
Servo myservo;

void setup(){

Serial.begin(9600);

myservo.attach(9);

Serial.println(“Enter 0-9 to adjust motor speed.”);
Serial.println(“Enter h or l to change the speed range.”);
}

void loop(){

digitalWrite(pin, HIGH);
delayMicroseconds(pulseTime);
digitalWrite(pin, LOW);
delay(10-(pulseTime/1000));

if(Serial.available() > 0){
incomingByte = Serial.read();
}

//void incomingByte(){
//void readSerialVal(){

switch (incomingByte) {
case ‘0’:
setTimingParams(1100);
incomingByte=’*’;
Serial.print(“Throttle: “);
Serial.print((pulseTime-1100)/8);
Serial.println(”%”);
break;

case ‘2’:
setTimingParams(1300);
incomingByte=’*’;
Serial.print(“Throttle: “);
Serial.print((pulseTime-1100)/8);
Serial.println(”%”);
break;

case ‘3’:
setTimingParams(1400);
incomingByte=’*’;
Serial.print(“Throttle: “);
Serial.print((pulseTime-1100)/8);
Serial.println(”%”);
break;

case ‘4’:
setTimingParams(1500);
incomingByte=’*’;
Serial.print(“Throttle: “);
Serial.print((pulseTime-1100)/8);
Serial.println(”%”);
break;

case ‘5’:
setTimingParams(1600);
incomingByte=’*’;
Serial.print(“Throttle: “);
Serial.print((pulseTime-1100)/8);
Serial.println(”%”);
break;

case ‘6’:
setTimingParams(1700);
incomingByte=’*’;
Serial.print(“Throttle: “);
Serial.print((pulseTime-1100)/8);
Serial.println(”%”);
break;

case ‘7’:
setTimingParams(1800);
incomingByte=’*’;
Serial.print(“Throttle: “);
Serial.print((pulseTime-1100)/8);
Serial.println(”%”);
break;

case ‘9’:
setTimingParams(1900);
incomingByte=’*’;
Serial.print(“Throttle: “);
Serial.print((pulseTime-1100)/8);
Serial.println(”%”);
break;

}
}

void setTimingParams(int newPulseTimeVal){
if(highSpeed){
pulseTime = newPulseTimeVal;
} else {
pulseTime = 1025 + (newPulseTimeVal/10);
}
}

I would suggest you follow the user manual http://www.skyrc.com/index.php?route=product/product/download&download_id=5 to reset it to factory default and ensure you have adequate (i.e. Full) battery power when doing the setup (and connected to the motor, just remove propellers for safety if you have any attached)

Also in your code the closing } for if something is available on Serial should be after all the handling code afterwards otherwise you call that at every loop messing around with timing (you only set the invomungByte to '*' if the code had been matched, but the serial read will also hold CR or LF which you don't clear.

CHeck your PM. I tried to attach a file, but you can't do that in private messages so I had to include the whole thing. It's pretty short.

Man, that timing loop is just not going to be accurate. It depends on a delay that's truncated to ms, and the time it takes to read bytes off the serial will also factor into it.

replace this code:

 digitalWrite(pin, HIGH);
 delayMicroseconds(pulseTime);
 digitalWrite(pin, LOW);
 delay(10-(pulseTime/1000));

with:

// OUTSIDE THE loop(), IN YOUR ***GLOBAL VARIABLE DECLARATIONS***
uint32_t pulseChangeUs;

// INSIDE THE loop(), REPLACING THE CODE ABOVE

 if(digitalRead(pin) == LOW) {
   if(micros() - pulseChangeUs >= pulseTime) {
     digitalWrite(pin, LOW);
     pulseChangeUs += pulseTime;
   }
 }
 else {
  if(micros() - pulseChangeUs >= 10000L - pulseTime) {
     digitalWrite(pin, HIGH);
     pulseChangeUs += (10000L - pulseTime);
  }
 }

You may be able to imprive it a smidge by precalculating 10000-pulseTime and having two variables.

Note that pulseChangeUs is advanced by the time that should have elapsed, rather than the time that did elapse. This means that the timing ignores delays caused by serialRead

Note that I put 'Us' on the end of my varibales to indicate microseconds. This saves confusion.

Consider using a higher baud rate on your serial. You can see in the dropdown on the ardiuino serial monitor what baud rates it can cope with.

If this fixes your problem, the hunnert bucks goes to my paypal pmurray@bigpond.com :slight_smile: .