Stepper Motor Homing

For other supported Arduino products from Adafruit: Shields, accessories, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
BPerry
 
Posts: 7
Joined: Mon Aug 10, 2020 5:53 pm

Stepper Motor Homing

Post by BPerry »

I am attempting to use an Adafruit MotorShield v2.3 to control a NEMA17 stepper motor that moves a worm gear slide rail. I would like to be able to use Adafruit_MotorShield.h rather than the Adafruit_StepperMotor library. I need to move the stepper to stop at a limit switch to gain a starting position. Is there a way to set a current position using the Motorshield library? I have seen ways to do it with the StepperMotor library as it has a "setCurrentPosition" function but am unable to find out what the parameters would be for statements such as; "AccelStepper stepper(1,7,6);" when using the Adafruit MotorShield v2.3 . Any help would be greatly appreciated!

User avatar
adafruit_support_bill
 
Posts: 88090
Joined: Sat Feb 07, 2009 10:11 am

Re: Stepper Motor Homing

Post by adafruit_support_bill »

The Adafruit_Motor_Shield_V2_Library is a low-level library that provides basic stepper motor functions. https://github.com/adafruit/Adafruit_Mo ... V2_Library
The AccelSteppr library works with the Adafruit_Motor_Shield_V2_Library to provide higher level stepper functionality such as position.
See the library reference here: https://www.airspayce.com/mikem/arduino ... epper.html

User avatar
BPerry
 
Posts: 7
Joined: Mon Aug 10, 2020 5:53 pm

Re: Stepper Motor Homing

Post by BPerry »

If I were to use the AccelStepper with the MotorShield V2.3 and the NEMA17 by Adafruit and using the connector for M3 and M4, how do I know what the pins are to assign. I know it’s a 4wire but am worried about it going up in smoke if the stepper wires are wrong. A sample code used “ AccelStepper stepper(1,7,6);” but how do you know what numbers to use in this? Sorry for my ignorance.

User avatar
adafruit_support_bill
 
Posts: 88090
Joined: Sat Feb 07, 2009 10:11 am

Re: Stepper Motor Homing

Post by adafruit_support_bill »

Code: Select all

A sample code used “ AccelStepper stepper(1,7,6);” but how do you know what numbers to use in this? Sorry for my ignorance.
That is for a different type of stepper controller. For use with the shield, you need to use both libraries. The AccelStepper library calls into the Adafruit library for low-level stepping control.

See the AccelStepper examples in the Adafruit library:
https://github.com/adafruit/Adafruit_Mo ... tSpeed.ino

User avatar
BPerry
 
Posts: 7
Joined: Mon Aug 10, 2020 5:53 pm

Re: Stepper Motor Homing

Post by BPerry »

Thank you. I will try that. I am early on in the coding of this sketch. I am attempting to build a model railroad transfer table for the locomotives in which the stepper will move the transfer bridge to one end of the rail, hit a limit switch to get a zero position and then move to whichever track position is needed. I will also have another safety limit switch at the far end of travel. I would like to include a “release” function so the motor is not constantly energized. Maintenance of position is not an issue since there won’t be any lateral stress to move the stepper rail. Thank you for your advice. If you have any suggestions they would be appreciated. I enjoy the support, advice and excellent products produced by Adafruit.

User avatar
adafruit_support_bill
 
Posts: 88090
Joined: Sat Feb 07, 2009 10:11 am

Re: Stepper Motor Homing

Post by adafruit_support_bill »

The AccelStepper library lends itself well to applications like that. The trick is to avoid any time-consuming operations in your loop() function so that the run or runSpeed function is called frequently. In between calls to the AccelStepper run function, you can add checks for limit switches etc.

AccelStepper does not directly support a release() function, but you can call the one from the underlying Adafruit motor shield library.

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Arduino products from Adafruit”