ok, i have a program that controls a pair of stepper motors.
this code works fine:
#include <Stepper.h>
// change this to the number of steps on your motor
#define STEPS 200
// create an instance of the stepper class, specifying
// the number of steps of the motor and the pins it's
// attached to
Stepper stepperA(STEPS, 10, 11, 12, 13);
Stepper stepperB(STEPS, 1, 2, 3, 4);
//for reverse
//Stepper stepperA(STEPS, 13, 12, 11, 10);
//Stepper stepperB(STEPS, 4, 3, 2, 1);
//25 revolutions = 5ml
//5 revolutions = 1ml
//1 revolution (200 steps) = 0.2ml
void setup()
{
// set the speed of the motor to () RPMs
stepperA.setSpeed(30);
stepperB.setSpeed(30);
}
void loop()
{
stepperA.step(200);
delay(1);
stepperB.step(200);
delay(1);
}
but when I run THIS code, the A stepper motor works, but the B stepper just vibrates, it doesn’t turn.
#include <Stepper.h>
// change this to the number of steps on your motor
#define STEPS 200
// create an instance of the stepper class, specifying
// the number of steps of the motor and the pins it's
// attached to
Stepper stepperA(STEPS, 10, 11, 12, 13);
Stepper stepperB(STEPS, 1, 2, 3, 4);
//for reverse remove comments and comment out above
//Stepper stepperA(STEPS, 13, 12, 11, 10);
//Stepper stepperB(STEPS, 4, 3, 2, 1);
//25 revolutions = 5ml
//5 revolutions = 1ml
//1 revolution (200 steps) = 0.2ml
long timewillbe, timeis, stepsperminuteA, stepsperminuteB;
int rolloverswas, rolloversis;
void setup()
{
//Serial.begin(9600);
// set the speed of the motor to () RPMs
stepperA.setSpeed(30);
stepperB.setSpeed(30);
timeis=0;
timewillbe=1000;
//////////////////////////////////////////
//get steps per minute from spreadsheet.
//20ml/day = 14 steps/minute
//max = 6000 total (sum of steppers)at 30rpm
////////////////////////////////////////////////////////////////
stepsperminuteA=400;
stepsperminuteB=400;
/////////////////////////////////////////////////////////////////
}
void loop()
{
timeis=millis();
rolloverswas=millisRollover();
//Serial.println(timewillbe);
if (timeis>timewillbe)
{
timewillbe=millis()+60000;
rolloversis=millisRollover();
if (rolloversis>rolloverswas)
{timewillbe=60000;
}
stepperA.step(stepsperminuteA);
//delay(1);
stepperB.step(stepsperminuteB);
//delay(1);
}
//delay(1);
}
int millisRollover() {
// get the current millis() value for how long the microcontroller has been running
//
// To avoid any possiblity of missing the rollover, we use a boolean toggle that gets flipped
// off any time during the first half of the total millis period and
// then on during the second half of the total millis period.
// This would work even if the function were only run once every 4.5 hours, though typically,
// the function should be called as frequently as possible to capture the actual moment of rollover.
// The rollover counter is good for over 35 years of runtime. --Rob Faludi http://rob.faludi.com
//
static int numRollovers=0; // variable that permanently holds the number of rollovers since startup
static boolean readyToRoll = false; // tracks whether we've made it halfway to rollover
unsigned long now = millis(); // the time right now
unsigned long halfwayMillis = 17179868; // this is halfway to the max millis value (17179868)
if (now > halfwayMillis) { // as long as the value is greater than halfway to the max
readyToRoll = true; // you are ready to roll over
}
if (readyToRoll == true && now < halfwayMillis) {
// if we've previously made it to halfway
// and the current millis() value is now _less_ than the halfway mark
// then we have rolled over
numRollovers = numRollovers++; // add one to the count the number of rollovers
readyToRoll = false; // we're no longer past halfway
}
return numRollovers;
}
anybody have any idea why this might be happening? It’s driving me nuts! Thanks!