Show Posts
Pages: [1] 2 3 ... 5
1  Using Arduino / Motors, Mechanics, and Power / Re: Stepper w/ limit switches on: July 28, 2012, 08:13:37 am
wildbill,

Badabing! Thank you! it finally works!
2  Using Arduino / Motors, Mechanics, and Power / Re: Stepper w/ limit switches on: July 28, 2012, 12:39:02 am
Here is what I've got. I think it is almost there working backwards by tracing your code. Is it obvious to you what I'm missing? It is not to me.

Code:
#include <Stepper.h>
#define motorSteps 200     // change this depending on the number of
                           // steps per revolution of your motor
#define motorPin1 9
#define motorPin2 10
#define motorPin3 11
#define motorPin4 12

int myStepperState;  // variables will change:

Stepper myStepper(motorSteps, motorPin1,motorPin2,motorPin3,motorPin4);
                     // initialize of the Stepper library:
int State = 0; // Up variable for reading pushbutton1 status

const int iPin = 2;    // input pin for Hi-Low control
int iState = 0;  // variable to store the value coming from inputPin

const int sPin1 = 3;    // input pin for +sensor
int sState1 = 0;  // variable to store the value coming from the sensor

const int sPin2 = 4;    // input pin for -sensor
int sState2 = 0;  // variable to store the value coming from the sensor


void setup()
{
  myStepper.setSpeed(80);   // set the motor speed at 80 RPMS:
  pinMode(sPin1, INPUT);    // sets digital pin as input to read sensor 1
  pinMode(sPin2, INPUT);    // sets digital pin as input to read sensor 2
  pinMode(iPin, INPUT);     // sets iPin as input for HIGH/LOW function 
}


void loop()
{
  iState = digitalRead(iPin);
  sState1 = digitalRead(sPin1);
  sState2 = digitalRead(sPin2);
 
  if (iState == LOW)  // if input pin is receiving constant GND
    {   
      if (sPin1 == LOW)  // if sensor pin 1 receives GND       
       {     
         digitalWrite(motorPin1, LOW);   // shut down motor
         digitalWrite(motorPin3, LOW);   // shut down motor
       }
      else if (sPin1 == HIGH)  // sensor 1 is receiving 5+ and waiting to be tripped
       {
         myStepper.step(10);  // Step backward (x)steps towards sensor 1
       }
    }
  else if (iState == HIGH)  // if input pin is receiving constant 5+
    {
      if (sPin2 == LOW)  // if sensor pin 2 receives GND
       {
         digitalWrite(motorPin1, LOW);   // shut down motor
         digitalWrite(motorPin3, LOW);   // shut down motor
       }
      else if (sPin1 == HIGH)  // sensor 2 is receiving 5+ and waiting to be tripped
       {
         myStepper.step(-10);  // Step backward (x)steps towards sensor 2
       } 
    }
}
3  Using Arduino / Motors, Mechanics, and Power / Re: Stepper w/ limit switches on: July 27, 2012, 08:09:14 pm
Yep, it works! Thank you very much Rob.

I have been playing with my old code now trying to backwards engineer to figure out the what I might have done before, if possible.

I will post it when I've had a chance to play with it a bit.
4  Using Arduino / Motors, Mechanics, and Power / Re: Stepper w/ limit switches on: July 27, 2012, 07:11:08 pm
Now this seems like a neat idea as long as there is no noticeable delay.
Code:
myStepper.step(2);

100 times a second. That way the motor doesn't move far between chances to stop it.

Since 140 steps should equal the 1/2" travel needed either way, this might just do quite well. I have been cautioned about ramp up and down but, there is not any mass to speak of.

So, it should run a bit, stop and look for a limit, then go a bit more, then stop and look for a limit and when it gets a limit it stops all travel in that direction until the opposite travels limit is tripped?
5  Using Arduino / Motors, Mechanics, and Power / Re: Stepper w/ limit switches on: July 27, 2012, 09:18:19 am
OK. I think it took me at least 4 min.!

