stepper1 works, stepper 2 not: w/ motorShield&S4

Hello, world.

I'm building a robot using 4 UNO's w/ motor shields coordinated by a 2560, all talking over TWI. Its coming along nicely, but I've run into a snag on the UNO code and wondered if any of you out there...

If I compile a 'stepperTest.pde" using the Arduino IDE, it runs fine: both steppers step. (all the code does is alternate between motors, stepping forward and backward in the 4 different modes).

If I cut-and-paste the UNO code into Studio4, compile, load w/ avrdude, stepper 1 works but stepper2 does not. Stepper2 has no current, no latching...it turns by hand without the resistance a stepper should when engaged.

I've wandered the AFMotor.cpp code and found naught of the smoking gun.

Suggestions?

Yes, I can abandon using S4 for the UNO, but it would be nice to have the other tools at hand when things go awry.

Thanks!

--Xnloder

I continue to dig:

this bug is from the use of delay() fcn. Currently, to get the core to compile, I've added:

#ifndef delay
#define delay( msec ) _delay_ms( msec )
#endif

which compiles and runs. Sorta.

How should I get delay() to compile such that it does not interfere with PWM on pins 5 and 6 (ie, the controls for stepper 2)?

It wasn't the delay. It was the library file for AFMotor.cpp. The enabling of the H bridges in AFStepper::AFStepper is followed by initialization of PWM, which disables the bridges. By copying the bridge enable lines, it works:

// enable both H bridges
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
digitalWrite(5, HIGH); // copy this line
digitalWrite(6, HIGH); // and this line

// use PWM for microstepping support
// use PWM for microstepping support
initPWM3(1);
initPWM4(1);
setPWM3(255);
setPWM4(255);
digitalWrite(5, HIGH); // paste this line
digitalWrite(6, HIGH); // and this line

This is 'duh' code. Why did it work in the IDE? I will post this find to the folks who wrote the library file...