Go Down

Topic: Running a stepper motor at constant speed (Read 4787 times) previous topic - next topic

zeedo65

Hi

I need to run a NEMA 17 chineese stepper motor at a constant RPM (lets say 70 RPM) with an expansion board. What I have bought are these one. I need an instruction for that but I can not find it with the keywords I put. Could you please help.

https://www.aliexpress.com/item/Free-Shipping-4-x-A4988-Stepper-Motor-Driver-with-Heat-Sink-UNO-R3-Board-CNC-Shield/32464507854.html?spm=2114.13010608.0.62.JA5fcd

and

https://www.aliexpress.com/item/freeshipping-to-any-Country-4-lead-Nema17-Stepper-Motor-42-motor-NEMA-17-motor-42BYGH-1/969326211.html?spm=2114.13010608.0.54.hPTfdC


BR

Zeedo

rpt007

#1
Aug 31, 2016, 02:46 pm Last Edit: Aug 31, 2016, 02:50 pm by rpt007
1. adjust the current limit; see my little instruction here:
http://forum.arduino.cc/index.php?topic=415724.0
Make sure that you don't adjust the current higher than your motor allows. Read the relevant datasheet of your hardware carefully.
AND: don't connect/disconnect a motor while the power supply is ON.

2. Start to move the motor with Robin2's simple stepper program and learn about stepper basics.
Here is the thread to start with:
http://forum.arduino.cc/index.php?topic=277692.0
Before you ask:
Did you really read and understand How to use this forum ?
AND:
Do you have already some solution or is a part of the problem sitting in front of the screen?  :)

MarkT

#2
Aug 31, 2016, 02:56 pm Last Edit: Aug 31, 2016, 02:56 pm by MarkT
I'd recommend the AccelStepper library, use setSpeed () and runSpeed () I think.  It works in
terms of steps per second, so you'll have to figure that out.  The A4988 like many stepper
controllers needs a step signal and direction signal, and for AccelStepper you configure it like:
Code: [Select]

#include <AccelStepper.h>

AccelStepper (DRIVER, steppin, dirpin) ;
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

rpt007

#3
Aug 31, 2016, 05:23 pm Last Edit: Aug 31, 2016, 05:28 pm by rpt007
When using AccelStepper library, the value for DRIVER = 1 and you are free to choose any digital pin of your Arduino (besides of TX and RX pins which should be reserved for communication purposes).

Example:
If you use pin 5 of your Arduino as "STEP Pin" and 6 as "DIR Pin", then you
1. connect Arduino pin5 with driver input "STEP" (sometimes it is called "CLK")
2. connect Arduino pin6 with driver input "DIR"
3. connect GND 2 GND
4. check if you need Enable, check microstepping
5. set up AccelStepper with:

Code: [Select]
AccelStepper (1, 5, 6) ;
Before you ask:
Did you really read and understand How to use this forum ?
AND:
Do you have already some solution or is a part of the problem sitting in front of the screen?  :)

Robin2

#4
Aug 31, 2016, 07:54 pm Last Edit: Aug 31, 2016, 07:56 pm by Robin2
These links may be useful
Stepper Motor Basics
Simple Stepper Code

The second one is the same as linked to in Reply #1.

The speed of a stepper motor is determined by the interval between steps. Keep that constant and the speed will be constant.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

MarkT

Quote
When using AccelStepper library, the value for DRIVER = 1
Always use DRIVER, not 1, as the first argument to AccelStepper, its a symbolic constant and its
value could change in different versions of the library, it might not even be an integer in the future.
Also '1' has no descriptive values whatsoever whereas 'DRIVER' implies a stepper driver.

I've already indicated how to code an AccelStepper correctly,
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

zeedo65

Hi Guys

Thanks for your comments, I used rpt007 comments to learn and adjust the VREF and the other stuff, and I learnt some coding with Robins codes.

However, I want to use the shield for running the motor at constant speed. The reason that I said so is that in my workplace I can not find a breadboard (it is a chemical laboratory,  not electrical :) ) and capacitors etc. I already ordered but it arrives after several days which is late for me.

So, with the mentioned shield and the rpt007 comments and other youtube stuff I made the motor to work. But now I need to run a GCODE that continiously drive my electromotor at a constant speed. Any idea on how to do that? What can be the code?

I am using the Universal Gcode sender to send the commands to grbl 0.9.

BR

Zeedo


rpt007

@MarkT:
Quote
Always use DRIVER, not 1, as the first argument to AccelStepper, its a symbolic constant
Big learning for me - I always used "1" in my sketches; now that you kicked me to that "symbolic" point - whatever that means, as I am not a programmer by education, I will use it in the future.

