Seeking Advice on Libraries/Shields for Projects Involving Stepper Motors with Encoders

Hello Arduino Community,

I'm embarking on a project to build a motorized drive for a telescope mount, specifically for the RA (Right Ascension) axis, to counteract the Earth's rotation. The project involves controlling a NEMA 17 stepper motor paired with a rotary encoder for manual microadjustments. Given the commonality of tasks involving stepper motors and encoders in robotics and DIY projects, I wonder if there are existing libraries, shields, or driver modules that can simplify this process. I don't want to reinvent the wheel, and don't want to spend time tweaking and debugging unexpected problems, that a community of robotic enthusiasts should have already solve.

Questions:

  1. Libraries: Are there any recommended Arduino libraries specifically tailored for synchronizing stepper motor operations with encoder input? I'm looking for something that could facilitate smooth integration of the motor's automatic movement with manual encoder adjustments.
  2. Shields/Drivers: Is there an all-in-one shield or driver module that supports both a stepper motor and an encoder, ideally optimized for ease of use and minimal wiring?
  3. Examples/Tutorials: Can anyone point me towards tutorials or project examples that involve similar setups? I believe in not reinventing the wheel and would appreciate any guidance or references to similar projects.

Goals:

  • Ease of assembly and programming, as my access to sophisticated tools and advanced soldering equipment is limited.
  • Cost-efficiency, utilizing readily available and affordable components.
  • Reliability and precision in tracking, suitable for amateur astronomical observations.

I'm eager to hear your suggestions and learn from your experiences. If there are any shortcuts, existing solutions, or advice you can share, it would greatly expedite my project and help me avoid common pitfalls.

Thank you in advance for your time and assistance!

  1. Not heard of.
  2. Not heard of.
  3. Hard to say without a more detailed specification.

To be clear. by rotary encoder do you mean a knob for user input, or an encoder on the motor?

Either way, the closest is probably a 3d printer board which often have support for LCD and encoder.

Not really sure what that means. Although people often ask for "a stepper motor controlled by a pot", I think your application is somewhat unique. However, there are libraries for steppers, and libraries for encoders, it should be easy enough to write a sketch using both.

You might search for "barn door tracker", which I believe addresses the same issue.

1 Like

Hello bobcousins, Thanks for the reply. By the rotary encoder I mean a knob for user input. My idea is that by rotating this knob I will be able to slightly adjust the rotation of the stepper motor. Anyway, I just ordered a starter kit with a stepper, driver and arduino and will start my experiments.

I once used an electronic tracker that held the automatic sidereal speed, and used a momentary 2-way toggle to slew either faster or slower than sidereal.

How would you expect to use the encoder information to adjust the rotation of your setup?

The basic case could be handled by:

Here's that code expanded into a Wokwi simulation:

1 Like

As I recall, the commercial devices all use synchronous AC motors to avoid the stop-start pulsing of a stepper motor. Have you researched others using stepper motors?

The non-commercial homebuilt one I used as a kid worked with a synchronous motor, using a 555's square wave to feed a transistor into transformer driving the geared synchronous motor.

Hi DaveX,

Thank you for the elaborate reply. I like the link to the Wokwi simulation. I didn't know there are such convenient things. My idea with the encoder is this - I would like to be able to adjust the orientation of the axis by rotating the encoder in one direction or in the opposite. Right now if I see misaligned the scope when I was freely rotating it, I have two choices - I can try to align it again by looking into a finderscope, or I can just wait till the object will appear in the view of the telescope because of the Earth rotation. With the encoder I want to be able to slightly move the view field of the telescope into one or another direction. I can do it right now with adjustment knob. But once I will mount the stepper motor - I wont be able to freely rotate the knob.

I guess my idea is somewhat similar to the slider that are there in your link that ajdusts the speed of rotation. But in my case I would like to be able to even rotate the stepper in the opposite direction.

Hi Paul_KD7HB. To be fair, I've seen a lot of projects where people were using stepper motors exactly for this purpose. But the existing projects are usually more complicated and tracks the starts in both axes. I just want to be able to adjust only one axis.

Ok, Can you make a drawing of how you will mount the stepper motor and how you will connect the motor armature shaft to the telescope mechanism? Perhaps using a resilient connection rather than a completely solid connection would dampen the stepping movement.

There seem to be quite a few DIY projects around, I guess because a commercial star tracker is quite expensive. But not everyone can afford "observatory class" solutions.

As I understand there are 3 types of mount, RA gear driven, tangent (or radius) arm and barn door. For our purposes however, the mechanical principles are similar, in that a motor is used to provide motion and software is used to control movement and compensate for any non-linear motion etc.

This thread https://www.cloudynights.com/topic/116068-stepper-motor-for-ra-tracking/ discusses stepper motor solutions. A couple of quotes :

Basically, there are two general approaches:

  1. Low end stepper (low torque with 24steps/rev or 48steps/rev) with a high gear-down transmission (e.g., 1:130 gearbox).
    Net mechanical reduction is in this range:
    1/130 * 1/180 (worm ratio) = 1:23400

Even with half-stepping, some are not comfortable about the jitter caused by stepper.
Since the gearbox ratio is high, the fast slew speed is fairly slow (typically 8x, some do 16x).

  1. High end hybrid stepper (high torque and 200steps/rev) with a low gear-down transmission (e.g., 1:4 spur gear).
    Net mechanical reduction is in this range:
    1/4 * 1/180 (worm ratio) = 1:720

