Go Down

Topic: RDL - Serial-Port Stepper Motor Command-Line Utility with Smooth Stepping (Read 6348 times) previous topic - next topic

BrendaEM

Hi,

Note RDL Version 2 is out: http://forum.arduino.cc/index.php?topic=469343.msg3213804

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 https://www.youtube.com/watch?v=Lm8oprDhAnQ
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! http://forum.arduino.cc/index.php?topic=469343.msg3213804

Enjoy : )

BrendaEM
My Youtube Page
My Patreon Page

BrendaEM

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

http://hackaday.com/2017/03/05/a-command-line-stepper-library-with-all-the-frills/

cmiyc

Very cool! Should making learning stepper motors a bit easier. Nice job. (FYI, found it via Hackaday.)
Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

sickparrot

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.)

BrendaEM

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.

sickparrot

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.




BrendaEM

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.

sickparrot

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)



BrendaEM

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 : )

sickparrot

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)

BrendaEM

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.

BrendaEM

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 .

sickparrot

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.

BrendaEM

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.

sickparrot

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.


Go Up