Show Posts
Pages: [1] 2 3
1  Using Arduino / Motors, Mechanics, and Power / Re: Anyone familiar with the "AccelStepper" library? on: May 02, 2013, 09:47:19 pm
Got it working the way I want now.

Someone suggested on the google support group to do the following after the button is released:

motor.setSpeed(0);
motor.moveTo(motor.currentPosition());

So now my code looks like:

Code:

#include <AccelStepper.h>

AccelStepper motor(1,7,8); // step pin = 7 dir pin = 8
int uppin = 3;    //pin number for the up button
int downpin = 4;  //pin number for the down button

void setup() {
 

        motor.setMaxSpeed(4000);
        motor.setAcceleration(1500);
        motor.setMinPulseWidth(100);
        motor.setCurrentPosition(0);
       
pinMode(uppin, INPUT);
pinMode(downpin, INPUT);

        Serial.begin(9600);
 
}

void loop() {

if (digitalRead(uppin) == HIGH) {         // check if the input is HIGH (button pushed)
            motor.moveTo(75000);             //Set target (absolute position)
moveup();      // run the moveup subroutine
  }

if (digitalRead(downpin) == HIGH) {       // check if the input is HIGH (button pushed)
            motor.moveTo(0);                  //Set target (absolute position)
movedown();      // run the movedown subroutine
 
 

Serial.println(motor.currentPosition());
}

void moveup() {
//routine to move the platform up
       
        while (digitalRead(uppin) == HIGH) {

if (motor.currentPosition() != 75000) {

motor.run();
}
               
          }
        motor.setSpeed(0);
        motor.moveTo(motor.currentPosition());
}


void movedown() {
//routine to move the platform down
             
while (digitalRead(downpin) == HIGH) {

if (motor.currentPosition() != 0) {

motor.run();
}
}
       motor.setSpeed(0);
       motor.moveTo(motor.currentPosition());
}

2  Using Arduino / Motors, Mechanics, and Power / Re: Anyone familiar with the "AccelStepper" library? on: May 02, 2013, 03:15:06 pm
I look at your code again and can't see why you are not calling motor.run() in loop - you must call this
very regularly - in loop() before each call to a subroutine might be a good place.  Remember run()
returns a boolean to tell you if you have arrived at the target.

You also call moveTo() repeatedly while a button is being held down - doesn't sound a
great idea - call it once when the button is first depressed (in other words detect button state
transitions).

Hi Mark,

You may have misinterpreted my code. I call the motor.run() repeatedly in my "while" loop... while the button is being pressed.

I only call the moveTo() once in my if statement, each time the button is pressed. From my understanding, this sets a new target that we want to step towards.


3  Using Arduino / Motors, Mechanics, and Power / Re: Anyone familiar with the "AccelStepper" library? on: May 02, 2013, 10:33:56 am
You have to wait for the motor to reach its target position before changing speed or acceleration settings, I believe,
otherwise you get the erroneous behaviour described.

I noticed that it doesn't have to actually reach the target position before changing directions. It just has to decellerate from whatever speed it was previously travelling back down to zero before changing directions.

It seems like a very flexible library, which is why I'm certain there is a way to do this. Some kind of reset for the speed...
4  Using Arduino / Motors, Mechanics, and Power / Anyone familiar with the "AccelStepper" library? on: May 02, 2013, 05:07:57 am
I'm trying to use the AccelStepper library to smoothly operate my stepper motor. I have a simple program right now that basically moves the stepper in one direction while one button is pushed, and then the other direction when the other button is pushed.

However, the code I've written so far does that (sort of). The problem I'm having is that once the motor accelerates in one direction (ex: clockwise) and I let go of the button (and the stepper is now stopped), it seems to "remember" that speed and acceleration in that direction. When I go to press the button to travel in the opposite direction (counter-clockwise) the stepper will resume it's previous speed clockwise direction and deccelerate until the speed is zero and THEN move in the counter clockwise direction.

I would like it such that every time the button is released, the speed is set back to zero. I cannot seem to find the function in the library to do this?

Here is my code:

Code:

#include <AccelStepper.h>

AccelStepper motor(1,7,8); // step pin = 7 dir pin = 8
int uppin = 3;    //pin number for the up button
int downpin = 4;  //pin number for the down button

void setup() {
 

        motor.setMaxSpeed(4000);
        motor.setAcceleration(1500);
        motor.setMinPulseWidth(100);
        motor.setCurrentPosition(0);
       
pinMode(uppin, INPUT);
pinMode(downpin, INPUT);

        Serial.begin(9600);
 
}

void loop() {

if (digitalRead(uppin) == HIGH) {         // check if the input is HIGH (button pushed)
            motor.moveTo(75000);             //Set target (absolute position)
moveup();      // run the moveup subroutine
  }

if (digitalRead(downpin) == HIGH) {       // check if the input is HIGH (button pushed)
            motor.moveTo(0);                  //Set target (absolute position)
movedown();      // run the movedown subroutine
 
 

Serial.println(motor.currentPosition());
}

void moveup() {
//routine to move the platform up
       
        while (digitalRead(uppin) == HIGH) {

if (motor.currentPosition() != 75000) {

motor.run();
}
               
          }
       
}


void movedown() {
//routine to move the platform down
             
while (digitalRead(downpin) == HIGH) {

if (motor.currentPosition() != 0) {

motor.run();
}
}
       
}


5  Using Arduino / Motors, Mechanics, and Power / Re: Anyone ever use one of these stepper drivers? Ebay 2M542 on: April 20, 2013, 09:22:23 pm
Thanks Mark,

Got it working. I was using to thin of gauge wires from the stepper driver to the motor.

I had them covered and I guess one melted to another and they were shorting  smiley-eek oops.

Switched to thicker wire and problem solved. Also took your advice and slowed things down a bit.
6  Using Arduino / Motors, Mechanics, and Power / Anyone ever use one of these stepper drivers? Ebay 2M542 on: April 20, 2013, 07:08:41 pm
As the title suggests,

I bought this stepper driver and I'm having a little trouble getting it to move my motor.

The data sheet can be found here:

http://www.hi-end.ro/pdf/motoare/CMP5042.pdf

I tried to run a test movement on it, just get it to spin a little doing this:

Code:
byte dir = 1;
digitalWrite(directionpin,dir);

while (location <=200) {


//step sequence to move up
digitalWrite(steppin, LOW);
                        delayMicroseconds(100);
digitalWrite(steppin, HIGH);
delayMicroseconds(100);
location++;

}

Am I doing something wrong?
7  Using Arduino / Programming Questions / Re: Problem with simple math code. sqrt() and sq() and the long variable type on: March 30, 2011, 01:30:28 pm
Works perfect.

I was not aware that the numbers you are working with must be declared as longs as well.

Thank you!
8  Using Arduino / Programming Questions / Problem with simple math code. sqrt() and sq() and the long variable type on: March 30, 2011, 12:26:55 pm
I need to do a little bit of math in some code I'm writing.

I simply need to use pythagorem theorem to solve for the magnitude of a side with two other known sides.

x = sqrt( sq(y) + sq(z) );

The largest values I anticipate seeing for my variables of y and z are around 150.

So I wrote some code to test out which variable types I need to use to properly hold my values.

Quote
void setup() {
         

Serial.begin(9600);
 
 
 
 }
 
 void loop(){
   
   long x = 0;
   
   x = sqrt(sq(150) + sq(150));
   
   Serial.println(x);
   
 }

In the serial monitor I was getting strange results, not the correct answer.

I then tried to elimnate the square root function to see if I would get the right answer before taking the square root:

Quote
void setup() {
         

Serial.begin(9600);
 
 
 
 }
 
 void loop(){
   
   long x = 0;
   
   x = sq(150) + sq(150);
   
   Serial.println(x);
   
 }

This was still giving me strange results. I guess it is some kind of data overflow? I thought a long variable type was supposed to hold up to the value of 2,147,483,647
I'm not even close to that. I should be getting an answer of 45000. If I only do one sq(15) and not the other, I get the correct answer of 22500. Why won't it add them together properly?

Thanks guys!
9  Using Arduino / Programming Questions / Re: Aref question using one arduino, and two arduinos on: March 23, 2011, 11:23:20 pm
Thanks for the response, that makes sense.

Only question left, is do I need to use the analogReference(external); before every line that I check the analog pins, or just once at the top of my code?
10  Using Arduino / Programming Questions / Aref question using one arduino, and two arduinos on: March 23, 2011, 09:54:44 am
Hello everyone,

I have two questions regarding the use of the Aref pin and analog sensors.

Lets say I have a 3.3V accelerometer that I have hooked up to the analog inputs. I also have it powered by the Arduino Uno board 3.3V out, and grounded to the Arduino Uno ground pins. Do I need to connect the 3.3V pin to the Aref pin? Or because my power source is the Arduino board, I don't need to use aref at all?

Now, lets assume I want to use two Arduinos and use the one accelerometer for both. Arduino 1 is hooked up in the same manner as the first scenario above. Arduino 2 needs to get the same readings that Arduino 1 is seeing. Do I need to connect Arduino 1's 3.3V pin to Arduino 2's Aref pin and then use the external reference? Is this correct? Should I connect the ground pins? Also, in my code, should I put analogReference(External) before EACH of the analogRead(xvalue), analogRead(yvalue) etc, or once at the top of my code suffice?

I guess it turned out to be more than two questions! Thanks for the help guys!
11  Using Arduino / General Electronics / Re: Hall Sensor SS451A Weird Behaviour? (Using "Interrupt") on: March 02, 2011, 10:51:25 pm
I try and give as much info as possible. I figured I was probably just using some kind of feature of the Arduino improperly.

Just out of curiosity, would you happen to know if its possible to run a subroutine in the background? What I mean is, can you run the main task, and an alternate subroutine simultaneously? I would imagine constantly polling the hall sensor in the background isn't very efficient, but I would just like to try it anyways (rather than use an interrupt).

Thanks again,

Chris
12  Using Arduino / General Electronics / Re: Hall Sensor SS451A Weird Behaviour? (Using "Interrupt") on: March 02, 2011, 10:24:34 pm
Works beautifully.

I heard that Arduino had a built in pull up resistor on the digital pins, but I wasn't sure how to use it. That explains it.

Thanks again, you're a real help around here!
13  Using Arduino / General Electronics / Hall Sensor SS451A Weird Behaviour? (Using "Interrupt") on: March 02, 2011, 10:04:25 pm
Hello everyone,

I have a problem with the Hall sensor I'm trying to use. It is a SS451A sensor:

http://ca.mouser.com/ProductDetail/Honeywell/SS451A/?qs=MPfWMdygYOY2ny0hGuKK6Q==

should be non latching, and data sheet can be found here:

http://mouser.com/catalog/specsheets/ProductSheet_SS351_451.pdf

I am running very simple code, just trying to see if the hall sensor will detect the presence of a magnet. The code is as follows:

Quote

volatile unsigned int count;

void setup()
{
  Serial.begin(57600);
  Serial.println ("Start");     // signal initalization done
  attachInterrupt(0, countP, RISING);
  delay(100);
}

void loop()
{
   
}

void countP()
 {
   count++;
   Serial.println (count);
 }


The problem I am having is that when I view the Serial Monitor, the counter is increasing rapidly with no magnet present. I only want the counter to increase when a rising edge is detected. Instead, when I place a magnet near the hall sensor, the counter stops. It seems as if it is doing the opposite of what I want? Any suggestions?
Thank you!
14  Using Arduino / General Electronics / Re: Looking for some help with positive edge trigger (flip flop) on: February 05, 2011, 01:03:03 pm
Hey thanks Lefty, that was going way above and beyond helpful!

I read up a bit more on the interrupt feature and your code was nice and easy to understand.

Big thanks!
15  Using Arduino / General Electronics / Re: Looking for some help with positive edge trigger (flip flop) on: February 04, 2011, 11:58:59 pm
Thanks guys, I think I will try the interrupt feature before anything else. I wasn't aware that this was possible.

Still kinda new with Arduino, programming, etc.

Very helpful!
Pages: [1] 2 3