This system has be using micro-stepping (e.g., 1/64 microstepping) to take out the jitter.
This system has to use high-end microstepping driver with ramp-up/ramp-down capability to avoid motor stall.
Fast slew speed is very fast (typically 800x).
This system can be used for GOTO.

I had written a detailed analysis in a different forum.

{EDIT}
In the second type using microstepping, the incremental movement is also in fine granular. Using the example given, per movement is 1/720 * 1/64 = 1:46080

and

The magic number in this space is to make the movement scale in the range of 0.15 to 0.5 arc-second/"movement scale".

Too low the number, fast slewing is going to be too low.
Too high the number, jitter will be seen.

The other magic is to know the final torque and how to achieve it. Commonly used two methods have been provided.

Some commercial mounts (e.g costing £6,0000) I looked at achieve a resolution of 0.11 arc-seconds or less, so 0.15 to 0.5 arcseconds is a good number to aim for.

Modern stepper drivers have up to 256 microstepping, so with a typical 1.8 deg stepper, that is 51200 steps/rev, or 0.07 arcseconds per step. So even with a direct drive that is pretty good. Note that microsteps are not "real steps", i.e they are interpolated and may not be exact.

However, we can improve natural accuracy by using a 0.9 stepper, and/or gearing.

So in summary there is a tradeoff between low jitter and fast slew rate, but in principle a stepper motor can achieve a level of accuracy regarded as "high quality".

2 Likes

They make dual shaft steppers, to which you could mount a knob, and it would be possible to disable power to the stepper during manual operation.

As for motion in the opposite direction, that is just a matter of degree and could be coded in to reverse the stepper.

In my dad’s drive from what I remember 50 years ago, we’d engage it for photography, and make only small +/- adjustments to the basic rate in order to better frame the steady view

What I was curious about was how you envision mapping encoder steps to stepper steps and steady motion. Do X encoder steps move the stepper Y steps or do they adjust the steps/ sec slew rate somehow?

The barn door mount handles the slew vs tracking by doing the slewing with fast manual controls on the telescope but moving the base at the smooth, mechanically scaled pitch/radius/steps rate. @johnwasser's example gives 1/400/200*pi/180=2.6 arc seconds before any microstepping, so you could use it (or that Wokwi sim) with 1/8 microstepping to get to 0.32 arc seconds at with 24ms between between steps.

Paul, I'm not sure this deserves any drawing. I just want to use something like in this photo (not mine) https://content.invisioncic.com/g327141/monthly_2017_04/DSC04868.JPG.a04a555030ddc029796cf250b3b85e09.JPG

Bobcousins, thanks for the link to the cloudynights, and for providing some actual numbers. This is very valuable as I don't have a good intuition for what parameters I need to look for in the stepper motor. I'm still not sure how to use the micro stepping, and why people always mention this micro stepping aspect when they discuss the usage of steeper motors in similar projects. I have a feeling that achieving micro stepping is more difficult to do just "conventional stepping". Anyway, this thread on cloudynights seems very valuable to me. Thanks again.

The dual shaft stepper looks like a wonderful idea! I didnt know you could do that. And this is a real simplification. The only downside to this, is that I would physical touch the mount and this will result in shake of the scope. Though, I'm not sure how bad this is for my case because I can hardly see anything in my scope from my backyard if I use x180 magnification. But still it would be nice to be able to control the scope movement "remotely".

As for the actual mechanic I though of X encoder steps move the stepper Y steps. So first I stop the continuous rotation with a button, and then, by rotating the encoder I move the axis Y step in the one or in the opposite direction.

With your pic, a long shaft stepper could be an option as well.

The gearing and microstepping options trade off speed versus accuracy and precision and vibration. If you know what you are turning, it's all just timing and ratios.

This is the circuit I've managed to setup on the woki site.

I've used the BarnDoor example and modified it a bit. I don't have experience writing code for Arduino, so I'm not sure if I'm using idiomatic ways of accessing the button and encoder so I'm a bit worried this code isn't exactly correct.

This all works fine in the simulation, but I'm have no idea if this will work in the real device. I know that real electronic devices are more complicated than Lego constructors, and there are unexpected effect everywhere.

Could you please clarify to me a few moments:

  1. I've used external interruption to control the state of the encoder. As Arduino Nano has only 2 pins that can be setup for external interruption - I've used the PinChangeInterrupt library for setting up interruptions for the button. How bad this decision is? Will it work in a real world?

  2. The encoder connected to the Arduino without physical pullup resistors. I'm not sure how reliable this is. I would like to use long cables (maybe a few feet).

  3. The denouncing is handled in the program. Isn't it better to use small capacitors for this?

Also, maybe in my program there are some obvious mistakes that can potentially lead to bugs that I can't even think of right now. Could you please let me know if you see anything like this after a brief look?

Thank you in advance. I really appreciate your helpful insight.

After the simulation has started you need to press the button on the encoder to start the motor rotation. To stop the rotation you need to press one more time. You can manually rotate the stepper with the encoder only if the automatic rotation disabled.

  1. Those decisions should work in the real world, depending on your actual hardware and circuit. Wokwi does not do any of the electrical simulation.

  2. Internal pullups can work fine for a couple feet. If not, you could add external pullups.

  3. Depending on the actual encoder, it may already produce a debounced signal. The encoder that the Wokwi encoder is modeled after is a slow and noisy encoder. Wth the barn door calcs, I doubt you could spin it fast enough to keep up with sidereal motion. Maybe a nice optical encoder with lots of PPR would be nice. My sloppy sketch with the pot aimed at being able to make small adjustments to a pretty fast stepping speed. But your device and usage would certainly be different.

1 Like