3 stepper motors with constant speeds, adjustable with 3 potentiometers

Dear Arduino-community,

I am new to this fantastic world and I‘ve started a project to build a machine that draws pictures (sounds cool, right? :)). To break it down to what is of interest:

Hardware:
3x stepper motors: bipolar, 1.8 degrees per step, 1.5A, 3.8V)
1x Arduino Uno
1x CNC Shield V3
3x DRV8825 with 3 Jumpers each
3x potentiometer (10 kOhm)

Idea:
All 3 engines run at the same time with a constant speed depending on their own potentiometer. The speed is adjustable at any time for each motor separately. Minimum speed is 0rpm, maximum is something around 60rpm.

Problem:
I have tried various pieces of code I’ve found and to adjust those to my needs. Generally, I tried the AccelStepper as well as the Stepper library. It’s hard to describe the outcome as nothing really seemed logical.

To start with (hopefully) easy questions:
-Is it even possible to realize what I want with the hardware I have?
-Is there any similar use case you know of, ideally with a piece of code to share.

I am happy to share more information if needed.

Thanks in advance,
Seb

I think what you want to do should be easily achievable using the runSpeed() function of the AccelStepper library.

Use the potentiometers to change the value used by the setSpeed() function.

...R

Hi Robin,

Thanks for your answer and sorry for my late reply.

We‘ve tried the setSpeed() function but it didn’t work out well.
Connecting two motors and two potentiometers to begin, it led to the weird result, that both motors would always have the same speed and both potis would control both motors. Also, the motors were super-noisy. Something we haven’t experienced before with simple code tests before.

We found it kind of confusing how the pins are used/connected and how to address them correctly within the code.

Would it help to post the code we’ve used?

Thanks,
Sebastian

Yes of course. Posting your sketch using the insert code function The button "<|> " on the left

best regards Stefan

slein90:
We‘ve tried the setSpeed() function but it didn’t work out well.

You need to post the program so we can see exactly what you have been trying.

When posting code please use the code button </>
codeButton.png

so your code 
looks like this

...R

Hello Arduino-Community,

i am also involved in the project and got the code on my computer.

We tried the following things:

#include <AccelStepper.h>
// Define some steppers and the pins the will use

AccelStepper stepper1(AccelStepper::FULL4WIRE, 2, 5, 5, 8);
AccelStepper stepper2(AccelStepper::FULL4WIRE, 3, 6, 6, 8);

void setup()
{  
    stepper1.setMaxSpeed(80000);
    stepper1.setSpeed(5000);

    stepper2.setMaxSpeed(80000);
    stepper2.setSpeed(3000);
}

void loop()
{
    stepper1.runSpeed();
    stepper2.runSpeed();
}

This made the motors rotate in different speed but with a high level of noise.

Using two potentiometers to adjust the speed with the following code:

#include <AccelStepper.h>
// Define some steppers and the pins the will use
AccelStepper stepper1(AccelStepper::FULL4WIRE, 2, 5, 5, 8);
AccelStepper stepper2(AccelStepper::FULL4WIRE, 3, 6, 6, 8);


void setup()
{  
  //  int sensorValue = analogRead(A0);
  //  float voltage = sensorValue * (5.0 / 1023.0);
  //  stepper1.setMaxSpeed(1000);
    // stepper1.setAcceleration(300.0);
   //  stepper1.setSpeed(voltage);
  
    
    stepper1.setMaxSpeed(80000);
    stepper2.setMaxSpeed(80000);

 Serial.begin(9600);
  
}
void loop()
{

  int sensorReading = analogRead(A0);
  int sensorReading2 = analogRead(A1);
  // Serial.println(sensorReading2);
  int motorSpeed = map(sensorReading, 0, 1023, 0, 52000);
  int motorSpeed2 = map(sensorReading2, 0, 1023, 0, 52000);

stepper1.setSpeed(motorSpeed);
stepper2.setSpeed(motorSpeed2);
  
    stepper1.runSpeed();
    stepper2.runSpeed();
}

Even changing the numers in “setMaxSpeed” or the int of motorSpeed (52000 to another number) wouldn’t work, as intended. The motors getting strange behaviours (changing direction when the potentiometer is moving at a specific point - not the middle state). The noise was ofc still there and pretty loud.

Anyone of you got an idea, how to solve this in a better way?

Thanks in advance,
Alex

If you are using DRV8825 stepper drivers then you should be using the DRIVER option for AccelStepper and not FULL4WIRE. That error may explain the noise

It may also explain other erroneous behaviour.

Considering that the DRV8825 only has step and direction pins it is hard to see why you chose FULL4WIRE or where you have connected the extra two wires.

...R

Robin2:
If you are using DRV8825 stepper drivers then you should be using the DRIVER option for AccelStepper and not FULL4WIRE. That error may explain the noise

If I understand you right we should go like this:

AccelStepper stepper1(AccelStepper::DRIVER, 2, 5);
void     setEnablePin (8)

Since we have to enable Pin 8. Am I correct? I just took the command out of the AccelStep library.

The choose on FULL4WIRE was because of testing and lack of knowledge I guess.
We read about "if your stepper has 4 wires...". But you are totally right, the DRV8825 just got STEP and DIR pins.

masn89:
Since we have to enable Pin 8. Am I correct? I just took the command out of the AccelStep library.

Unless you need to control the enable pin with the Arduino I suggest you just connect it to GND or 5v (whichever is necessary to get the DRV8825 to work).

Or you could set it LOW or HIGH using digitalWrite() separately from the AccelStepper library.

...R

Thanks for your help Robin!

With the following code the stepper motors are moving with lowspeed and really quiet.
The main “mistake” was, as you already mentioned, the wrong stepper definition with FULL4WIRE.

With the attached shield, we had to enable pin 8, which was with your help and google pretty easy.

Next step would be the implementation of a 3rd stepper and 3 potentiometer. We already have prepared some code there.

#include <AccelStepper.h>

AccelStepper stepper1(AccelStepper::DRIVER, 2, 5);
AccelStepper stepper2(AccelStepper::DRIVER, 3, 6);

void setup()
{  
    pinMode(8, OUTPUT);
    digitalWrite(8,LOW);

    stepper1.setMaxSpeed(80000);
    stepper1.setSpeed(10);

    
    stepper2.setMaxSpeed(80000);
    stepper2.setSpeed(50);
}
void loop()
{
   stepper1.runSpeed();
   stepper2.runSpeed();
}