Posted by SillyOldDuffer on 29/10/2018 09:57:17:
Posted by Alan Charleston on 29/10/2018 03:13:35:
…
…
All practical dividing code provides some way of allowing the user to decide when he wants to turn the table to the next working position. It's usually done by pressing a 'GO' button on the controller. The StepDuino diagram shows a number of breakout pins are available. Any of these 'spare' pins can be wired to a button and the Arduino programmed to detect when that button is pressed. I'll update the example later to show one way of doing it.
…
According to the stepduino documentation pin A1 is available on the bottom right hand side of the board.
The example makes pin A1 an input and also sets it HIGH by putting 5V on it via a built-in resistor.
divide() has been modified so that after each step it waits for Pin A1 to be momentarily connected to ground with a push-button (or spare bit of wire!).
<pre>
/* StepDuino example */
const int Stepper1Step = 5;
const int Stepper1Direction = 2;
const int GoButton = A1; // Analog Pin A1 can be used as a digital pin
const int StepsPerRev1 = 1600;
const int ratio = 120;
const int PAUSE_BETWEEN_DIVISIONS_mS = 3000; // 3 seconds
void divide( long n, long microStepsPerTurn ) {
// Divides with rounding correction – Duncan Webster's algorithm
long lastSteps = 0, nextSteps = 0;
long increment, halfn = n / 2;
for (long step = 1; step <= n; step++) {
nextSteps = ( step * microStepsPerTurn + halfn ) / n; //the +halfn makes it round to nearest
increment = nextSteps – lastSteps;
lastSteps = nextSteps;
stepMotor( increment );
waitForButton( GoButton );
}
}
void stepMotor( long microSteps ) {
while ( microSteps– ) {
stepper1Forward();
}
}
void waitForButton( int GoButton ) {
while ( digitalRead( GoButton ) == HIGH ) ; // Wait until the go button goes LOW
}
void setup() {
pinMode(Stepper1Step, OUTPUT);
pinMode(Stepper1Direction, OUTPUT);
pinMode( GoButton, INPUT_PULLUP ); // Make pin an INPUT with 5V on it so grounding with a switch can be detected
}
/* Main loop */
void loop() {
divide( 127, (long) StepsPerRev1 * ratio );
delay( 4000 );
}
/* Rotate stepper 1 forward by 1 step */
void stepper1Forward()
{
digitalWrite(Stepper1Direction, HIGH);
digitalWrite(Stepper1Step, HIGH);
delayMicroseconds(2); // 1uS minimum pulse duration for DRV8811
digitalWrite(Stepper1Step, LOW);
delayMicroseconds(100);
}
</pre>
Dave
Edited By SillyOldDuffer on 29/10/2018 17:23:49