an 2 motor shields for controlling the frequency of the other 3 motors?
I don't know what you mean by frequency. Speed? If so, yes, you'll need two.
Is it possible to stack these 5 shields on my arduino mega 2560, if they are stackable?
No.
Which pins on my arduino must I use
Any three PWM pins to control the speed of the motors and any three pins to control the direction. Since you won't be using shields, you won't be constrained to some set of pins.
Any three step pins for the steppers, and any three direction pins. Since you won't be using shields, you won't be constrained to some set of pins.
will i have to change programming if i use stepper motor instead of servo motors? #include <Servo.h> //include Servo library
const int RForward = 0;
const int RBackward = 180;
const int LForward = RBackward;
const int LBackward = RForward;
const int RNeutral = 90;
const int LNeutral = 90; //constants for motor speed
const int pingPin = 7;
const int irPin = 0; //Sharp infrared sensor pin
const int dangerThresh = 10; //threshold for obstacles (in cm)
int leftDistance, rightDistance; //distances on either side
Servo panMotor;
Servo leftMotor;
Servo rightMotor; //declare motors
long duration; //time it takes to recieve PING))) signal
void setup()
{
rightMotor.attach(11);
leftMotor.attach(10);
panMotor.attach(6); //attach motors to proper pins
panMotor.write(90); //set PING))) pan to center
}
void loop()
{
int distanceFwd = ping();
if (distanceFwd>dangerThresh) //if path is clear
{
leftMotor.write(LForward);
rightMotor.write(RForward); //move forward
}
else //if path is blocked
{
leftMotor.write(LNeutral);
rightMotor.write(RNeutral);
panMotor.write(0);
delay(500);
rightDistance = ping(); //scan to the right
delay(500);
panMotor.write(180);
delay(700);
leftDistance = ping(); //scan to the left
delay(500);
panMotor.write(90); //return to center
delay(100);
compareDistance();
}
}
void compareDistance()
{
if (leftDistance>rightDistance) //if left is less obstructed
{
leftMotor.write(LBackward);
rightMotor.write(RForward); //turn left
delay(500);
}
else if (rightDistance>leftDistance) //if right is less obstructed
{
leftMotor.write(LForward);
rightMotor.write(RBackward); //turn right
delay(500);
}
else //if they are equally obstructed
{
leftMotor.write(LForward);
rightMotor.write(RBackward); //turn 180 degrees
delay(1000);
}
}
long ping()
{
// Send out PING))) signal pulse
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);
//Get duration it takes to receive echo
pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);
With your Help I now seem to have a solution for steering 3 DC-Motors und 3 stepper-motors with the Arduiono Mega 2560 (each DC-Motor < 600mA; stepper-motors each phase < 1A)
1.I use an adafruit Motor shield for the 3 DC-Motors
2. The 3 stepper-Motors are connected each with a BigEasyDriver as you suggested.
3. Because I don't use servos, the PWM-Pins 9 and 10 ( and 2 which is always unused; Mega2560!) of the adafruit motorshield can be used as PWM for the 3 stepper-motors. Each of them also uses another free digital-Pin for its direction control.
4. I want to use the AccelStepper-Library to control all motors.
Because I don't use servos, the PWM-Pins 9 and 10 ( and 2 which is always unused; Mega2560!) of the adafruit motorshield can be used as PWM for the 3 stepper-motors. Each of them also uses another free digital-Pin for its direction control.
Stepper motors don't use PWM. Did you mean DC motors here?
Stepper motors don't use PWM. Did you mean DC motors here?
Either I didn't understand fundamental things or I was not precise enough:
I meant that the BigEasy-Drivers need PWM as input if stepper-motors are to be steered.I found an example http://bildr.org/2012/11/big-easy-driver-arduino/ where one PWM-Pin is connected to the BigEasyDriver inputs while the other input Pin is connected to a normal digital output (direction).
But if a steppermotor only needs two digital inputs, everything would be more easy because the Mega2560 has much simple digital pins.
Do BigEasyDriver need PWM-Outputs for steering stepper-Motors?
I meant that the BigEasy-Drivers need PWM as input if stepper-motors are to be steered.
No, they don't. They simply need to be told step, step, step, at the right time. PWM is NOT the way to do that. That the example you liked to used a PWM-capable pin does not mean that it is using PWM. The two pins could just as easily have been reversed, with only minor changes in the code and NO change in results.