I am a complete newbie to electronics and the Arduino world. I have challenged myself the build a program that drives 2 large stepper motors Nema 34's simultaneously with acceleration/decelleration and at a fairly high rpm; over 600 RPM.
I have a pretty good grasp on the wiring aspects and have completed the wiring from the Arduino to two HBS86H drivers.
Ihave watched some Youtube tutorials on stepper motors and Arduinos and building sketches and have accessed some of the sketches in the Accelstepper library and Arduino library. No sketches offer high speed with acceleration for multiple steppers. I cannot get the Accelstepper programs to run my steppers and was hoping someone could provide some guidance to get me up and running?
For 10 RPS (600RPM) for one motor you would need 2000 steps per second. That should be within the scope of the AccelStepper library on an Uno or Mega. However two motors would mean 4000 steps per second and that may be too much for the library. The library is slow because it uses floating point maths.
Assuming your driver takes step and direction signals it is not difficult to operate stepper motors without any library. These two links should give you ideas Simple Stepper Code simple acceleration code
For higher speeds it would be a good idea to use the digitalWriteFast library as it performs much much better than the standard digitalWrite() and digitialRead(). The digitalWriteFast library requires you to identify the I/O pins at compile time.
Do you want co-ordinated movement of two motors meaning that they start as stop at the same time even though they move different numbers of steps (like a 3D printer). If so then you need to find a common value (I think it's the Lowest Common Multiple) and use that to determine when the steps happen. An example is probably the easiest way to explain. Suppose you want one motor to move 25 steps and the other to move 13 steps. If you generate 325 "ticks" then the first motor will move one step every 13 ticks and the slower motor will move one step every 25 ticks.
Yes the steppers would perform exact same movements at the same time. I have uploaded the accelstepper sketches and can’t get them to run in my setup, I may not be naming outputs correctly.
Hi (jump asside) strikesFromAbove, (Jump Back) ;-)))
exact same movement means exact same amount of steps and exact same speed?
If yes this can be solved by just parallel-wiring step and dir-inputs of both stepper-drivers and you are done.
I knew that there might be a very easy solution as soon as all details are known.
But I'm unsure if you mean that.
Your requirements of pretty high RPMs remembers me of a porgram that is written for the Teensy.
Teensy 3.5 / 4.0 / 4.1 (not Teensy 4.x yet) are another arduino-compatible microcontrollers.
The underlying library uses the special hardware of the teensy to perform this.
So this library works only with a teensy
I also started with an Arduino Mega + RAMPS 1.4 shield and two NEMA17 stepper motors about one month ago.
At the begin I did look through a lot of libraries, escpecially to get a high step ratio, but the most of them do not use timer ISR to achieve a high and constand step rate and/or use float calulations like the AccelStepper which makes them slow in general.
Then I found the jStepper library which uses hardware-timers to achieve high stepping rates. It also uses direct port manipulation as the digitalWriteFast library which Robin2 mentioned. Maybe you want to have a look on it.
Another interesting project is Klipper which also achieves high stepping rates, but it seems to be more complex and I was not able to find and extract only the functions to control the steppers within a reasonable time.
Try more basic stuff. Forget Accelstepper for now. Just get a single stepper stepping with the most basic code you can lay your hands on: toggle the step pin with delays between.
Prove to yourself that you can step it at all, then move on to the more complex things.
Which pins have you connected and how?
Did you connect an encoder to it?
Are you able to turn the stepper manually by hand if you enable it? If yes, then it is probably not enabled, maybe the signal is inverted.
Did you measure the motor coil resistance between phase A+ and A- as well as phase B+ and B- ? There should be a low resistance.
Maybe you can post the code here you have already written.
more confused than when i started here unfortunately, as i said I am seriously ground level and have played with a bit of code on sketches but am causing more issues than solving.
someone suggested i post the equipment im using so here it is.
Elegoo Uno R3
HBS86H drivers x2
nema 34 stepper motors x2 model 86hb250-156b
I need these steppers to move in exact same positions simultaneously.
One stepper should move CW, the other CCW.
Both steppers need to obtain a speed of 600 RPM minimum, preferably faster provided the movements are stable.
The sketch needs acceleration and decelleration so the steppers ramp up somewhat slowly.
i also need to be able to cut off signal to one stepper so only one will rotate.
i also need them to move in opposite direction simultaneously.
I believe I can set up the board with switches to achieve this without messing with the sketch.
any assistance would be great, suggestions on simple sketches that may work or even pointing out any resources where i can hire someone to write the sketch.
This program drives a unipolar or bipolar stepper motor.
The motor is attached to digital pins 8 - 11 of the Arduino.
A potentiometer is connected to analog input 0.
The motor will rotate in a clockwise direction. The higher the potentiometer value,
the faster the motor speed. Because setSpeed() sets the delay between steps,
you may notice the motor is less responsive to changes in the sensor value at
low speeds.
Created 30 Nov. 2009
Modified 28 Oct 2010
by Tom Igoe
*/
#include <Stepper.h>
const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
// for your motor
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
int stepCount = 0; // number of steps the motor has taken
void setup() {
// nothing to do inside the setup
}
void loop() {
// read the sensor value:
int sensorReading = analogRead(A0);
// map it to a range from 0 to 100:
int motorSpeed = map(sensorReading, 0, 1023, 0, 100);
// set the motor speed:
if (motorSpeed > 0) {
myStepper.setSpeed(motorSpeed);
// step 1/100 of a revolution:
myStepper.step(stepsPerRevolution / 100);
}
}
strikesfromabove:
Here is the sketch ive been trying to modify.
That suggests to me that you have not taken any notice of the advice you have already received. That won't encourage people to help you. If you don't understand some of the advice then you should say what you don't understand rather than ignoring it.
As well as that you have not told us what the program you posted actually does and what you want it to do that is different.