please take a look at this code: beginner here

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
auspicious
 
Posts: 71
Joined: Tue Apr 26, 2011 12:44 am

please take a look at this code: beginner here

Post by auspicious »

hello.
I had already typed this all out once before i lost connection...so i'll make it breif and not fancy this time.

hardware:
adruino
adafruit motor shield
2 slow dc motors
1 adrafruit stepper

purpose:
trying to get this code to simply move the 1st DC motor forward , backwards, and pause.

then the stepper to do the same...

then the 2nd dc motor to do the same...

right now the2 dc motors are on ports 1 and 2
the stepper is one ports 3 and 4

both the 2dc motors together and then the stepper worked fine with the code when alone...
but when i tried to combine the stepper with the dc's nothing seems to work correctly. one of the dc motors
keeps turning many more times then it should and that's about it.

I will adjust it later, but if we could just get this basic code working then things would be much easier...
Thanks so much for taking time to look!

heres the code so far (its just combining the AF motortest and AF stepper test): :arrow:

[Edit - moderator - use code button when submitting large blocks of code ]

Code: Select all

// Adafruit Motor shield library
// copyright Adafruit Industries LLC, 2009
// this code is public domain, enjoy!

#include <AFMotor.h>

AF_DCMotor motor1(2), motor3(1);
AF_Stepper motor2(48, 3);

void setup() {
  Serial.begin(9600);           // set up Serial library at 9600 bps
  Serial.println("Motor test!");
  
 motor2.setSpeed(10);  // 10 rpm 
  // turn on motor
  motor1.setSpeed(200);
    motor1.run(RELEASE);
    // turn on motor
  motor3.setSpeed(200);
    motor3.run(RELEASE);
  
}

void loop() {
   Serial.println("Single coil steps");
  motor2.step(500, FORWARD, SINGLE); 
  motor2.step(500,BACKWARD,SINGLE);

  
  Serial.print("tick-");
    motor1.run(FORWARD); 
      motor1.setSpeed(250);  
        delay(500);
    
      Serial.print(" pause---");
       motor1.run(RELEASE);
      delay(500);
      Serial.print("tock---");
     motor1.run(BACKWARD);
        motor1.setSpeed(250);  
            delay(500);
    
        Serial.print("puase1-");
    motor1.run(RELEASE);
      delay(5000);
      Serial.print("pause2--");
    motor3.run(RELEASE);
      delay(5000);    
            
 
  Serial.print("rotate 1-");
    motor3.run(FORWARD); 
      motor3.setSpeed(250);  
        delay(500);
             Serial.print("pause2-");
                motor3.run(RELEASE);
                  delay(500);  
    Serial.print("rotate 2--");
     motor3.run(BACKWARD);
        motor3.setSpeed(250);  
            delay(500);
 
Serial.print("pause2-");
    motor1.run(RELEASE);
      delay(5000);
      Serial.print("pause2--");
    motor3.run(RELEASE);
      delay(5000);
       }
     

User avatar
adafruit_support_bill
 
Posts: 88154
Joined: Sat Feb 07, 2009 10:11 am

Re: please take a look at this code: beginner here

Post by adafruit_support_bill »

How are you powering these motors?
What is the output on the Serial Monitor when you run this sketch?

auspicious
 
Posts: 71
Joined: Tue Apr 26, 2011 12:44 am

Re: please take a look at this code: beginner here

Post by auspicious »

the motors are powered by the 9vlt ac plug in from adafruit...

the print window says
1) exactly what is listed when the stepper command is removed. All print commands show up propperly when stepper command is removed.
2)when the stepper command is left there, then it
doesnt get past the intro of the "Motor test!"
...and that's all it does when the stepper is connected...

what could be wrong with the stepper command?
is it hooked to the correct port? and called correctly?
I'm not sure what is not happening, but something must not
be recognized maybe???? i bet its something very simple.

thanks again for your time. :)

User avatar
adafruit_support_bill
 
Posts: 88154
Joined: Sat Feb 07, 2009 10:11 am

Re: please take a look at this code: beginner here

Post by adafruit_support_bill »

Code: Select all

AF_Stepper motor2(48, 3);
You have your stepper motor defined on port 3. The valid values for a stepper are 1 (M1, M2) and 2 (M3, M4).

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”