Go Down

Topic: Home position for steppermotor while connecting power or at reset. (Read 680 times) previous topic - next topic

sregth

Hello,

                I'm a newbie on arduino. i want the steppermotor to do the following. Please help me..

 
1. power up arduino.
2. stepper motor at low speed to clockwise.
3. shaft hits limitswitch.
4. inputing limitswitch, steppermotor goes anticlockwise a few steps from limitswitch and gets its starting postion.
5. from this postion, it turns anticlockwise and clockwise and stops at the starting postion without hitting the limit switch.
6. continues to rotate anticlockwise and clockwise.
 
It should be on <stepper.h> because the whole project can be driven by 5 volt. (ie, without a4988 driver (12volt).
 I'm using arduino version 1.8.5.
<accelstepper.h> is showing
exit status 1
Error compiling for board Arduino/Genuino Uno.

PLEASE HELP ME ,

I have a code but incomplete ( wrong code) for the above project.


#include <Stepper.h>
const int HomePin=2;  // attach interrupt pin is 0 for arduino uno.
const int stepsPerRevolution = 2200;
const int stepsPerRevolution1 = 1000;   
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
Stepper myStepper1(stepsPerRevolution1, 8, 9, 10, 11);


void setup() {
  pinMode(LedPin,OUTPUT);
  pinMode(HomePin,INPUT_PULLUP);
  myStepper.setSpeed(15);
    myStepper1.setSpeed(10);
 myStepper1.step(-stepsPerRevolution1);
attachInterrupt(0,MainLoop,CHANGE);
}
void MainLoop(){
  digitalWrite(LedPin,HIGH);
delay(500);
digitalWrite(LedPin,LOW);
delay(500);

}
void loop() {
   myStepper.step(stepsPerRevolution);
  delay(50);
  myStepper.step(-stepsPerRevolution);
  delay(50);
}

 

PLEASE HELP ME..

pert

Please use code tags (</> button on the toolbar) when you post code or warning/error messages. The reason is that the forum software can interpret parts of your code as markup, leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier to read your code and to copy it to the IDE or editor. If your browser doesn't show the posting toolbar then you can just manually add the code tags:
[code]// your code is here[/code]
Using code tags and other important information is explained in the How to use this forum post. Please read it.

Please always do a Tools > Auto Format on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read. If you're using the Arduino Web Editor you will not have access to this useful tool but it's still unacceptable to post poorly formatted code. I recommend you to use the standard IDE instead.

<accelstepper.h> is showing
exit status 1
Error compiling for board Arduino/Genuino Uno.
It's saying much more than that.

When you encounter an error you'll see a button on the right side of the orange bar "Copy error messages". Click that button. Paste the error in a message here USING CODE TAGS (</> button on the toolbar).

sregth


groundFungus

The way to home a stepper is to step the motor one step toward the switch and then check the switch state.  Keep doing that, a step at a time, until the switch changes state.  Then reverse the motor and step it enough to move off the switch.  No interrupt is necessary (and really makes homing more complicated than it needs to be).

The stepper library is meant to drive only one stepper.  You may (will) have problems trying to drive two.  In the posted code both steppers are wired to the same pins so that won't work anyway.  In the posted code, you never read the home switch so how will that work?

Robin2 has written the Stepper Motor Basics and Simple Stepper Program pages to help get people started with steppers.  Really worth the time to read.
You will save everyone's time if you read and follow the forum guidelines.  :)          
https://forum.arduino.cc/index.php/topic,148850.0.html
and
https://forum.arduino.cc/index.php?topic=97455.0

Robin2

Do NOT have any delay()s in an Interrupt Service Routine. An ISR should be written so it completes as quickly as possible - 100 microseconds would be a very long time.

What stepper motor and stepper motor driver are you using?

...R
Stepper Motor Basics
Simple Stepper Code
Two or three hours spent thinking and reading documentation solves most programming problems.

TomGeorge

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom... :)
Everything runs on smoke, let the smoke out, it stops running....

Go Up