Pages: [1]   Go Down
Author Topic: Continuous Standard Servos and Two Servos in One Breadboard  (Read 862 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So I'm doing a project with a normal Arduino kit where we need two motors to run continuously forwards and in reverse. Since apparently the motors that come with the kit can't run in reverse, we ended up using a motor controller in order to make the program believe the motor is actually a servo. However, we cannot make the servo/motor run continously- it only runs for a while, pauses, then turns the opposite direction. We edited the original code- which is the code for Circuit 4- as much as we could, but cannot figure it out.

We also have an issue with multiple servo/motors on one breadboard. Even though both work, one works normally, while the other is weaker and stutters a lot.

Any assistance? The code is the original code for Circuit number 4 in the manual.
Logged

UK
Offline Offline
Shannon Member
****
Karma: 184
Posts: 11159
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

apparently the motors that come with the kit can't run in reverse

That seems a bit odd. Is it a DC motor? Is it a case of the circuit powering the motor not supporting reverse, rather than the motor itself? A driver that only supports one direction can use a simple transistor, whereas on that supports reverse needs to be more complex. If you have got a dedicated motor controller (I assume this is a circuit that provides power to the motor) I'd guess that this would be an H bridge driver that supports reverse. However, without any details of the motor, driver or sketch I can't do more than guess.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

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

So I'm doing a project with a normal Arduino kit where we need two motors to run continuously forwards and in reverse. Since apparently the motors that come with the kit can't run in reverse, we ended up using a motor controller in order to make the program believe the motor is actually a servo. However, we cannot make the servo/motor run continously- it only runs for a while, pauses, then turns the opposite direction. We edited the original code- which is the code for Circuit 4- as much as we could, but cannot figure it out.

DC motors turn in the direction of the polarity of the applied DC voltage wired to the motor. Your complaint, if real, has to do with the circuit that is controlling/driving the motor or possibly the software logic you are using to try and control it. So we would need much more details about the hardware you actually purchased and a posting of your code.

We also have an issue with multiple servo/motors on one breadboard. Even though both work, one works normally, while the other is weaker and stutters a lot.

 Possibly you may not have enough power to run the servos. I recommend 1 amp current capacity for each servo you want to run. What are the details of your power supply?

Any assistance? The code is the original code for Circuit number 4 in the manual.

That's not very easy for me to find. Post a link to the code or post the code here if you want to make it easier for people to try and help.
Logged

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

Okay, some more information.

Basically we need to make a project using this starter kit:

https://www.sparkfun.com/products/10173

We want to connect two motors to the Arduino and control speed and the direction they're moving in. The motors are powered by 5V, and wiring two motors parallel to each other on the breadboard allows both to run.

However, we were not able to change the direction of the toy motor, so we ended up using this product:
http://www.vexrobotics.com/276-2193.html

It allows the motor to run via a PWM cable, in which we could pretend the motor is actually a servo and we can run it forwards and reverse. This works, but 1) The motor does not run continuously without stopping and changing direction and 2)When connecting two motors with PWM cables only one motor functions correctly while the other is weaker, whereas with normal two-pin wires it functions perfectly.

This is the original code to get the toy motors running with a two-pin wire:
Code:
/*     -----------------------------------------------------------
 *     |  Arduino Experimentation Kit Example Code               |
 *     |  CIRC-03 .: Spin Motor Spin :. (Transistor and Motor)   |
 *     -----------------------------------------------------------
 *
 * The Arduinos pins are great for driving LEDs however if you hook
 * up something that requires more power you will quickly break them.
 * To control bigger items we need the help of a transistor.
 * Here we will use a transistor to control a small toy motor
 *
 * http://tinyurl.com/d4wht7
 *
 */

int motorPin = 9;  // define the pin the motor is connected to
                   // (if you use pin 9,10,11 or 3you can also control speed)

/*
 * setup() - this function runs once when you turn your Arduino on
 * We set the motors pin to be an output (turning the pin high (+5v) or low (ground) (-))
 * rather than an input (checking whether a pin is high or low)
 */
void setup()
{
 pinMode(motorPin, OUTPUT);
}


/*
 * loop() - this function will start after setup finishes and then repeat
 * we call a function called motorOnThenOff()
 */

void loop()                     // run over and over again
{
 motorOnThenOff();
 //motorOnThenOffWithSpeed();
 //motorAcceleration();
}

/*
 * motorOnThenOff() - turns motor on then off
 * (notice this code is identical to the code we used for
 * the blinking LED)
 */
