Jump to content

Stargazers Lounge Uses Cookies

Like most websites, SGL uses cookies in order to deliver a secure, personalised service, to provide social media functions and to analyse our traffic. Continued use of SGL indicates your acceptance of our cookie policy.

# Correct control of stepper motors

## Recommended Posts

I'd like to ask for an advice regarding a driving my stepper motors by the RPi and the A4988 controller.

Presently I send pulses with delays calculated using equations of transformation Ra/Dec->Az/Alt for DSO and some extra equations and tables for the Sun and the Moon. I gonna write some modules for planets as well, but not yet. At this moment I'd like to rebuild my software and implement a GoTo-like system. While a testing of a quality of driving (using lasers beam) I realized that it takes over 5 minutes to make a full revolution around Az axis (1433600 steps in total). The quality is satisfactional, but the time - not...

I've got an information that the full revolution should take a few tens of seconds, so I will be happy to obtain even 30 seconds for a half of the revolution that menas a farest object (opposite one) in relation with the previous one. The direction doesn't matter - I have no limitation in Az axis, my Dob can rotate all night around.

Thus I'd like to ask the question: what kind of driving and what library (for Python 3) should be used to be able to obtain:
- acceleration ramp - I have a homemade 450mm worm gear having an aluminium ring with hobbed 3/8" BSW thread, so I have to accelerate it from 0 to maximum possible speed then slow down (negative acceleration) back to 0,
- remembrance of a number of steps/actual position - the Ra and Dec can change while the previous Az and Alt positions have to be a point of reference for a next move.
I'm not sure if something else can so important.

I have an idea to switch configuration of jumpers of the A4988 controllers "on the fly". I could make a kind of "driver" changing number of micro steps directly from the RPi (of course with disconnecting the +5V as first). Presently I use 8 micro steps (the gearboxes have 896 and 897 teeth) that gives me about 0.9 arcsec/step, so the full revolution takes over 5 minutes. If I could change the number of micro steps from 8 to 0 and then use full steps during a change of position, then I could gain the change of 180 degrees within 18 seconds!

That's great idea if:
- I can safely change number of micro steps,
- I will develop method of keeping actual number of micro steps.

Every steps means 8 micro steps, so after the movement I should change the position by 8 * number of full steps. Sounds good, but I think it seems to be a breaking the open door if the proper library exists somewhere.

I tried to find any "fast driving" library, but didn't reach good results.

The perfect example is a CNC milling machine: can rapidly move a router across the table and as well very precisely and slowly operate with tool.

#### Share this post

##### Share on other sites
1 hour ago, Vroobel said:

I have an idea to switch configuration of jumpers of the A4988 controllers "on the fly". I could make a kind of "driver" changing number of micro steps directly from the RPi (of course with disconnecting the +5V as first). Presently I use 8 micro steps (the gearboxes have 896 and 897 teeth) that gives me about 0.9 arcsec/step, so the full revolution takes over 5 minutes. If I could change the number of micro steps from 8 to 0 and then use full steps during a change of position, then I could gain the change of 180 degrees within 18 seconds!

If you connect the MS1, 2, & 3 inputs of the A4988 to 3 GPIO outputs on the Pi  rather than use jumpers you can then change the micro-stepping mode at any time in your program without having to disconnect anything. You just need to check that the stepper has moved a multiple of 8 micro steps before switching to full step mode to avoid missing some microsteps.

Can't help with the python libraries I'm afraid as I've used Arduino Nanos in my stepper projects.

Alan

#### Share this post

##### Share on other sites

In order to run at tracking rates and slew rapidly, you will need to use those micro steps and keep track. Change electronic gears on the microscope boundaries and you can keep track. Overdrive the steppers in voltage to get good stepping rates, your controller is good for 4amps of current control.

You might like to have a look at onstep and ramps for examples of handling slew movements. Both have available source code.

#### Share this post

##### Share on other sites

Thank you for that. First of all I have to throw out the presently used Arduino shield with jumpers. A new board should be designed and the controllers should be driven straight from the RPi. Unfortunately I use 3 stepper motors, one of them is for a focuser. The one can be set up by jumpers, but I still need 6 pins of GPIO for the micro steps controlling.