1- it seems like a big run-on sentence, so visually it is prohibitive. (although, at least I am understanding the lingo)
2- I believe the "stepCW or stepCCW" stops everything else until it is has completed its task. (which would negate the usefulness of a "limit switch"to stop it prematurely)

Hope there is something correct.
I have never used the "?" so, that is new to me. Perhaps that is part of what I lacked in  making my code work properly.

Learning from a book is sooo difficult for me that I had to reference back a lot of times to finally get it into my thinking that == means "equal to" and then seeing "!=" through me for a bit, but, in reference to "==" it took less time to become comfortable with it. However, being an infant here, I was not sure (even though it they are opposite ways of doing the same thing, that it wasn't something entirely else with the different wording you use in your entire code. Since I kind of know "digitalRead, digitalWrite, etc., I suppose I would have to see what their equivalent in your style of code would be to feel comfortable with it. And I do like how simple and neat yours appears BTW, as mine generally looks like a pack rats nest.
6  Using Arduino / Motors, Mechanics, and Power / Re: Stepper w/ limit switches on: July 27, 2012, 12:06:51 am
Oh! I thought you left them out to see if I was paying attention!
I find others style of coding is different from what I have been learning from the "Make" books on the Arduino. So, I thought there was some reason based on how you code to use the !=HIGH instead of the ==LOW I have read about. Yours is so much more concise, I figured it must be a better way. The tutorials seem to have a lot of bloat, but, perhaps that is just to get one used to thinking in coding terms. :p

I am trying to learn the language and expect it to be quite difficult in the process. Perhaps a formal college course would help to start. When I look at how you code, it defies the way I am learning in the books. It is all very confusing. Should I be looking into Javascript instead?
7  Using Arduino / Motors, Mechanics, and Power / Re: Stepper w/ limit switches on: July 26, 2012, 07:06:06 pm
OK, I found the lack of ";"'s you left me here
Code:
void stepCCW () {
myStepper.step(200);
}

void stepCW () {
myStepper.step(-200);
}

So, I am trying to check my punctuation. And it compiles fine.

You are exactly right. I have been trying to learn the C language and am just not getting very far with it. 

I did try changing the cw_ls != HIGH to LOW and was not getting anything, so I changed back.

Since I need to have  sensors HIGH for movement to occur in either direction, DO I not read correctly:

!= HIGH   // means "not equal to", so cc_ls !=(is not equal to HIGH, means it is LOW becausee the sensor has been tripped and the pin is getting GND.

No?
8  Using Arduino / Motors, Mechanics, and Power / Re: Stepper w/ limit switches on: July 26, 2012, 06:25:05 pm
Agreed, I was just trying the steps in different places trying to get something happening.

Is this perhaps what you are referring to?

Code:
if (dir == CCW) {
if (ccw_ls != HIGH) // assume switches go HIGH when activated
// but that means external pull down resistors
[u]stepCW(myStepper.step(100) );[/u]
} else {
if (cw_ls != LOW)
stepCCW(myStepper.step(-100) );
}
delay (SPEED);

I get the erro at the underlined portion: expected ')' before ';' token
9  Using Arduino / Motors, Mechanics, and Power / Re: Stepper w/ limit switches on: July 26, 2012, 05:40:43 pm
So, I tried adding the steps in different locations at different times and always got the errors.
10  Using Arduino / Motors, Mechanics, and Power / Re: Stepper w/ limit switches on: July 26, 2012, 05:37:29 pm
Quote
you added stuff to screw things up
I have NO doubt of that!
Here is what I have changed although, it was not done all at once.
And, agreed, yours did compile. Before my altering the steps.
Please, let me know what you think.

Code:

#include <Stepper.h>

#define motorSteps 200   
#define motorPin1 9
#define motorPin2 10
#define motorPin3 11
#define motorPin4 12

#define dirPin 2     // HI/LOW pushbutton pin
#define limit_sw_CW_Pin 3   // neg. direction sensor limit pin
#define limit_sw_CCW_Pin  4   // pos. direction sensor limit pin

#define CCW HIGH
#define SPEED 100 // number of mS between steps

int ccw_ls;
int cw_ls;
int dir;
int myStepperState;  // variables will change:
Stepper myStepper(motorSteps, motorPin1,motorPin2,motorPin3,motorPin4);

void setup() {
  // set the motor speed at 60 RPMS:
  myStepper.setSpeed(60);
 
  pinMode (limit_sw_CCW_Pin, INPUT);
  pinMode (limit_sw_CW_Pin, INPUT);
  pinMode (dirPin, INPUT);
}

void stepCCW (100) {
// code to step the motor a small amount in the CCW direction
}

void stepCW (100) {
// code to step the motor a small amount in the CW direction
}

void loop () {

ccw_ls = digitalRead(limit_sw_CCW_Pin);
cw_ls = digitalRead(limit_sw_CW_Pin);
dir = digitalRead(dirPin);

if (dir == CCW) {
if (ccw_ls != HIGH) // assume switches go HIGH when activated
// but that means external pull down resistors
stepCW(100);
} else {
if (cw_ls != LOW)
stepCCW(100);
}
delay (SPEED);

}

BTW, your confession is safe with me.  Means more rum for me!
11  Using Arduino / Motors, Mechanics, and Power / Re: Stepper w/ limit switches on: July 26, 2012, 01:29:34 pm
OK yes. I tried adding steps in the loop and got errors in the void stepCW. So, I tried adding the steps in the void CW and it brought error to the #define SPEED 10. So, I tried raising that one to 100. No go.

I ALSO tried putting void CCW to 100 and got an error at #define CCW  HIGH.

BTW, this hardware setup requires about 140 steps to = the 1/2" travel required. So, the 100 steps is just for test purposes.

And I must say, that is a true shame. Good Rum is one of my favorite drinks. But, that's OK. I'm sure I and the rest of Australia can find it in our hearts to forgive you.   smiley-wink

Toto
12  Using Arduino / Motors, Mechanics, and Power / Re: Stepper w/ limit switches on: July 26, 2012, 08:54:22 am
I need to go milk my goats now. I'll try to catch you online after work. Thanks Rob for your efforts. You must have the Bundy spirit!

Toto
13  Using Arduino / Motors, Mechanics, and Power / Re: Stepper w/ limit switches on: July 26, 2012, 08:26:52 am
Quote
Modify the code accordingly.
Yes, I figured I might have to play with the settings a bit to tailor it. The switches will be pulled up as they will ultimately have a constant 5vdc sent from them and be sent to GND upon button press signaling the input pin.

Quote
I don't understand this, do you mean the example I posted?
Yes, It seems so much cleaner than mine and straight forward.

It seems complete(though I don't understand how it is doing it). Is it a partial I should have added to my own?
14  Using Arduino / Motors, Mechanics, and Power / Re: Stepper w/ limit switches on: July 25, 2012, 07:52:40 pm
Rob,

The code does not actuate the motor in either direction. It does with some of my old code, so I am pretty sure it should work with this. Just to simplify, I am using 2 tact switches for my limit sensors. They are tied HIGH and the press sends them LOW. The input switch is tied LOW and sends a HIGH when pressed.
15  Using Arduino / Motors, Mechanics, and Power / Re: Stepper w/ limit switches on: July 25, 2012, 06:59:24 pm
Rob,

Thanks for your time and synapses. I am trying the code now. I notice that upon verification in the IDE I get no "ELSE" errors. I was getting them likecrazy and tried everything I could to releive them! I feel truly lost. I know it is my code grammar, but, how to find out?
Pages: [1] 2 3 ... 5