Pages: [1]   Go Down
Author Topic: Brushless motor control via Serial  (Read 990 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 25
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
// 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);
  }
Logged

Red Sea, Saudi Arabia
Offline Offline
God Member
*****
Karma: 12
Posts: 579
..On The Red Sea
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Let us know!

Logged

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

0
Offline Offline
Newbie
*
Karma: 0
Posts: 25
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Pages: [1]   Go Up
Jump to: