Go Down

Topic: Brushless motor control via Serial (Read 1 time) previous topic - next topic

acecombat

Hi,

I'm trying to drive a brushless motor via an ESC which worked fine, now I am trying to have it read data from serial and control the motor with the serial data but I'm having a problem.

After it inits it sits there idle, then after sending a value to the com port it goes to the speed for the duration of Delay() but then no more.

The code is messy (I haven't done a whole lot with the Arduino) as it's got bits and pieces from different projects/posts
Code: [Select]
// this uses the Arduino servo library included with version 0012

// caution, this code sweeps the motor up to maximum speed !
// make sure the motor is mounted securily before running.

#include <Servo.h>
int serspeed = 0;

Servo myservo;

void arm(){
  // arm the speed controller, modify as necessary for your ESC 
  setSpeed(30);
  delay(1000); //delay 1 second,  some speed controllers may need longer
}

void setSpeed(int speed){
  // speed is from 0 to 100 where 0 is off and 100 is maximum speed
  //the following maps speed values of 0-100 to angles from 0-180,
  // some speed controllers may need different values, see the ESC instructions
  int angle = map(speed, 0, 100, 0, 180);
  myservo.write(angle);   
}

void setup()
{
  myservo.attach(12);
  arm(); 
  Serial.begin(9600);
  pinMode(serspeed, OUTPUT);
}


void loop()
{
    serspeed = Serial.read();
    setSpeed(serspeed);
    delay(1000);
  }


Terry King

Hi,
I think you need to check if Serial has data available. Otherwise your SerialRead may return 0??

Let us know!

Regards, Terry King  ..On the Red Sea at KAUST.edu.sa
terry@yourduino.com  LEARN! DO! (Arduino Boards, Sensors, Parts @ http://yourduino.com

acecombat

It has to have some data because the first value I enter starts it up for the delay period.
I'm using the serial monitor in arduino.  How can I check to make sure it is sending?

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy