Simple question: how to block a Stepper in a fixed position using AccelStepper

Hi folks!
I have to ask you a question: it is really simple I think, but I can't work it out!
I am controlling two stepper motor at the time (I'm using the AccelStepper library).
I want that when a motor reaches its goal position, it stops and blocks its position (using its coils) until I want otherwise.

I can't manage to find a function in AccelStepper library that blocks a stepper in a fixed position: can you tell me how I could do that? :slight_smile:

I want this because since I'm building a two joint drawing arm, when the "shoulder" joint finishes to move I want it to block its position, in order to not be moved accidentally by the remaining "elbow" joint rotation.

Thank you so much for your time!

Richard

This is what a stepper normally does -- I'm not sure I understand the question. If you are not moving the stepper, and current is still flowing to it, then it is "locked", or blocked as you say. The greater the current, the greater its ability to resist being turned.

--
The Rugged Motor Driver: two H-bridges, more power than an L298, fully protected

The problem is that I use the library AccelStepper to control the motors, and the library doesn't have such method!
In fact, if I use the method "move(0)" wich means move yourself of 0 steps simply the motors doesn't do nothing at all, instead of lock his position :slight_smile:

You don’t need a method. You move the motors to a position, and once they reach that position the motor stays there, “blocked”.

If you look at the AccelStepper() class it takes control over the step/direction wires of your motor (or 2-wire outputs or 4-wire outputs) but it does not control the current. Whatever motor driver you are using, you must set the current level in these outputs. The AccelStepper() class just handles the LOGIC of stepping the motor from one place to another.

So whatever current you have set during motion, that will be the same current that is flowing during the stopped state.


The Gadget Shield: accelerometer, RGB LED, IR transmit/receive, speaker, microphone, light sensor, potentiometer, pushbuttons

Thanks you a lot for your reply! ^^

But what if I don't move at all one of the motor since the beginning of the program?
In fact, if I try to make one stepper "move(0)" since the beginning, that motor is not locked!
On the other side, if I move it a little bit (for example, "move(1)" in the setup() function) and then start to move it with "move(0)" in the loop() function, then it is blocked.

Do I need at least to make it move a little bit to have it blocked? :slight_smile:

P.S.
Excuse me for my bad english!

I think it would be helpful at this point to know what motor driver you are using and how you have your connections made between the Arduino and the motor driver.

--
The Quick Shield: breakout all 28 pins to quick-connect terminals

I have two 6 wired stepper motor linked to a ULN2803 driver.
They are powered by an external DC source of 12 V.
Do you need additional information?

Ah, OK you've got a unipolar driver connected directly to the stepper outputs. How do you have the Arduino outputs connected to the ULN2803? And how is the motor connected to the ULN2803?

You might have to call the enableOutputs() function when you find the motor is not blocked.

--
The Aussie Shield: breakout all 28 pins to quick-connect terminals

Stepper no. 1
Arduino Out Pins: 11 10 9 8 are linked to ULN 2803 Pins: 1 2 3 4
ULN 2803 Pins: 18 17 16 15 are linked to Stepper1 Pins: 1 5 2 6

Stepper no. 2
Arduino Out Pins: 7 6 5 4 are linked to ULN 2803 Pins: 5 6 7 8
ULN 2803 Pins: 14 13 12 11 are linked to Stepper2 Pins: 1 5 2 6

Then both steppers pins 3 and 4 are linked to 12 V, while the ULN 2803 pin 9 is connected to the ground.

You should probably connect ULN2803 pin 10 to 12V too, but other than that I don't see much of a problem. It might be some minor glitch in the AccelStepper library. Sorry I can't be more help.

--
The Gadget Shield: accelerometer, RGB LED, IR transmit/receive, speaker, microphone, light sensor, potentiometer, pushbuttons

From looking at the code of the AccelStepper library (isn't open source wonderful) its clear that none of the output pins are driven high until the motor is first moved - so it will be off until then. Suggest you simply call move(1) ; move(-1) ; at startup

Thank you a lot! It is the solution I've used so far, but I didn't notice it was the only solution i've got :slight_smile: