2 steppers running simultaneously

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Christhebiss
 
Posts: 2
Joined: Tue Jan 17, 2023 3:48 pm

2 steppers running simultaneously

Post by Christhebiss »

Hi!

I am an artist and try to finish my installation. (see pic) Therefore I need two steppers, which have to run simultaneously. As well I need to change the speed and the direction individually in the programming list, it should be kind of a composition, which I could change in detail.
Now, I got the latest Adafruit Motor Shild and the Itead Dual Motor Shild. The Itead shild can operate with more voltage, which also means that I can speed up the motor even more, right? So I still do not know, which shild I should take, because even I connect the 12V Adapter the full speed of the motors is quite slow, how can I improve?

The programming is as well a problem regarding the shilds and the circumstance, where I need to "wrap the steppers into an accel stepper-object". The example code from arduino is a mix of the library of adafruit and accel stepper. Isnt it possible just to control the two steppers with the adafruit library? Btw: Is there any proper manual for both library? I mean like a manual, which explains the structure of the code with examples?(Accel Stepper documentation is only about the functions)

Following you will see the code I am using right now:

Code: Select all

#include <AccelStepper.h>
#include <MultiStepper.h>

// Define the stepper motor and the pins that is connected to
AccelStepper stepper1(1, 2, 3); // (Typeof driver: with 2 pins, STEP, DIR)
AccelStepper stepper2(1, 6, 7);

MultiStepper steppersControl;  // Create instance of MultiStepper

long gotoposition[2]; // An array to store the target positions for each stepper motor