void motorOnThenOff(){
  int onTime = 2500;  //the number of milliseconds for the motor to turn on for
  int offTime = 1000; //the number of milliseconds for the motor to turn off for
  
  digitalWrite(motorPin, HIGH); // turns the motor On
  delay(onTime);                // waits for onTime milliseconds
  digitalWrite(motorPin, LOW);  // turns the motor Off
  delay(offTime);               // waits for offTime milliseconds
}

/*
 * motorOnThenOffWithSpeed() - turns motor on then off but uses speed values as well
 * (notice this code is identical to the code we used for
 * the blinking LED)
 */
void motorOnThenOffWithSpeed(){
  
  int onSpeed = 200;  // a number between 0 (stopped) and 255 (full speed)
  int onTime = 2500;  //the number of milliseconds for the motor to turn on for
  
  int offSpeed = 50;  // a number between 0 (stopped) and 255 (full speed)
  int offTime = 1000; //the number of milliseconds for the motor to turn off for
  
  analogWrite(motorPin, onSpeed);   // turns the motor On
  delay(onTime);                    // waits for onTime milliseconds
  analogWrite(motorPin, offSpeed);  // turns the motor Off
  delay(offTime);                   // waits for offTime milliseconds
}

/*
 * motorAcceleration() - accelerates the motor to full speed then
 * back down to zero
*/
void motorAcceleration(){
  int delayTime = 50; //milliseconds between each speed step
  
  //Accelerates the motor
  for(int i = 0; i < 256; i++){ //goes through each speed from 0 to 255
    analogWrite(motorPin, i);   //sets the new speed
    delay(delayTime);           // waits for delayTime milliseconds
  }
  
  //Decelerates the motor
  for(int i = 255; i >= 0; i--){ //goes through each speed from 255 to 0
    analogWrite(motorPin, i);   //sets the new speed
    delay(delayTime);           // waits for delayTime milliseconds
  }
}

And this is the code to run the motors with a PWM cable:
Code:
// Sweep
// by BARRAGAN  

#include  
 
Servo myservo;  // create servo object to control a servo
                // a maximum of eight servo objects can be created
 
int pos = 0;    // variable to store the servo position
 
void setup()
{
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}
 
 
void loop()
{
  for(pos = 0; pos < 180; pos += 1)  // goes from 0 degrees to 180 degrees
  {                                  // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for(pos = 180; pos>=1; pos-=1)     // goes from 180 degrees to 0 degrees
  {                                
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
}

I understand that the starter kit may have limited functionality, but I think it should still work. We are not able to obtain anything else. Sorry for not giving enough info.
« Last Edit: August 19, 2012, 09:10:07 pm by 16rahmanm » Logged

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

Well the problem is with the sketch code. Your are going to have to modify the sweep sketch so that the motor will do what you want it to do, rather then what the sweep sketch was written to do. Because of the servo/driver you have you will have to keep in mind that the motor will do the following with the corresponding servo commands:

myservo.write(0); //full speed in one direction
myservo.write(180); //full speed in the other direction
myservo.write(90);  // motor stopped

Values other then those but still within 0-180 will have the motor turning in one direction or the other direction at some variable speed. The (90) value may have to be increased or decreased slightly for full stop due to timing calibrations.

Good luck;

Lefty
Logged

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

Thanks a lot, I'll continue modifying the code with your advice and see if it works!
Logged

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

What about, however, the second motor connected as a PWM being weaker than the other when on the same breadboard?
Logged

0
Offline Offline
Tesla Member
***
Karma: 114
Posts: 8913
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you are using continous rotation servos for the wheel drive setup, you should be able to do simple testing with the below servo code via the serial monitor.

Code:
// 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
  }
}


Logged

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

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

Wrong thread? I don't remember talking about wheel drives, and I'm using small motors with a PWM connection as servos instead of continuous rotation servos.
Logged

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

Wrong thread? I don't remember talking about wheel drives, and I'm using small motors with a PWM connection as servos instead of continuous rotation servos.

Yes, but your specific controller/motor are working just like a modified continuous rotation servo as far as the arduino servo commands are concerned. Your hardware and such a modified servo act the same.

Lefty
Logged

0
Offline Offline
Tesla Member
***
Karma: 114
Posts: 8913
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Wrong thread? I don't remember talking about wheel drives, and I'm using small motors with a PWM connection as servos instead of continuous rotation servos.

Then why are you trying code with "And this is the code to run the motors with a PWM cable:" followed by code containing "Servo myservo;  // create servo object to control a servo"? Stand alone motors usually can't be controlled via the servo library whichprovides a control scheme generally refered to as PPM. Hmmm..., kind of like a soup sandwich.
Logged

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

Pages: [1]   Go Up
Jump to: