Offline
Newbie
Karma: 0
Posts: 9
|
 |
« on: November 27, 2012, 12:07:56 pm » |
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
Sr. Member
Karma: 7
Posts: 386
|
 |
« Reply #1 on: November 27, 2012, 12:15:02 pm » |
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
Offline
Edison Member
Karma: 24
Posts: 2345
|
 |
« Reply #2 on: November 27, 2012, 12:16:11 pm » |
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
Edison Member
Karma: 23
Posts: 1313
|
 |
« Reply #3 on: November 27, 2012, 12:19:36 pm » |
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
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 9
|
 |
« Reply #4 on: November 27, 2012, 12:25:19 pm » |
Oh many answers!  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
Edison Member
Karma: 23
Posts: 1313
|
 |
« Reply #5 on: November 27, 2012, 12:50:48 pm » |
Oh many answers!  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
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 9
|
 |
« Reply #6 on: November 27, 2012, 01:11:52 pm » |
I can't work it out..  I'm pretty new to programing.
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 311
Posts: 35470
Seattle, WA USA
|
 |
« Reply #7 on: November 27, 2012, 01:30:09 pm » |
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
Newbie
Karma: 0
Posts: 9
|
 |
« Reply #8 on: November 27, 2012, 01:45:11 pm » |
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
Offline
Brattain Member
Karma: 311
Posts: 35470
Seattle, WA USA
|
 |
« Reply #9 on: November 27, 2012, 03:51:52 pm » |
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
Newbie
Karma: 0
Posts: 9
|
 |
« Reply #10 on: November 28, 2012, 05:47:55 am » |
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. #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
|
|
|
|
|
|