void setup() {

  stepper1.setMaxSpeed(1000); // Set maximum speed value for the stepper
  stepper2.setMaxSpeed(1000);

  // Adding the 3 steppers to the steppersControl instance for multi stepper control
  steppersControl.addStepper(stepper1);
  steppersControl.addStepper(stepper2);
 

void loop() {
  // Store the target positions in the "gotopostion" array
  gotoposition[0] = 2000;  // 800 steps - full rotation with quater-step resolution
  gotoposition[1] = 2000;
  steppersControl.moveTo(gotoposition); // Calculates the required speed for all motors
  steppersControl.runSpeedToPosition(); // Blocks until all steppers are in position

  delay(1000);

  gotoposition[0] = 0;
  gotoposition[1] = 0;
  steppersControl.moveTo(gotoposition);
  steppersControl.runSpeedToPosition();

  delay(1000);
}

[b]Here I can change it more or less individually, but isnt there a way with more shorcuts? Because for every individual change of speed and direction I need to add 5 code lines, relatively 6 with the delay...[/b]
Why does it only works with stepper1.setmaxspeed and not with just setspeed?

Underneath you see a code for one stepper with a shild, which I used. This was very easy, couldnt it work for 2 steppers, who run simultaneously as easy as that? Btw: Which function exactly runs them simultaneously?

Are this code lines responsible for it?
    if (stepper1.distanceToGo() == 0)
	stepper1.moveTo(-stepper1.currentPosition());

    if (stepper2.distanceToGo() == 0)
	stepper2.moveTo(-stepper2.currentPosition());


/* Example sketch to control a stepper motor with Arduino Motor Shield Rev3, Arduino UNO and Stepper.h library. More info: https://www.makerguides.com */
// Include the Stepper library:
#include <Stepper.h>
// Define number of steps per revolution:
const int stepsPerRevolution = 200;
// Give the motor control pins names:
#define pwmA 3
#define pwmB 11
#define brakeA 9
#define brakeB 8
#define dirA 12
#define dirB 13
// Initialize the stepper library on the motor shield:
Stepper myStepper = Stepper(stepsPerRevolution, dirA, dirB);
void setup() {
  // Set the PWM and brake pins so that the direction pins can be used to control the motor:
  pinMode(pwmA, OUTPUT);
  pinMode(pwmB, OUTPUT);
  pinMode(brakeA, OUTPUT);
  pinMode(brakeB, OUTPUT);
  digitalWrite(pwmA, HIGH);
  digitalWrite(pwmB, HIGH);
  digitalWrite(brakeA, LOW);
  digitalWrite(brakeB, LOW);
  // Set the motor speed (RPMs):
  myStepper.setSpeed(150);
}
void loop() {
  // Step one revolution in one direction:
  //Step on revolution in the other direction:
  myStepper.step(650);
  delay(1000);
  myStepper.step(150);
  delay(50);
  myStepper.step(-150);
  delay(50);
  myStepper.step(150);
  delay(50);
  myStepper.step(-150);
  delay(50);
  myStepper.step(150);
  delay(50);
  myStepper.step(-150);
  delay(50);
  myStepper.step(150);
  delay(50);
  myStepper.step(-150);
  delay(500);
  myStepper.step(150);
  delay(50);
  myStepper.step(-150);
  delay(50);
  myStepper.step(150);
  delay(50);
  myStepper.step(-150);
  delay(50);
  myStepper.step(150);
  delay(500);
  myStepper.step(-150);
  delay(50);
  myStepper.step(150);
  delay(50);
  myStepper.step(-150);
  delay(50);
  
  myStepper.setSpeed(50);

  myStepper.step(150);
  delay(50);
  myStepper.step(-150);
  delay(50);
  myStepper.step(150);
  delay(50);
  myStepper.step(-150);
  delay(50);
  myStepper.step(150);
  delay(50);
  myStepper.step(-150);
  delay(50);
  myStepper.step(150);
  delay(50);
  myStepper.step(-150);
  delay(500);

  myStepper.setSpeed(150);

  myStepper.step(400);
  delay(500);
  myStepper.step(-200);
  delay(50);
  myStepper.step(200);
  delay(50);
  myStepper.step(-200);
  delay(50);
  myStepper.step(200);
  delay(50);
  myStepper.step(-200);
  delay(50);
  myStepper.step(200);
  delay(50);
  myStepper.step(-200);
  delay(50);
  myStepper.step(200);
  delay(50);
  myStepper.step(-200);
  delay(50);
  myStepper.step(200);
  delay(50);
  myStepper.step(-200);
  delay(50);
  myStepper.step(200);
  delay(50);
  myStepper.step(-200);
  delay(50);
  myStepper.step(200);
  delay(50);
  myStepper.step(-200);
  delay(50);

  myStepper.step(-850);
  delay(10000);
}

Thanks a lot for your feedback!

Image
Attachments
Installation.jpeg
Installation.jpeg (442.83 KiB) Viewed 158 times
Last edited by adafruit_support_bill on Thu Jan 19, 2023 5:13 pm, edited 1 time in total.
Reason: Please use [code] tags when posting code to the forums

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

Re: 2 steppers running simultaneously

Post by adafruit_support_bill »

Sounds like two separate issues here. But not a lot of relevant details.

Controlling two motors simultaneously is possible with the Adafruit library alone. But to do it, you would be replicating much of what the AccelStepper motor already does for you. AccelStepper is your best solution in the Arduino environment.

Motor speed is a function of many variables. Supply voltage is only one of them. In the case of the Adafruit shield, communication with the shield is often the bottleneck in multi-motor configurations. I am not familiar with the other shield you mention. But if it has both lower communication overhead and higher supply voltage capability, it may be capable of faster speed. But depending on the motors you are using, you may need current limiting.
https://learn.adafruit.com/all-about-st ... he-stepper

A third option is to use a more sophisticated driver such as the Pololu "Tic" stepper drivers. These can perform much of the work at the driver level instead of in your code - eliminating almost all of the communication overhead. And they have current limiting as well. https://www.pololu.com/category/212/tic ... ontrollers

User avatar
Christhebiss
 
Posts: 2
Joined: Tue Jan 17, 2023 3:48 pm

Re: 2 steppers running simultaneously

Post by Christhebiss »

Thank you for your immediate reply.

Finally I could create a code, which works the way I am looking for. Now it looks like this:



Code: Select all

#include <AccelStepper.h>
#include <MultiStepper.h>

// Define the stepper motor and the pins that is connected to
AccelStepper stepper1(1, 2, 3); // (Typeof driver: with 2 pins, STEP, DIR)
AccelStepper stepper2(1, 6, 7);

MultiStepper steppersControl;  // Create instance of MultiStepper

long gotoposition[2]; // An array to store the target positions for each stepper motor

void setup() {

  stepper1.setMaxSpeed(4000); // Set maximum speed value for the stepper
  stepper2.setMaxSpeed(4000);

  // Adding the 3 steppers to the steppersControl instance for multi stepper control
  steppersControl.addStepper(stepper1);
  steppersControl.addStepper(stepper2);

}

void loop() {
  // Store the target positions in the "gotopostion" array
  gotoposition[0] = 100000;  // 800 steps - full rotation with quater-step resolution
  gotoposition[1] = 100000;
  steppersControl.moveTo(gotoposition); // Calculates the required speed for all motors
  steppersControl.runSpeedToPosition(); // Blocks until all steppers are in position

  delay(1000);

  stepper1.setMaxSpeed(2000);
  stepper2.setMaxSpeed(2000);

  gotoposition[0] = 0;
  gotoposition[1] = 0;
  steppersControl.moveTo(gotoposition);
  steppersControl.runSpeedToPosition();

  delay(1000);

  stepper1.setMaxSpeed(4000);
  stepper2.setMaxSpeed(4000);

  gotoposition[0] = 120000;
  gotoposition[1] = 120000;
  steppersControl.moveTo(gotoposition);
  steppersControl.runSpeedToPosition();

  delay(1000);

  stepper1.setMaxSpeed(100);
  stepper2.setMaxSpeed(100);

  gotoposition[0] = 4000;
  gotoposition[1] = 4000;
  steppersControl.moveTo(gotoposition);
  steppersControl.runSpeedToPosition();

  delay(10000);
}
Still the speed an recently the noise of the steppers are the problem. I checked out the datasheet of my driver and the one of the stepper nema 17-1.

The ITEAD Dual Stepper Motor Driver Shield enables your Arduino or compatible microcontroller to drive two stepper motors.

This Arduino shield is specifically designed to drive two independent 4 pin bipolar stepper motors. It supports stepper motors with operating voltages from 4.75V to 30V at up to 750mA and can be used with 3.3V or 5V Arduino compatible microcontrollers.

Dual A3967 microstepping motor driver chips are used to drive the stepper motors. The A3967 driver chip features automatic current- decay mode detection and selection, crossover-current protection and has built in thermal shutdown circuitry. It is designed to drive bipolar stepper motors in full, half, quarter and eighth step modes using a minimal number of control lines. This is the same chip used in the popular EasyDriver boards. This shield is like having two EasyDriver boards mounted on an Arduino friendly shield.

This shield also has a set of 3 pin analog input and 4 pin i2c and serial port header pins for additional convenience.

Use this Arduino shield to drive your robot or create a robotic CNC machine or a two dimensional art generator.


I connect a 12V Adapter to the Shild and the arduino is still connected to my computer, when they run. As well I adjusted as recommended on this website the speed level via #define TWI_FREQ 400000L, from 200000 to 400000.
More than a MaxSpeed of 4000 in the code is not possible. So should I better buy the pololu driver as you recommended or apply more voltage to the shild (like 24V)? Maby the problem then is the relation between the current and the power..?
Anyway I am considering to buy the pololu Tic driver, it looks like a highly professional driver. Which one could you recommend to my installation? Tic T500? It should turn down the noise and perform better then the shild I operate with now, means especially more speed.
What you mean by lower communication overhead?
If I want to run 2 steppers with the pololu driver system, I guess I need two of them and connect them via a breadbord, right? Will I still use the Accel Stepper library to control the steppers via the pololu driver?

Please keep in mind I am a beginner in this fild, there so many information you need to consider. I really appreciate your patience and answer to my questions, even they are not always relevant. Thank you in advance!
Last edited by adafruit_support_bill on Thu Jan 19, 2023 5:09 pm, edited 1 time in total.
Reason: Please use [code] tags when posting code to the forums

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

Re: 2 steppers running simultaneously

Post by adafruit_support_bill »

I can only offer general advice here, since I have no firsthand experience with the motor driver you are using. For more specific advice, you should contact the manufacturer or seller for technical assistance.

Motor maximum speed is a function of a number of things. There are the electromechanical limits of the motor, power supply and driver characteristics. And there is the speed at which you can send it stepping commands.

The A3967 drivers have a 'step & direction' interface. This is simpler than the i2c interface used by the Adafruit shield. So you are not limited by the speed of i2c communication. You are only limited by the speed at which you can send pulses to the 'step' pin.

The Pololu 'TIC' controllers are 'smart' controllers. You can tell them how many steps to take and how fast to move. The TIC controller handles the actual steppinng, and no further communication or action from your code is necessary.

Motor noise is partly a function of the stepping modes and even more a function of natural resonances of the motor and whatever it is attached to. Microstepping tends to be less noisy than full-step mode. But the torque and speed will be lower.

Motor noise can be reduced by using rubber washers in the motor mount to help dampen the vibrations. It also helps to pay attention to the stepping frequency and try to avoid those frequencies which resonate loudest in your mechanism.

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

Return to “General Project help”