Pages: [1]   Go Down
Author Topic: help servo motors  (Read 2601 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi there, i dont hnow where to post this, so I post it here smiley

i want to control this servo motor http://www.servodatabase.com/servo/hextronik/hxt900 with Arduino board -uno. i was trying library Servo.h (just copy&paste code that was there). It doesnt work.
than i thought that servo motors behave just like potenciometer , only middle is not output but input, so I connect to digital 9(PWM) and i thought that it's working - it was moving , but cant control it - for example with potentiometer and servo was very hot after my experimetns smiley
any idea how to conquer that beast ? smiley
sorry for english. 
Logged

I like Arduino !

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

i try this before I establish? this topic. it's not working at all.
I try this code:
Code:
int t=0;
int d=5;
void setup(){
  pinMode(9,OUTPUT);
}

void loop(){
   analogWrite(9,t);
   t = t + d;
   if (t == 0 || t == 255)
     d=-d;
   delay(21);
}
it's better than nothing , but it's not fully working.
Logged

I like Arduino !

0
Offline Offline
Tesla Member
***
Karma: 141
Posts: 9470
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Some simple servo test code you can try.

Code:
// zoomkat 10-4-10 serial servo test
// type servo position 0 to 180 in serial monitor
// for writeMicroseconds, use a value like 1500
// for IDE 0019 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.attach(7);  //the pin for the servo control
  Serial.println("servo-test-21"); // so I can keep track of what is loaded
}

void loop() {

  while (Serial.available()) {
    delay(10); 
    if (Serial.available() >0) {
      char c = Serial.read();  //gets one byte from serial buffer
      readString += c; //makes the string readString
    }
  }

  if (readString.length() >0) {
    Serial.println(readString);  //so you can see the captured string
    int n;
    char carray[6]; //converting string to number
    readString.toCharArray(carray, sizeof(carray));
    n = atoi(carray);
    myservo.writeMicroseconds(n); // for microseconds
    //myservo.write(n); //for degees 0-180
    readString="";
  }
}

Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

0
Offline Offline
Newbie
*
Karma: 0
Posts: 16
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for your example.

How it can be modified to rule more than just one servomotor?

I'm using Arduino Uno and I don't find any example about how to rule up to 5 or 6 servomotors with the serial monitor.

Have a nice day
Logged

0
Offline Offline
Tesla Member
***
Karma: 141
Posts: 9470
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
How it can be modified to rule more than just one servomotor?

Some simple test code for two servos:

Code:
// zoomkat 11-22-10 serial servo (2) test
// for writeMicroseconds, use a value like 1500
// for IDE 0019 and later
// Powering a servo from the arduino usually DOES NOT WORK.
// two servo setup with two servo commands
// send eight character string like 15001500 or 14501550

#include <Servo.h>
String readString, servo1, servo2;
Servo myservo1;  // create servo object to control a servo
Servo myservo2;

void setup() {
  Serial.begin(9600);
  myservo1.attach(6);  //the pin for the servo control
  myservo2.attach(7);
  Serial.println("servo-test-21"); // so I can keep track of what is loaded
}

void loop() {

  while (Serial.available()) {
    delay(10); 
    if (Serial.available() >0) {
      char c = Serial.read();  //gets one byte from serial buffer
      readString += c; //makes the string readString
    }
  }

  if (readString.length() >0) {
      Serial.println(readString); //see what was received
     
      // expect a string like 07002100 containing the two servo positions     
      servo1 = readString.substring(0, 4); //get the first four characters
      servo2 = readString.substring(4, 8); //get the next four characters
     
      Serial.println(servo1);  //print ot serial monitor to see results
      Serial.println(servo2);
     
      int n1; //declare as number 
      int n2;
     
      char carray1[6]; //magic needed to convert string to a number
      servo1.toCharArray(carray1, sizeof(carray1));
      n1 = atoi(carray1);
     
      char carray2[6];
      servo2.toCharArray(carray2, sizeof(carray2));
      n2 = atoi(carray2);
     
      myservo1.writeMicroseconds(n1); //set servo position
      myservo2.writeMicroseconds(n2);
    readString="";
  }
}

Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Left Coast, CA (USA)
Online Online
Brattain Member
*****
Karma: 361
Posts: 17263
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I'm using Arduino Uno and I don't find any example about how to rule up to 5 or 6 servomotors with the serial monitor

You have to deal with this project one issue at a time. First one can't power 5 or 6 servos from the +5vdc pin on an Arduino, there is just not enough current to handle that much load. So you first have to come up with how you will power the servos, large enough battery or a external regulated +5vdc 6 amp power supply? Then work on how you are going to wire all that up as there is a requirement to have any external DC power share a ground connection with the Arduino. When you have that all sorted out then you can revisit the software questions.

 To control 6 servos in software will require a servo library that can support that many: http://arduino.cc/playground/Code/MegaServo

Lefty
« Last Edit: January 29, 2011, 12:36:19 pm by retrolefty » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 16
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for your answers. I feed the servos directly with the PC cutting some USB cables to get the +5V.

I'm going to work always with Arduino connected and ruled by the PC.
Can¡t wait to try your examples.

I thoght that the pde that let us control so many servos was going to be something like a charachter and a number sended via the COM port (Something like analogwrite($pinnumber, "a120"). So if the character is the letter "a" and the number is "120" it will move the first servo to position 120º, if the character is "b" and the number is 100 the move the second servo to position 100º...

I'm going to study your examples to try to understand how do they works (comments on the code are really apreciatted for newbies like me).

Cheers
Logged

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

Some simple servo test code you can try.

Code:
// zoomkat 10-4-10 serial servo test
// type servo position 0 to 180 in serial monitor
// for writeMicroseconds, use a value like 1500
// for IDE 0019 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.attach(7);  //the pin for the servo control
  Serial.println("servo-test-21"); // so I can keep track of what is loaded
}

void loop() {

  while (Serial.available()) {
    delay(10); 
    if (Serial.available() >0) {
      char c = Serial.read();  //gets one byte from serial buffer
      readString += c; //makes the string readString
    }
  }

  if (readString.length() >0) {
    Serial.println(readString);  //so you can see the captured string
    int n;
    char carray[6]; //converting string to number
    readString.toCharArray(carray, sizeof(carray));
    n = atoi(carray);
    myservo.writeMicroseconds(n); // for microseconds
    //myservo.write(n); //for degees 0-180
    readString="";
  }
}

thanks for that code, very much smiley
Logged

I like Arduino !

Pages: [1]   Go Up
Jump to: