Pages: [1]   Go Down
Author Topic: Homing stepper with a swtich  (Read 662 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey!
I'm worink on a project where I'm gonna build a box that is sliding on a linear rail (very much like a CNC) using a stepper motor. I'm using an meny to determine the actions of the stepper motor, but i wont the stepper to "home" itself before it move to its first stop.

So my question is: Is it posible to make the stepper move until it triggers a switch before starting its actions?

Sorry if the question is bad formulated. It is to prevent the motor to start from a wrong point incase of the power shuts down in the middle of a previous action.

I'm using the library "accelstepper" to control the stepper. 
Logged

Offline Offline
Edison Member
*
Karma: 33
Posts: 1431
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sure, limit switches are used all the time for this. Look at "micro switches".

Simply move the motor a little bit (In case it is already at the limit) and then slowly move it back while checking the state of the switch.
Logged

New Jersey
Online Online
Faraday Member
**
Karma: 66
Posts: 3672
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Rig up a limit switch and at startup, move the stepper until it triggers it. Look at the reprap project - there are limit switches used there for the same thing.
Logged

Norfolk UK
Offline Offline
Faraday Member
**
Karma: 67
Posts: 2507
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You could use 2x micro switches to speed up reference point homing. Return home at full speed until first micro switch is closed then slow until second one closes.
Logged

There is no such thing as a stupid question but there are a lot of inquisitive idiots.

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Oh many answers!  smiley
But how am I going to prgoram it? Is there a tutorial on those RepRap machines?
« Last Edit: November 27, 2012, 12:27:06 pm by ekarlsson25 » Logged

Norfolk UK
Offline Offline
Faraday Member
**
Karma: 67
Posts: 2507
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Oh many answers!  smiley
But how am I going to prgoram it? Is there a tutorial on those RepRap machines?
In setup...
Is limit switch active?
    yes: step out x number of steps
    is limit switch active?
        yes: Error, switch broken. stop.
while limit switch not active
    step in 1 step
wend
your home.
Logged

There is no such thing as a stupid question but there are a lot of inquisitive idiots.

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I can't work it out..  smiley-confuse
I'm pretty new to programing.
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 610
Posts: 49016
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I can't work it out..  smiley-confuse
I'm pretty new to programing.
What have you tried? Try as I might, I can't find your code anywhere in this thread.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I haven't got the rail atm, but it seems like it should work anyways, like if the button is not active the motor moves backwards. But when the button gets pressed the code from the menu starts.

I've just tried to modify the AccelStepper's example "blocker" with a funktion that reads the buttonstate. But i don't really know how i should proceed, or if I'm doing it right from the start?
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 610
Posts: 49016
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
But i don't really know how i should proceed, or if I'm doing it right from the start?
Move over a little. Your blocking our view of your code.

A little more. More. Careful you don't fall off of the chair. A little more.

 Hey, I said be careful. Now, get up and post your code.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here is the code.  I've gotten it so far that it needs a press of the button to start activate the program. But i cant figure out how to make it move backwards until the button in pressed.

Code:
#include <AccelStepper.h>

// Define a stepper and the pins it will use
AccelStepper stepper(1, 49, 47);

int switchPin = 33;
int ledPin = 13;
boolean lastButton = LOW;
boolean currentButton = LOW;
boolean ledOn = false;

void setup()
{
  pinMode(switchPin, INPUT);
  pinMode(ledPin, OUTPUT);
  stepper.setMaxSpeed(200.0);
    stepper.setAcceleration(100.0);
}

boolean debounce(boolean last)
{
  boolean current = digitalRead(switchPin);
  if (last != current)
  {
    delay(5);
    current = digitalRead(switchPin);
  }
  return current;
}

void loop()
{
  currentButton = debounce(lastButton);
  if (lastButton == LOW && currentButton == HIGH)
  {
    ledOn = !ledOn;
    stepper.runToNewPosition(0);
    stepper.runToNewPosition(500);
    stepper.runToNewPosition(100);
    stepper.runToNewPosition(120);
  }
  lastButton = currentButton;
  }

 
« Last Edit: November 28, 2012, 06:36:13 am by ekarlsson25 » Logged

Pages: [1]   Go Up
Jump to: