Controlling 2 Stepper Motors simultaneously (AccelStepper Library)

Hi everyone,

and thank you for your time and help on this.
I am a it of a newbie with Processing and Arduino; in my project Processing finds an 'x' amount of words reading google news and then sends those ints to Arduino, which in turn uses them to set new positions for 2 stepper motors.
I am using the AccelStepper library to drive the motors.
It is working pretty decently at the moment, only thing is that I cannot figure out how to control the two steppers simultaneously; so far one moves, then stops, then the other kicks in. Following some research done on this forum I had a look at the multistepper example which comes with the library, but still can't find a way to make them move at the same time.
Any help would be enourmously appreciated.

Here is my code in Arduino

// Modified from Blocking.pde
// -- mode: C++ --
//
// Shows how to use the blocking call runToNewPosition
// Which sets a new target position and then waits until the stepper has
// achieved it.
//
// Copyright (C) 2009 Mike McCauley
// $Id: Blocking.pde,v 1.1 2011/01/05 01:51:01 mikem Exp mikem $

#include <AccelStepper.h>

// Define a stepper and the pins it will use
AccelStepper stepper1 (4,2,3,4,5); // Defaults to 4 pins on 2, 3, 4, 5
AccelStepper stepper2 (4,9,10,11,12); // Defaults to 4 pins on 9, 10, 11, 12

//Motor variables
int m1val = 0; //variable controlling position of motor 1
int oldm1val = 0; // old variable controlling position of motor 1
int m3val = 0; //variable controlling position of motor 3
int oldm3val = 0; // old variable controlling position of motor 3

boolean startLine = true; // controls that all motors are reset to '0' at the beginning,
// this function happens at the end of the code

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//Reset all Motors by pushing a button
const int buttonPin01 = 8; // push button connected to pin 8
int buttonState01 = 0; // variable for reading the pushbutton status

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

char buff[]= "0000000000"; // this is for the data sent from Processing

void setup() {
Serial.begin(9600);

stepper1.setMaxSpeed(400.0);
stepper1.setAcceleration(100.0);
stepper2.setMaxSpeed(400.0);
stepper2.setAcceleration(100.0);
pinMode(buttonPin01, INPUT); // push button set to input
}

void loop() {

buttonState01 = digitalRead(buttonPin01); // reads value of the push button 01

if (buttonState01 == LOW) { //check if button was pressed
delay(10); // waits for 10 milliseconds
Serial.println("RESET MOTORS");
resetMotors();
}

if (startLine == false){
resetMotors();
startLine = true;
}

while (Serial.available()>0) { //It reads the new data sent by Processing every 10 seconds
for (int i=0; i<10; i++) {
buff*=buff[i+1];*

  • }*

  • buff[10]=Serial.read(); //if it recognises one array of chars ending with P it assigns the 9th value of the array to m1val*

  • if (buff[10]=='P') {*

  • m1val=int(buff[9]);*

  • }*

  • if (buff[10]=='R') {*

  • m3val=int(buff[9]); //same for R and m3val*

  • }*

  • }*

  • if (m1val != oldm1val){ //if the values are different from the ones previously sent, it then moves the second stepper to a value specified by m1val*

  • stepper2.enableOutputs();*
    _ stepper2.runToNewPosition(m1val*50);_

  • }*

  • else {*

  • stepper2.disableOutputs(); //if nothing happens it disables the outputs to save energy*

  • }*

  • if (m3val!= oldm3val){ //same for the other stepper motor*

  • stepper1.enableOutputs();*
    _ stepper1.runToNewPosition(m3val*50);_

  • }*

  • else {*

  • stepper1.disableOutputs(); //if nothing happens it disables the outputs to save energy*

  • }*

  • oldm3val = m3val; // stores the value of m3val*
    old1val = m1val; //stores the value of m1val
    }
    void resetMotors (){

  • stepper1.runToNewPosition(0);*

  • stepper1.disableOutputs();*

  • stepper2.runToNewPosition(0);*

  • stepper2.disableOutputs();*
    }
    -------------------------------------------------------------------------------------------------------------------
    Please let me know if you need the code from processing
    Thanks
    Faeve

Forgot to specify a few details:
I am using one Hbridge SN754410 to drive two ASTROSYN 1 MY7001 STEPPER MOTOR, 14, 20MM
These motors are bipolar and have 4 pins.
At now I am using an Arduino Uno to drive two steppers, but I will switch to an Arduino Mega in a few hours.

Thanks if you can help!

No probs.

I have found the solution, just needed to replace the way the motors were being called.
The new code relating to my two stepper motors looks like this:

stepper2.moveTo(m2val50); // where m2val is a variable I've received from processing
stepper2.run();
stepper1.moveTo(m1val
50); // same for m1val
stepper1.run();

Best

Faeve