Hello everyone! I am new to this community and the arduino platform. I am trying to run a stepper motor QSH4218-35-10-027 simultaneous with a servor motor Modelcraft MC-1811 on an Arduino UNO with an Adafruit Motor Shield v.2.3. (Motor/Stepper/Servo Shield (Version 2) | Adafruit Shield Compatibility Guide | Adafruit Learning System)
Stepper motor data: 200Steps, 1A phase current, rated voltage 5.3V, (http://www.trinamic.com/products/motors/motors-stepper/qmot-qsh4218)
A short overview about my project: I have a big spool with e.g. 500 meters of electric cable on it and an emtpy spool. My goal is it to uncoil a defined length of the big spool to the small spool. The stepper is connected to the small spool. The servo is placed between big and small spool and moves from 80° to 100° (start position 90°).
Process:
Step1: Stepper motor accelerate the small spool from 0 to 100.
Step2: After the small spool turned 1 rotation the servo starts. The servo starts at 90° and moves to 100° and than back to 80° (1° steps) and so on. I need this movement to avoid that the cable uncoils at the same place.
Step3: Shortly before the stepper reaches his target position it should deccelerate and stop at the target position.
Step4: Stepper and servo motor stop their movement.
Sketch:
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"
#include <Servo.h>
#include <Stepper.h>
#include <AccelStepper.h>
float Circumference= 0.2827; // in meters
float CableLength = 3; // for example 3 meters
long NumberRotation;
//Servo
const int SERVO_PIN = 9;
int SRV_pos;
boolean SRV_moveForward;
long SRV_nextWakeUp;
Servo myservo;
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
Adafruit_MotorShield AFMStop(0x60); // Rightmost jumper closed
Adafruit_StepperMotor *myStepper1 = AFMStop.getStepper(200, 1);
void forwardstep1() {
myStepper1->onestep(FORWARD, DOUBLE);
}
AccelStepper stepper1(forwardstep1, 0);
void setup() {
Serial.begin(9600);
Serial.println("Stepper: Start");
AFMStop.begin();
NumberRotation= 200*(FiberLength/Circumference);
stepper1.setMaxSpeed(100.0);
stepper1.setAcceleration(10.0);
stepper1.moveTo(NumberRotation);
Serial.println(NumberRotation/200);
myservo.attach(SERVO_PIN);
SRV_pos = 90;
SRV_moveForward = true;
SRV_nextWakeUp = millis();
}
void loop()
{
if(stepper1.distanceToGo() == 0)
stepper1.moveTo(stepper1.currentPosition());
stepper1.run();
}
long currentTime = millis();
long nextWakeUpSRV = SRV_doStep(currentTime);
/***Servo***/
long SRV_doStep(long currentMillis) {
if(currentMillis>SRV_nextWakeUp) {
if(SRV_moveForward) {
SRV_pos += 1;
if(SRV_pos>100){
SRV_moveForward = false;
SRV_pos = 100;
}
} else {
SRV_pos -= 1;
if(SRV_pos<80) {
SRV_moveForward = true;
SRV_pos = 80;
}
}
myservo.write(SRV_pos);
SRV_nextWakeUp = currentMillis + 100;
Serial.println(SRV_pos);
}
return SRV_nextWakeUp;
}
Problem:
If I run this sketch without any acceleration and decceleration task both motors are moving simultaneous.
But if I try to run the sketch with the acceleration and decceleration task than the servo allways stays at his start position 90° and does not move. The stepper rotates without any problem.
Did I do a mistake in my sketch?
Is it possible to run this process with a stepper and a servo motor or is it better to use 2 stepper motors.
I tried to run 2 stepper motors at 5V (external power supply) last week. It worked but I had a strong heat development and a rough and harsh noice! It does not matter if I use 2 or 1 stepper.
If I run the sketch without the motor shield (stepper connected to Arduino Uno breadboard) than the stepper runs smooth and without a strong heat development.
Thanks a lot for your help.