I want to monitor the progress of the attached sketch that is controlling step motors with delay loops of 10 minutes and 1 hour.
How can I place monitoring points in the sketch using the Serial Monitor tool to monitor count down of timers and other events so I dont have to watch all the time to confirm things are working?
The programming is very difficult for me to understand and I have only crudely cobbled together a sketch by modifying sample sketches so I could use some help with the serial monitor.
thank you
/*
* cheapStepper_simple.ino
* ///////////////////////////////////////////
* using CheapStepper Arduino library v.0.2.0
* created by Tyler Henry, 7/2016
* ///////////////////////////////////////////
*
*
*
* //////////////////////////////////////////////////////
*/
// first, include the library :)
#define SECOND 1000UL
#define MINUTE (SECOND * 60UL)
#define Hour (MINUTE * 60UL)
#include <CheapStepper.h>
CheapStepper stepper;
// here we declare our stepper using default pins:
// arduino pin <--> pins on ULN2003 board:
// 8 <--> IN1
// 9 <--> IN2
// 10 <--> IN3
// 11 <--> IN4
// let's create a boolean variable to save the direction of our rotation
boolean moveClockwise = true;
//Here set the Jiggle delay for all loops, e.g., jiggle every 10 min.
long jiggle = (MINUTE * 10);
//Here set the delay for a 180 degree rotation. Typically 75 min after the prior 5 jiggles.
// Set for 75 minutes
long halfrotation = (MINUTE * 75);
//Here set the delay to start motor after powered up. To allow motor to stabilize. Same value set in all locations.
// 1000=1s. Using 2 seconds
int motorstabilize = (SECOND * 2);
void setup() {
stepper.setRpm(18); //18 RPM appears to be the fastest without motor stalling
}
void loop() {
// let's move a full rotation (4096 mini-steps)
// we'll go step-by-step using the step() function
for (int s=0; s<9800; s++) {
// this will loop 9800 times. With 7:2 circumferance pulley to diameter ratio,
// 9800 is ~180 degrees or 1/2 rotation
// 4096 steps = full rotation using default values
/* Note:
* you could alternatively use 4076 steps...
* if you think your 28BYJ-48 stepper's internal gear ratio is 63.68395:1 (measured) rather than 64:1 (advertised)
* for more info, see: http://forum.arduino.cc/index.php?topic=71964.15)
*/
// let's move one "step" (of the 4096 per full rotation)
stepper.step(moveClockwise);
/* the direction is based on moveClockwise boolean:
* true for clockwise, false for counter-clockwise
* -- you could also say stepper.stepCW(); or stepper.stepCCW();
*/
}
// now we've moved 1/2 rotation
// and switch directions before starting loop() again
// here is where we need to add jiggle
//
// Turn off Hold current to motors
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
// JIGGLE1, Delay set as variable and changes all Jiggles loop to the same delay
delay(jiggle);
// Turn on current to motors
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
// 2 sec delay for motors to stabalize
delay(motorstabilize);
// Here is the jiggle, 3 times and back to where it was
for (int x = 0; x < 3; x++)
{
for (int s = 0; s < 1024; s++)
{
stepper.stepCCW();
}
for (int s = 0; s < 1024; s++)
{
stepper.stepCW();
}
}
// Turn off hold current
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
// JIGGLE2 .
delay(jiggle);
// Turn on current to motors
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
// 2 sec delay for motors to stabilize
delay(motorstabilize);
// Here is the jiggle, 3 times and back to where it was
for (int x = 0; x < 3; x++)
{
for (int s = 0; s < 1024; s++)
{
stepper.stepCCW();
}
for (int s = 0; s < 1024; s++)
{
stepper.stepCW();
}
}
// Turn off hold current
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
// JIGGLE3
delay(jiggle);
// Turn on current to motors
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
// 2 sec delay for motors to stabilize
delay(motorstabilize);
// Here is the jiggle, 3 times and back to where it was
for (int x = 0; x < 3; x++)
{
for (int s = 0; s < 1024; s++)
{
stepper.stepCCW();
}
for (int s = 0; s < 1024; s++)
{
stepper.stepCW();
}
}
// Turn off hold current
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
// JIGGLE4
delay(jiggle);
// Turn on current to motors
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
// 3 sec delay for motors to stabilize
delay(motorstabilize);
// Here is the jiggle, 3 times and back to where it was
for (int x = 0; x < 3; x++)
{
for (int s = 0; s < 1024; s++)
{
stepper.stepCCW();
}
for (int s = 0; s < 1024; s++)
{
stepper.stepCW();
}
}
// Turn off hold current
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
// JIGGLE5
delay(jiggle);
// Turn on current to motors
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
// 3 sec delay for motors to stabilize
delay(motorstabilize);
// Here is the jiggle, 3 times and back to where it was
for (int x = 0; x < 3; x++)
{
for (int s = 0; s < 1024; s++)
{
stepper.stepCCW();
}
for (int s = 0; s < 1024; s++)
{
stepper.stepCW();
}
}
// Turn off hold current
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
//Here is a delay to turn 180 again and reset the sand for a total of 6 hour
//
delay (halfrotation);
// Turn on Motor
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
//3s delay for motors to stabilize before rotating
delay(motorstabilize);
moveClockwise = !moveClockwise;
}