Motor Shield code question

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

Moderators: adafruit_support_bill, adafruit

Motor Shield code question

Postby XtremeIN » Thu Feb 14, 2013 2:54 am

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
XtremeIN
 
Posts: 4
Joined: Mon Feb 04, 2013 4:47 am

Re: Motor Shield code question

Postby adafruit_support_bill » Thu Feb 14, 2013 6:20 am

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.
User avatar
adafruit_support_bill
 
Posts: 16054
Joined: Sat Feb 07, 2009 9:11 am

Re: Motor Shield code question

Postby XtremeIN » Fri Feb 15, 2013 4:30 am

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
XtremeIN
 
Posts: 4
Joined: Mon Feb 04, 2013 4:47 am

Re: Motor Shield code question

Postby adafruit_support_bill » Fri Feb 15, 2013 6:15 am

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.
User avatar
adafruit_support_bill
 
Posts: 16054
Joined: Sat Feb 07, 2009 9:11 am


Return to Arduino Shields from Adafruit

Who is online

Users browsing this forum: No registered users and 5 guests

Stuff to buy from the Adafruit store and links to product documentation!


New Products [103]

Raspberry Pi[80]
 
FLORA[23]
 
Bunnie Studios[9]
 
FPGA[1]
 
mbed[11]
Arduino[60]
 
NETduino[14]
 
BeagleBone[24]
 
Android[6]
 
XBee[10]
More Dev Boards[30]


 
BoArduino[8]
 
SpokePOV[4]
 
TV-B-Gone[4]
 
MiniPOV[3]
 
SIM reader[3]
 
Microtouch[5]
 
Clocks & Watches[18]
 
Drawdio[4]
 
Brain Machine[1]
 
Game of Life[2]
 
MintyBoost[2]
More DIY Kits[16]


 
MaKey MaKey[3]
 
Tweet-a-Watt[5]
 
Young Engineers[33]
 
Discover Electronics[2]
 
Snap Circuits[4]
 
littleBits[3]
 
Project packs[8]


 
Breakout Boards[33]
LCDs & Displays[48]
Components & Parts[69]
Batteries & Power[49]
EL Wire/Tape/Panel[52]
LEDs[109]
 
Wireless[14]
Cables[61]
 
Lasers[6]
Sensors/Parts[145]
 
Enclosures/Cases[11]
 
Solar[11]
 
RFID / NFC[13]
Prototyping[70]
 
iDevices[13]
Tools[71]
 
Wearables[39]
 
CNC[37]
 
Robotics[29]
 
3D printing[1]
 
Materials[24]


 
Stickers[41]
 
Skill badges[55]
 
Books[25]
 
Circuit Playground[7]
 
Gift Certificates[4]