So before I start looking for proper libraries I have to sort the new board. I'll inform about results.

Thanks again.

#### Share this post

##### Share on other sites

Actually you don't need all those pins. Upgrade to the trinamic controllers and you can use spi and run all three off a serial interface.

The onstep drives two axis motors and two focus motors this way.

#### Share this post

##### Share on other sites

Thank you, skybadger. That sounds good. I just tried to connect A4988 drivers on universal board straight to my daughter's RPi, but I think I should read about the mentioned drivers.

#### Share this post

##### Share on other sites
2 hours ago, Vroobel said:

but I still need 6 pins of GPIO for the micro steps controlling.

If you only need to switch between full step and 1/8 step you only need 1 GPIO pin per stepper connected to MS1 and MS2 shorted together. MS3 can stay jumpered to low permanently.

Alan

#### Share this post

##### Share on other sites

I connected all three MS lines together and to one GPIO pin to get 16X and single step modes.

#### Share this post

##### Share on other sites

Maybe add in encoders so the processor “knows” where the scope is pointing at all times, and write a set of arrays to store these data sets the processor can then use to calculate ramp up-down slewing speeds?

#### Share this post

##### Share on other sites
2 hours ago, symmetal said:

If you only need to switch between full step and 1/8 step you only need 1 GPIO pin per stepper connected to MS1 and MS2 shorted together. MS3 can stay jumpered to low permanently.

Alan

OK, but can I do it for two drivers in one time using 1 pin? Shortly saying, can connect M0 of 1st driver with M0 of 2nd driver, etc? Or should I keep them not connected?

Sorry, different labels... MS1 = M0.

Edited by Vroobel

#### Share this post

##### Share on other sites
2 hours ago, Gina said:

I connected all three MS lines together and to one GPIO pin to get 16X and single step modes.

I prefer to use 8 micro steps. I don't need 0.45 arcsec/step accuracy. 0.9 is good enough at this moment, but I am still ready to do it, as A4988 can do it. Moreover, DRV8825, which I have as well, can do 32 micro steps. But the bigger number of micro steps the smaller torque and bigger possibility of loosing the steps.

#### Share this post

##### Share on other sites
1 hour ago, theropod said:

Maybe add in encoders so the processor “knows” where the scope is pointing at all times, and write a set of arrays to store these data sets the processor can then use to calculate ramp up-down slewing speeds?

Thanks. I will try without the encoders. I should have the ones with a resolution equal at least 200x8. They are expensive I think.

#### Share this post

##### Share on other sites
30 minutes ago, Vroobel said:

OK, but can I do it for two drivers in one time using 1 pin? Shortly saying, can connect M0 of 1st driver with M0 of 2nd driver, etc? Or should I keep them not connected?

Sorry, different labels... MS1 = M0.

If you want both drivers to step at the same rate then you can connect the MS inputs together on different drivers. The MS lines (along with the step, direction and enable inputs) are all high impedence input connections so there is no problem in connecting them together if you wish.

Alan

Edited by symmetal

#### Share this post

##### Share on other sites

I need same rate for Az and Alt, so need 2 pins. But I'll reserve 3pins in case of change of mind if I need doubled precision. Moreover, I can set the precision whilst setting it up every time. The motofocuser can use jumpers.

#### Share this post

##### Share on other sites

Having a separate MS control pin for Alt and Az is easier if you envisage Alt and Az slewing at the same time, as they will need switching to microstep mode at different times. If you slew one axis then the other , you could have one MS control pin for both axes.

Alan

#### Share this post

##### Share on other sites

There are plenty of GPIO pins available on the RPi - you shouldn't have a problem.

#### Share this post

##### Share on other sites

