RDL - Serial-Port Stepper Motor Command-Line Utility with Smooth Stepping

Hi,

Note RDL Version 2 is out: RDL V2 Stepper Motor Serial Command-Line Utility - Motors, Mechanics, Power and CNC - Arduino Forum

I want to share a handy Arduino sketch that I have been using to test various stepper motors and mechanisms.

In use, the user types movement and setting commands in serial port or serial monitor, to send commands to the Arduino.

Most movements are done with smooth stepping. Motor settings and timings are saved to the Arduino's EEPROM, automatically.

There are hook-up instructions and pin definitions in the beginning of the code.

Video Manual RDL - Arduino Serial Command-Line Stepper Motor Utility - YouTube
Code Review: Coming soon.

Features:

  • ? Shows command list.
  • @ Shows position.
  • . Shows settings.
  • Automatically, saves many configuration settings to EEPROM.
  • Most movements use sinusoidal smoothing with time-compensation code.
  • Has variable/proportional analog single-axis joystick support for movement, rotation, and increments.
  • Works with both Step/Dir and Step/Step type drivers by using "setdirmode" .
  • Has a "setspeed" to divide the motor speed for testing.
  • Floating-point position math used.
  • Fits and runs on an Arduino Micro, barely.
  • Supports "sleep" and "wake" to enable and disable the motor by driver.
  • Has a g)oto command to move by absolute movement.
  • Settable and goto-able: s)tart, h)ome, and e)nd positions.
  • Has an "setlimitmode" option to use the n)one, h)ardware s)oftware, b)oth of the start and end positions.
  • Has linear and rotary modes that can be set set with "setmode" .
  • Has a l)inear mode that:
  • Can be set with "setsteps" to move a given physical distance, such as setting it to 1200 per milimeter
  • Has a m)ove command for relative movement.
  • Homes using multiple revolutions if you are has moved that far.
  • Has software limits that will not put the motor to sleep.
  • Has preliminary hardware limit-sensor support that will put the motor to sleep.
  • Has a default r)otary mode that:
  • Can rotate by t)urn or d)egree.
  • Can "divide" by a given number of segments, change them with "+" , "-" or the joystick, or user "/" to choose a particular one.
  • Homes to closest angle of a single revolution.
  • Can auto-home "ah" with optional EEPROM optional settable final offset for correcting mechanical misalignments.
  • Has a "setmicrosteps" command to software set microsteps, after choosing "A4988" or "DRV8825" with "setdriver" .
  • Has an option to automatically scale your current steps during a "setmicrosteps" microstep change.
  • You have already been introduced to 23 of RDL's 39 commands.

Note: Compiles fine on Arduino Micro and 1.8.1, but may give memory error with older Arduino IDE.

Changelog:
1.158 Changed limit and E-Stop default states for easier first-time setup for without switches.
1.157 Fixed joystick bug where if it were absent, the motor would run. To use joystick, it must now be enabled in code.
1.157 Flash Memory Use Down by 3% by adding the joystick enable. I am not sure why, but okay.
Version 2 is out! RDL V2 Stepper Motor Serial Command-Line Utility - Motors, Mechanics, Power and CNC - Arduino Forum

Enjoy : )

BrendaEM
My Youtube Page
My Patreon Page

RDL_158.ino.ino (62.3 KB)

RDL had a nice write-up in Hackaday.com. Thanks!

Very cool! Should making learning stepper motors a bit easier. Nice job. (FYI, found it via Hackaday.)

Thanks Brenda, this looks good. I was thinking several times recently that I need such a utility and should really get round to doing something, so if I can get this working you will have saved me some effort.

I connected a small stepper to a small anonymous ebay 'step&dir' -type driver board, downloaded your code to a Uno clone but no joy so far. How do I stop it spewing text? I disconnected the Arduino from the driver board but it's just the same. The text does look like the right kind of thing - motor, turn, degree, steps and only halts briefly when I type something intended to affect it (s, h . ?) but it's too fast to read the numbers or see if it responded to me and then got overwritten quickly.

Any thoughts? Thanks.

(PS I found this through Hackaday too.)

Sickparrot, firstly, you should check the pin definitions in the beginning of the code.

If it is spewing text, it is likely moving. Is your joystick centered, or you do you have one?

I had a checklist of functions to test. There might be an issue if there were no joystick. I will check it.

Brenda, thanks for responding. I started with what seemed simplest - just the dir (D11) & step (D12) pins and nothing else. Looking at the pin definitions in the code, it seems all the others are optional. Have I mis-read this?

I do have a joystick I could add but hoping to get it responding to command line first.
At present I have nothing connected to the 'Arduino' and it's still sending serial text continuously. Does it need to be connected to a driver for the text output to make sense? I'm also wondering whether some old data in the EEPROM is confusing it.

In your video the monitor output was static waiting for a command so I can't think what's different here.

Yes, they are supposed to be optional.

Can you capture any of the text? If it is positional information, it's likely that it is doing a movement.

I had a massive amount of real-life things to do today, but I will check on it tomorrow.

If there were "garbage" in you EEPROM, it would have re-wrote it.

Also, it will default to 9600bpm. And it uses the default /n /cr terminal settings. I am not sure what has gone wrong, but I will also bring my nano clone. The micro/newer chips do have differences in the serial handling. Perhaps that is it.

I will check it.

Thanks for reporting it.

Brenda, to exclude specific hardware problems, I tried loading RDL onto a Nano (clone) with no connections except mini USB to the PC and it's also constantly emitting text.

