Go Down

Topic: running 1 stepper and 2 servos with Adafruit v2 Motorshield? (Read 177 times) previous topic - next topic

sierrahorangic40

Hi, I have a NEMA 17 stepper and two towerpro micro servos on an Adafruit v2 motorshield.
I guess I just assumed from the pictures on the website you could run both servos and the stepper on the same board.
I've gotten the stepper to work with one of the servos, but I can't figure out how to get both servos working at the same time. Is this even possible? Here's the code I've been trying:


Code: [Select]
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include <Servo.h>

Adafruit_MotorShield AFMS = Adafruit_MotorShield();

Adafruit_StepperMotor *myMotor = AFMS.getStepper(200, 1);
Servo servo1;
Servo servo2;

void setup() {
  Serial.begin(9600);           
  Serial.println("rack and wrist");


  AFMS.begin(); 
  servo1.attach(10);
  servo2.attach(20);
  myMotor->setSpeed(10); 
 servo1.write(180);
servo2.write(180);
 

}

void loop() {


  Serial.println("single coil steps");
  myMotor->step(300, FORWARD, SINGLE);
  delay (30000);
 
 myMotor->step(100, BACKWARD, SINGLE);
   }
 



It runs the stepper and one servo fine, but not the other one. The two servos would be performing the exact same thing at the same time, if that could help me. Any help would be greatly appreciated :)

sierrahorangic40

I fixed it! sorry for asking that question my problem was that I set servo2 on pin 20 (?) instead of 9 which is what it is and now it works if anyone else ever has my problem.

Go Up