But I have end stop switches for motofocuser and Alt axis (can't drive more down under horizon and more up behind zenith), buzzer and some other ideas like smart dew heater based on measurement of humidity and temperature, so I have to save the pins...

#### Share this post

##### Share on other sites
4 hours ago, symmetal said:

Having a separate MS control pin for Alt and Az is easier if you envisage﻿ Alt and Az slewing at the same time, as they will need switching to ﻿microstep mode at different times. If you slew ﻿one axis then the other , you could have one MS control pin for both axes.

Alan

I'd like to calculate a kind of vector for both Az and Alt axes and drive them in one time. That should be more efficient I think. When I stop in calculated position, the object moves, so I have to drive slowly to exact position using micro steps. If I do the slew in two steps, the object moves more.

#### Share this post

##### Share on other sites
1 hour ago, Vroobel said:

I'd like to calculate a kind of vector for both Az and Alt axes and drive them in one time. That should be more efficient I think. When I stop in calculated position, the object moves, so I have to drive slowly to exact position using micro steps. If I do the slew in two steps, the object moves more.

Yes, I agree driving the two axes at the same time would be quicker in getting on target with less fine adjustment needed at the end.

Do you need end stop switches on the focuser?. Assuming the focus stepper is permanently attached and you save the current position in flash memory it will know where it is when you power up next time. You just need to initially set specified count values as your end stops. If the torque of the stepper is not too great there would be no harm done if the focuser did try to drive beyond the  physical limits. I've tried to drive my rack and pinion focusers beyond their limits when messing about setting them up and they just stop moving with no complaining. The stepper motor doesn't care that it can't move any more as they are effectively operating in a stalled mode all the time. The stepper driver sets the maximum current the stepper can use.

Alan

#### Share this post

##### Share on other sites

To be honest, I didn't think that I could/should remember current position of the focuser when I shut the system down.  Whilst a preparation to changing an original construction I tried to join its axis with standard 0.65Nm Nema 17 stepper motor, but it was not strong enough. So I bought same stepper motor containing a 5:1 planetary gearbox. On the end of the job I took a telescope outside and was so fascinated by its effects that didn't realise a power of that solution. I was surprised and shocked when the pinion jumped over the rack. My first idea was to implement 2 small end stop switches and it works fine.

#### Share this post

##### Share on other sites

Ah, you've already got the end stop switches in place so no problem. I just thought it might save you having to build them.  If the stepper is too powerful you could always set the driver's current limit adjustment pot to a lower value to reduce the torque.

Alan

#### Share this post

##### Share on other sites
17 hours ago, Vroobel said:

I'd like to calculate a kind of vector for both Az and Alt axes and drive them in one time. That should be more efficient I think. When I stop in calculated position, the object moves, so I have to drive slowly to exact position using micro steps. If I do the slew in two steps, the object moves more.

Yes, and you know roughly how long it takes to transition from slew to track so build that into your landing point estimate in terms of time and position then make small feedback adjustments when you get that based on a real time.

#### Share this post

##### Share on other sites

That is exactly what I want to do ,as I've seen original GoTo in action on YT. A conclusion was only one.

#### Share this post

##### Share on other sites

Hi,

If you don't mind giving up on the RPi and using a different board there is a very good stepper library for the Teensy range at https://github.com/luni64/TeensyStep

If you use a Teensy 3.6 board you have over 40 GPIO pins available and hardware FP calculations at a 180 MHz clock rate, so way more than fast enough fpr motor control. The only other downside for you might be that the Teensy's use the Arduino IDE so you need to program in C++ - or at least the bastardized Arduino dialect.

I don't have any experience of this stepper library yet but I am planning to change my Obsy motor drives to use it in place of Accelstepper as it will offer some valuable improvements for my particular case.

HTH

Regards, Hugh

#### Share this post

##### Share on other sites
58 minutes ago, hughgilhespie said:

Accelstepper as it will offer some valuable improvements for my particular case

I dont understand that comment - I have used this library on many occasions for both focuser and filter wheel control - it is excellent IF its matched by the hardware/driver specification. Something like a Nano works great,Teensy even better but it will drive steppers using ESP2866/ESP32 but I have found you have to be careful ,ESP's are really 2 "operating systems" (when used with Arduino IDE) and don't really like delays which can effect the TCP stack (and crash) unlike the Nano/Teensy which are "one task robust cart horses".

The main advantage of Accelstepper,IMO, is it's accuracy,flexibility and ability to control a broad range of Stepper drivers with little code changes.

Please explain how and what improvements you will get - always open to better ways/methods

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×

• ### Recently Browsing   0 members

No registered users viewing this page.

×
×
• Create New...

## Important Information

By using this site, you agree to our Terms of Use.