Go Down

Topic: motor code error (Read 3 times) previous topic - next topic

AWOL

I have no idea.
What are you trying to do?
What does your code look like?
What does it do that you don't want it to, and what doesn't do that you do want it to?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

arduinosoccer33k

I need the PWM TO BE 2500
zoomkat gave me the code below. It does not do anything but was the best help  I've had so far. he said that I put the values for angle milliseconds, etc in the serial monitor but when I do, nothing happens just my esc's beeps change each time i type in a number

// zoomkat 10-22-11 serial servo test
// type servo position 0 to 180 in serial monitor
// or for writeMicroseconds, use a value like 1500
// for IDE 0022 and later
// Powering a servo from the arduino usually *DOES NOT WORK*.

String readString;
#include <Servo.h>
Servo myservo;  // create servo object to control a servo

void setup() {
  Serial.begin(9600);
  myservo.writeMicroseconds(1500); //set initial servo position if desired
  myservo.attach(7);  //the pin for the servo control
  Serial.println("servo-test-22-dual-input"); // so I can keep track of what is loaded
}

void loop() {
  while (Serial.available()) {
    char c = Serial.read();  //gets one byte from serial buffer
    readString += c; //makes the string readString
    delay(2);  //slow looping to allow buffer to fill with next character
  }

  if (readString.length() >0) {
    Serial.println(readString);  //so you can see the captured string
    int n = readString.toInt();  //convert readString into a number

    // auto select appropriate value, copied from someone elses code.
    if(n >= 500)
    {
      Serial.print("writing Microseconds: ");
      Serial.println(n);
      myservo.writeMicroseconds(n);
    }
    else
    {   
      Serial.print("writing Angle: ");
      Serial.println(n);
      myservo.write(n);
    }

    readString=""; //empty for next input
  }
}

arduinosoccer33k

ALL i NEED TO DO IS TO GET THE MOTOR TO SPIN
(i FORGOT TO MENTION THAT IN MY LAST POST)

AWOL

#38
Jan 05, 2013, 04:20 pm Last Edit: Jan 05, 2013, 04:25 pm by AWOL Reason: 1
Quote
It does not do anything

What do you mean by that?
You are entering numbers in the serial monitor, aren't you?

( when posting code, please use code tags, and please don't SHOUT)

This
Code: [Select]
if(n >= 500)
    {
      Serial.print("writing Microseconds: ");
      Serial.println(n);
      myservo.writeMicroseconds(n);
    }
    else
    {   
      Serial.print("writing Angle: ");
      Serial.println(n);
      myservo.write(n);
    }
isn't really necessary; the Servo library does it for you - any value sent to the Servo write method greater than about 540 is automatically sent to the writeMicroseconds method.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

arduinosoccer33k

lIm entering numbers like 1500 and 180,etc.
Nohthing happens except the ESC beeps. The motor does not spin.
It is giving really akward beeps now.
The capitals are accidental and I only realize it when it is too late
sorry for the long wait

Go Up