Go Down

Topic: Beginner - Help please (Read 487 times) previous topic - next topic

Hey, would really appreciate any help

Basically, i have got an Aquino Uno board, 2 stepper motors and 2 stepper drivers.

I have got the Arduino environment ready for use, but would like some assistance in the programming. The motors will be representing the x and y axis, so i just need to programme so that the motors work in a sweeping action, so that x motor moves across the full legnth, then the y motor moves it a row, then the x motor moves across the full length again, And so on until the whole area has been covered (scanned).
Any help would be really appreciated.

Thanks
Jack

johnwasser

Code: [Select]

const unsigned long int X_STEPS_MAX = 745683;
const unsigned long int Y_STEPS_MAX = 87346;

unsigned long int X_position = 0;
unsigned long int Y_position = 0;

boolean X_increasing = true;

void loop() {
    if (X_increasing) {
        if (X_position == X_STEPS_MAX) {
             Y_position ++;
             Y_step_down();
             X_increasing = false;
         } else {
            X_position++;
            X_step_right();
         }
    } else { // decreasing
        if (X_position == 0) {
             Y_position ++;
             Y_step_down();
             X_increasing = true;
         } else {
            X_position--;
            X_step_left();
         }
     }

   while (Y_position == Y_STEPS_MAX);  // stop everything
}
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

MarkT

And implicit in that code is that the X_step_right() etc functions will delay appropriately to step at the desired rate!
[ I won't respond to messages, use the forum please ]

johnwasser


And implicit in that code is that the X_step_right() etc functions will delay appropriately to step at the desired rate!


Actually, implicit in that code is that no step rate was specified. :)
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Code: [Select]
[quote]
#include <[color=#CC6600]Stepper[/color].h>

[color=#7E7E7E]// initialize the stepper library on pins 8 through 11:[/color]
[color=#CC6600]Stepper[/color] myStepper(stepsPerRevolution, 8,9,10,11); 

[color=#CC6600]const[/color] [color=#CC6600]unsigned[/color] [color=#CC6600]long[/color] [color=#CC6600]int[/color] X_STEPS_MAX = 745683;
[color=#CC6600]const[/color] [color=#CC6600]unsigned[/color] [color=#CC6600]long[/color] [color=#CC6600]int[/color] Y_STEPS_MAX = 87346;

[color=#CC6600]unsigned[/color] [color=#CC6600]long[/color] [color=#CC6600]int[/color] X_position = 0;
[color=#CC6600]unsigned[/color] [color=#CC6600]long[/color] [color=#CC6600]int[/color] Y_position = 0;

[color=#CC6600]boolean[/color] X_increasing = [color=#CC6600]true[/color];

[color=#CC6600]void[/color] [color=#CC6600][b]loop[/b][/color]() {
    [color=#CC6600]if[/color] (X_increasing) {
        [color=#CC6600]if[/color] (X_position == X_STEPS_MAX) {
             Y_position ++;
             Y_step_down();
             X_increasing = [color=#CC6600]false[/color];
         } [color=#CC6600]else[/color] {
            X_position++;
            X_step_right();
         }
    } [color=#CC6600]else[/color] { [color=#7E7E7E]// decreasing[/color]
        [color=#CC6600]if[/color] (X_position == 0) {
             Y_position ++;
             Y_step_down();
             X_increasing = [color=#CC6600]true[/color];
         } [color=#CC6600]else[/color] {
            X_position--;
            X_step_left();
         }
     }

   [color=#CC6600]while[/color] (Y_position == Y_STEPS_MAX);  [color=#7E7E7E]// stop everything[/color]
}

[/quote]


Would this do it then?
Or do I need to add somthing else to get it working?

Also, would it help if i told you here are the components I have:

http://www.technobotsonline.com/arduino-uno-main-board-r3.html  x1
http://www.technobotsonline.com/stepper-motor-20x30mm-3.9v-600ma.html x2
http://www.technobotsonline.com/pololu-a4988-stepper-motor-driver-carrier--voltage-reg.html x2

Finally, probably a stupid question, but how do I link the arduino to the drivers and the drivers to the motors. I am assuming wires as the use of a protoboard was suggested?

Apologies about all of the questions, new to all this Arduino programming but it needs to be done for a team project.

Cheers
Jack


Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy