I wanted to be able to allow all the motors to hold while others were running. This hack succeeded in getting me 4 motors with full control. I'm not attempting to microstep, I'm just using this for single stepping, I think maybe the way the library deals with microstepping it may not work because the PWM leads are shared.
Using two of these motor control boards:
We are going to stack two motor shields on top of the Arduino. Using stacking headers on the first instead of the headers that come with it. Got the headers from Adafruit too. http://www.adafruit.com/index.php?main_page=product_info&cPath=17_21&products_id=85 . I used two sets of stacking headers because in order to drive my steppers I stacked another set of H bridge drivers on top and used a small 16pin dip heat sink from digikey.
So here comes the very subtle and elegant hack!
On top motor shield, cut pin 12 out of the header pins so it doesn't connect to the top board. Short pin 12 and 13 on the top motor shield, because pin 13 is the new motor latch for the top shield, and needs to connect to the shield where 12 used to. A nip and a solder blob and Bob's your uncle.
With the stack, one board will use the latch on pin 12, and the other on pin 13.
All the commands are sent to both, one board ignores (never latches) the commands for the other. Picked pin 13 for the new latch because it is in the same register as 12 and will be clocked the same way by the port writes. I don't think this technique is extensible to more boards, because there are no more pins. pin3 and the analog pins are in different ports and wouldn't be synchronous.
|Here you can see the Arduino with two motor shields on top, connected to stepper motors. The third is out of the picture. Motor power comes from an old computer ATX power supply 5V.|
Some links to facts on the motor shield board:
Digital pin 2, and 13 are not used.
Digital pin 11: DC Motor #1 / Stepper #1 (activation/speed control)
Digital pin 3: DC Motor #2 / Stepper #1 (activation/speed control)
Digital pin 5: DC Motor #3 / Stepper #2 (activation/speed control)
Digital pin 6: DC Motor #4 / Stepper #2 (activation/speed control)
Digital pin 4, 7, 8 and 12 (and now 13) are used to drive the DC/Stepper motors via the 74HC595 serial-to-parallel latch
OK, now at the end will be the modified library posted, but here is what I did.
Coding wise this may not be the most efficient method because of the redundant libaries, but it made the hack very easy to do w/o risk of messing up the code.
Copy the AFMotor directory in the arduino/libraries directory to AFMotorA. In the copy, change the names of AFMotor.h and AFMotor.cpp to AFMotorA.h and AFMotorA.cpp. Note that you will have to restart the Arduino software to see the new library.
Now find the line in the AFcontrol.h file in the libraries directory
#define MOTOR_LATCH 12
and change it to