To slow down the text enough to capture some, I added a delay(3000) at the top of the loop() and got this:

RDL v1.156 by BrendaEM
EEPROM Read
Motor = awake

RDL:
Motor = sleeping
Emergancy Stop
 
Motor = sleeping
Turn = 0.005000
Degree = 1.800000
Steps = 1.000000
.
.
. 
.
Motor = sleeping
Turn = -1.224999
Degree = -440.999664
Steps = -244.999816
Motor = sleeping
Emergancy Stop
 
Motor = sleeping
Turn = -1.229999
Degree = -442.799652
Steps = -245.999816
Motor = sleeping
Emergancy Stop

This shows the initial output and typical output from a little later.

I hope this is useful.

Thanks
Andrew (UK)

The joystick issue should be fixed now in 1.157. Indeed the joystick was running on. The joystick has to be enabled in the code now, but that's during a hardware change anyway.

If you get estop notifications with no estop, change the estop "estop_tripped" value in "// Sensor States."

it's now 3% smaller for some unknown compiling reason.

Thanks for the feedback : )

Brenda, thanks for adding the joystick_enable; with it set false, it stopped the stream of text which is good but set true or false it does not respond to ? . or @ or other commands. It waits a second then I get the RDL prompt but with no apparent other effect.

I decided to add a joystick and it does turn a motor now (though I'm not sure nothing else was changed!) It does respond to the joystick (proving the driver and connections are good) but I still have no command line control.

I don't know the settings but I must have something set wrong.

Please help! Thanks

PS using RDL_158 (newest)

I brought my laptop to work on it tonight, but my laptop is not charging, and will go dead soon. I will have to look at to tomorrow afternoon.

I am looking at it on my roommate's Macbook Air, which I am not used to. This might take a bit : )

Still checking. You might try a setdefaults .

I'll try setdefaults but can't just now.

I've noticed the joystick doesn't affect the speed, just whether the motor moves and direction.

The speed is quite slow taking about a second to rotate once and that's only 20 steps.

Added: I typed setdefaults and it came back with the RDL prompt but nothing changed.

If you can't adjust speed with the joystick, it might be hooked up to a digital pin instead of an analog one. You might check the pin definitions, as well.

Bug hunting will be interesting if the program (I hate the term sketch) lives up to intent.

Nope - it's on pin marked A0. On a Nano it's between A1 and REF so it'd be hard to get it that wrong.

I wondered if the resistance range of cheapo joysticks is consistent. That could mess things up.

Do you know why I never see any text in response to anything I type except a prompt? And why what I type has no effect on the motor when the joystick does (sort of) ?

I like the intent of this program (yeah, 'sketch' hmmm.... ) but I wanted to control a stepper with the command line so if I can help you get this right for other users, I'll do what I can. It still may be that you're perfectly correct and I'm doing something stupid).

PS Time zones differ - I'm GMT.

I am sorry that you are still having problems.

If you have a multimeter, a properly (in this case) joystick axis should put out 2.5V to the Arduino analog pin and the Arduino ground, while the joystick it is centered. Likewise, about 0 volts at one end, and about 5 volts the other. If you cannot produce roughly 2.5v at center, then I would attend to that.

Generally, the Arduino IDE terminal window does not place echo characters on the screen. Though if you type a command into the 1-line text box and send it to the Arduino, it should respond, well, if the joystick isn't going rail to rail and is activated by the joystick_enable constant in the code.

What I need to do: watch other people hook their hardware in their own way and test the program. If this program works as it should, it will be adapted in ways I wouldn't have thought of.

Thanks you for your patience,
Brenda

The joystick/A0 pin is around 2.5V or a bit less, so that's ok. The ends are 0V and about 5V as they should be. Since it responds to the joystick when moved by rotating the motor and reporting values for turn, degree steps I think that's working ok.

It doesn't respond to input commands so that's where the problem is (for me). It's seeing me type something as I get a prompt but nothing else. Something is different between your setup and mine. What can it be? Has anyone else reported typing commands and getting no text response or movement? Have you tested your code always with the same setup?

One difference is that I think you're using MS Windows while I'm on Linux but why should that matter? Might the compiler output (or the arcane compiler options) be different !?? Seems possible but unlikely.

Thanks for checking the voltages.

If you are using the terminal window from inside the IDE, you might try changing drop down box options at the bottom for "No Line Editing" and what have you. I know that it won't take a command if those are not set just so, which is "No Line Editing"

Generally, unless I've changed the data structure, I've noticed odd behavior in every few hundred uploads as far as the saved EEPROM data, that's why I also suggested loading the defaults, but it was quite rare.

Also, does it does compile okay with no red warnings?

I will look at again tomorrow.

I have all the options unhooked now except for the stepper driver/motor. No joystick, no buttons, no homing sensor. Buttons are set to HIGH; joystick_enable is set to false in the code.

Although these are really low-level changes, I still might put them as interactive options IF I can first makes some room in the code. As a goal, I want to leave some room for a user to add a function.

My computer is being repaired, and the code might change, so I've delayed the code-review video.

256 People downloaded the code, and 88 for the new version; has anyone got it working?

Thanks,
Brenda

The next version of RDL will have a more hierarchical movement handler scheme, whereas most floating point absolute and relative movements are done through the same code.

The software bounds checking will also be moved to an external function.

I may add a command or two, but I will leave some room for users to add their own command or two.

Memory will still be tight on the Arduino Micro, though. Not so much on the Nanos and compatibles.