I had (tried) studied the AccelStepper library but didn't pay attention to this point, mentioned in the very first sentences of the class description.

The library is a mighty one and I am happy that I got all my projects, were I use the library, are running smoothly (still with the "1"). When my customers will require to get new features in the application, I will change the "1"'s to "DRIVER", so I won't run into a problem one day, if the library would have changed to a non-integer then.

Thank you for this valuable information.
Before you ask:
Did you really read and understand How to use this forum ?
AND:
Do you have already some solution or is a part of the problem sitting in front of the screen?  :)

rpt007

@zeedo65:
You said ".. at a constant speed" - what does that mean - do you want to "jump" the motor speed from "0" to "x" without acceleration (technically not feasible by the way) ??

But I suspect, this won't be the major point for the moment.
Quote
But now I need to run a GCODE that continiously drive my electromotor at a constant speed. Any idea on how to do that? What can be the code?
Would you pls give us a bit more information what you mean by "run a GCODE .." - only one GCode command and will this stay stable or will there be many GCode commands with different parameters and you expect the stepper motor to follow those instructions?

When grbl is on board of an Arduino - it is like a new firmware and the Arduino won't be able - at least up to my current knowledge - to execute other commands than those coming from a GCode sender.

That means, that you won't be able to use any library or line by line commands as in a "normal" Arduino environment. You will be "caught" in the grbl-firmware environment, which is not the worst scenario because it opens you a lot of options to run multiple steppers at different accelerations and directions and speed etc.

In a thread of early 2014 @Robin2 said, that
Quote
I plan to write my own simple Arduino software and have the G Code interpreted by my PC. That is, a lot of the work that's done within GRBL will happen on my PC.
So, if Robin has succeeded in doing this, you might find his solution more flexible than using the grbl firmware running on your Arduino.

On te other hand - you see, I am just guessing and assuming a lot. Why don't you explain a bit more in detail, what exactly your project is all about and then we can tell you, what direction to follow. Otherwise we guide you into a jungle which won't get you to the goal you are aiming at.



Before you ask:
Did you really read and understand How to use this forum ?
AND:
Do you have already some solution or is a part of the problem sitting in front of the screen?  :)

Robin2

Following on from the reference in Reply #8 to my efforts, I am not sufficiently familar with GCode to know if there is a code to make a motor move continuously - or (if there is) if GRBL is designed to interpret it.

I don't think GRBL can interpret every Gcode instruction that a big commercial machine could.

GRBL is normally used for tasks which have a series of finite movements within the physical limits of a milling machine.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

MarkT

#10
Sep 02, 2016, 12:13 am Last Edit: Sep 02, 2016, 12:13 am by MarkT
G-code is all finite line segments and arcs, nothing unbounded, since it is motion control.
However there is scope for things like spindle motor speed and switching it on and off which
are continuous.  I cannot recall if GRBL has any support for that sort of thing.

Quote
I don't think GRBL can interpret every Gcode instruction that a big commercial machine could.
I think you can be stronger than that - it simply cannot at all do anything like a big commercial
machine - those are frankly astonishing in their power and sophistication and accuracy.

It'll do you a 3D printer or simple CNC machine though.  Throw a more powerful process at
the task and you'll get more capabilities.  LinuxCNC is based on the original MIT codebase for
CNC research IIRC, that'll get you a lot closer to higher end capabilities.  There are other,
non-free software suites too that use the power of a full-blown processor.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

rpt007

But we still don't know the exact requirements from the OP.
I think only then we could give him some better advice, before we begin to think in bigger complexities.

I suspect the project challenge is much simpler, but I am only guessing as long we don't have better information what he really wants to achieve (another XY issue ??).
Before you ask:
Did you really read and understand How to use this forum ?
AND:
Do you have already some solution or is a part of the problem sitting in front of the screen?  :)

zeedo65

Hi Everyone

Thanks, I was a bit far these days from this project. Sorry, I just want to run a pump with a speed of 70 RPM using the GRBL. But, as you mentioned, I could not do that because the codes were not letting me to move the steppermotor continiously. Sorry, you are much expert in this field than me so your minds got far beyond my thoughts :) If you have any suggestions, I would be grateful.

Best regards

Zeedo

Robin2

If all you want is to run  stepper motor at a constant speed why do you need GRBL?

My Simple Stepper Code can do that.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

rpt007

#14
Sep 17, 2016, 05:18 pm Last Edit: Sep 17, 2016, 05:19 pm by rpt007
If you don't need to use GCode, GRBL is not needed at all and might even block your intention to just run the stepper at a constant speed.
Before you ask:
Did you really read and understand How to use this forum ?
AND:
Do you have already some solution or is a part of the problem sitting in front of the screen?  :)

Go Up