0

I have a stepper motor and try to program it like this but I kinda stuck since I'm new to Arduino. 1. The target is set to 2048, means motor have to move 2048 steps. 2. I program the motor to run 200 steps each time, every 200 steps will stop for a sec until it reach 2048.

I've been using AccelStepper library to program my motor, I found out it is very hard for me to program like this. I'm not asking to do my homework but I dunno where to start. Just wanted to ask what method can I use to program the motor to work like this. Thank you.

asked Nov 6, 2018 at 5:16
1
  • Have you tried modifying one of the examples provided with the library? Commented Nov 6, 2018 at 5:50

1 Answer 1

1

I would start with the Blocking example provided with the library. Add the delays you need, the steps/distance you want. The following is simple but crude. It is call blocking code. It can only do the following sequence, but sometimes that is good enough.

A bit better would be to have a conditional loop to get to the final target. The loop would move 200, then delay 1 second, subtract the amount moved. Loop until you use up all the required distance. But initially I suggest to keep it simple and just make it work with inline sequences.

#include <AccelStepper.h>
// Define a stepper and the pins it will use
AccelStepper stepper; // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5
void setup()
{ 
 stepper.setMaxSpeed(200.0);
 stepper.setAcceleration(100.0);
}
void loop()
{ 
 stepper.runToNewPosition(0);
 delay(1000);
 stepper.runToNewPosition(200);
 delay(1000);
 stepper.runToNewPosition(200);
 delay(1000);
 stepper.runToNewPosition(200);
}
answered Nov 6, 2018 at 5:55
1
  • Thanks! I will read first. Appreciate it! Commented Nov 6, 2018 at 8:02

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.