Motor Shield code question

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
XtremeIN
 
Posts: 4
Joined: Mon Feb 04, 2013 5:47 am

Motor Shield code question

Post by XtremeIN »

Hello,
I have what I think is a simple question. I have my motor shield assembled and turning my stepper motors nicely, but in the example code the following is used:

AF_Stepper motor(48, 2);

I know the 2 calles the second motoer or M3 and M4 on the board. What is the 48?

Thank you,
Micheal

User avatar
adafruit_support_bill
 
Posts: 88154
Joined: Sat Feb 07, 2009 10:11 am

Re: Motor Shield code question

Post by adafruit_support_bill »

The 48 tells the stepper library how many steps there are in a full rotation for your motor.

This number is used in speed calculations. When you specify a certain number of RPM, the library will calculate the number of steps per second it needs to generate to achieve that speed.

If you are using something other than a 48-step (1.25 degree/step) motor, you should change that number to match.

XtremeIN
 
Posts: 4
Joined: Mon Feb 04, 2013 5:47 am

Re: Motor Shield code question

Post by XtremeIN »

Thank you very much for you quick response. I now remember reading that somewhere.....duh!

I know have another question.
I understand that I can not turn on two different stepper motors at the same time. To simulate the look and feel of both I must interlace them stepping.

for (int i=0; i<200; i++)
{
motor1.step(1, FORWARD, SINGLE);
motor2.step(1, FORWARD, SINGLE);
}

What I am trying to do is home a X and Y axis table. At power up of the table it will not know where the table is. I would like to have both the X and Y stepper motors jog until a switch is made. I can make it work by doing it one at a time, but I would relly like for both to move toghter. Right now I have this, which does one at a time:

while (digitalRead (XhomeSwitch) == HIGH)
{
XaxisMotor.step (1, FORWARD, DOUBLE);
}

while (digitalRead (YhomeSwitch) == HIGH)
{
YaxisMotor.step (1, FORWARD, DOUBLE);
}

I m just not sure which stlye loop to use or how to nest them.
Thank you,
Micheal

User avatar
adafruit_support_bill
 
Posts: 88154
Joined: Sat Feb 07, 2009 10:11 am

Re: Motor Shield code question

Post by adafruit_support_bill »

Something like this should do it:

Code: Select all

while ((digitalRead (XhomeSwitch) == HIGH) || (digitalRead (YhomeSwitch) == HIGH))
{
   if(digitalRead (XhomeSwitch) == HIGH)
   {
      XaxisMotor.step (1, FORWARD, DOUBLE); 
   }

   if(digitalRead (YhomeSwitch) == HIGH)
   {
      YaxisMotor.step (1, FORWARD, DOUBLE);
   } 
}
You should also consider the AF_Motor/AccelStepper option. See the "MultiStepper" example in the AF_Motor library.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”