Dump from SVN
This commit is contained in:
@ -0,0 +1,126 @@
|
||||
/*
|
||||
* cheapStepper_move.ino
|
||||
* ///////////////////////////////////////////
|
||||
* using CheapStepper Arduino library v.0.2.0
|
||||
* created by Tyler Henry, 7/2016
|
||||
* ///////////////////////////////////////////
|
||||
*
|
||||
* This sketch illustrates the library's
|
||||
* "blocking" move functions -
|
||||
* i.e. the move will "pause" the arduino sketch
|
||||
* -- for non-blocking moves, see cheapStepper_newMoveTo.ino example
|
||||
*
|
||||
* This sketch also shows how to set the RPM
|
||||
* and shows a few different types of move functions
|
||||
* - by steps or by degrees.
|
||||
*
|
||||
* Blocking moves are useful if you need a specific RPM
|
||||
* but don't need your arduino to perform other functions
|
||||
* while the stepper is moving.
|
||||
*
|
||||
* //////////////////////////////////////////////////////
|
||||
*/
|
||||
|
||||
// first, include the library :)
|
||||
|
||||
#include <CheapStepper.h>
|
||||
|
||||
// next, declare the stepper
|
||||
// and connect pins 8,9,10,11 to IN1,IN2,IN3,IN4 on ULN2003 board
|
||||
|
||||
CheapStepper stepper (8,9,10,11);
|
||||
|
||||
// let's create a boolean variable to save the direction of our rotation
|
||||
|
||||
boolean moveClockwise = true;
|
||||
|
||||
|
||||
void setup() {
|
||||
|
||||
// let's set a custom speed of 20rpm (the default is ~16.25rpm)
|
||||
|
||||
stepper.setRpm(20);
|
||||
/* Note: CheapStepper library assumes you are powering your 28BYJ-48 stepper
|
||||
* using an external 5V power supply (>100mA) for RPM calculations
|
||||
* -- don't try to power the stepper directly from the Arduino
|
||||
*
|
||||
* accepted RPM range: 6RPM (may overheat) - 24RPM (may skip)
|
||||
* ideal range: 10RPM (safe, high torque) - 22RPM (fast, low torque)
|
||||
*/
|
||||
|
||||
// now let's set up a serial connection and print some stepper info to the console
|
||||
|
||||
Serial.begin(9600); Serial.println();
|
||||
Serial.print(stepper.getRpm()); // get the RPM of the stepper
|
||||
Serial.print(" rpm = delay of ");
|
||||
Serial.print(stepper.getDelay()); // get delay between steps for set RPM
|
||||
Serial.print(" microseconds between steps");
|
||||
Serial.println();
|
||||
|
||||
// stepper.setTotalSteps(4076);
|
||||
/* you can uncomment the above line if you think your motor
|
||||
* is geared 63.68395:1 (measured) rather than 64:1 (advertised)
|
||||
* which would make the total steps 4076 (rather than default 4096)
|
||||
* for more info see: http://forum.arduino.cc/index.php?topic=71964.15
|
||||
*/
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
// let's do a clockwise move first
|
||||
|
||||
moveClockwise = true;
|
||||
|
||||
// let's move the stepper clockwise to position 2048
|
||||
// which is 180 degrees, a half-turn (if using default of 4096 total steps)
|
||||
|
||||
stepper.moveTo (moveClockwise, 2048);
|
||||
|
||||
// now let's print the stepper position to the console
|
||||
|
||||
Serial.print("step position: ");
|
||||
Serial.print(stepper.getStep()); // get the current step position
|
||||
Serial.print(" / 4096");
|
||||
Serial.println();
|
||||
|
||||
// now let's wait one second
|
||||
|
||||
delay(1000); // wait a sec
|
||||
|
||||
// and now let's move another 90 degrees (a quarter-turn) clockwise
|
||||
|
||||
stepper.moveDegrees (moveClockwise, 90);
|
||||
// stepper.moveDegreesCW (90); <--- another way to do a clockwise 90 degree turn
|
||||
|
||||
// let's print the stepper position to the console again
|
||||
|
||||
Serial.print("step position: ");
|
||||
Serial.print(stepper.getStep());
|
||||
Serial.print(" / 4096");
|
||||
Serial.println();
|
||||
|
||||
// and wait another second
|
||||
|
||||
delay(1000);
|
||||
|
||||
// ok, now let's reverse directions (to counter-clockwise)
|
||||
|
||||
moveClockwise = false;
|
||||
|
||||
// and move back to the start position (0 degree)
|
||||
|
||||
stepper.moveToDegree (moveClockwise, 0);
|
||||
// moveClockwise is now false, so move counter-clockwise back to start
|
||||
|
||||
// let's print the position to the console once again
|
||||
|
||||
Serial.print("step position: ");
|
||||
Serial.print(stepper.getStep());
|
||||
Serial.print(" / 4096");
|
||||
Serial.println();
|
||||
|
||||
// and wait another second before starting loop() over
|
||||
|
||||
delay(1000);
|
||||
}
|
||||
|
@ -0,0 +1,110 @@
|
||||
|
||||
/*
|
||||
* cheapStepper_newMoveTo.ino
|
||||
* ///////////////////////////////////////////
|
||||
* using CheapStepper Arduino library v.0.2.0
|
||||
* created by Tyler Henry, 7/2016
|
||||
* ///////////////////////////////////////////
|
||||
*
|
||||
* This sketch illustrates the library's
|
||||
* "non-blocking" move functions -
|
||||
* i.e. you can perform moves with the stepper over time
|
||||
* while still running other code in your loop()
|
||||
*
|
||||
* This can be useful if your Arduino is multi-tasking,
|
||||
* but be careful: if the other code in your loop()
|
||||
* slows down your Arduino, the stepper motor may
|
||||
* slow down or move with a stutter
|
||||
*
|
||||
* //////////////////////////////////////////////////////
|
||||
*/
|
||||
|
||||
// first, include the library :)
|
||||
|
||||
#include <CheapStepper.h>
|
||||
|
||||
// next, declare the stepper
|
||||
// and connect pins 8,9,10,11 to IN1,IN2,IN3,IN4 on ULN2003 board
|
||||
|
||||
CheapStepper stepper (8,9,10,11);
|
||||
|
||||
|
||||
// let's also create a boolean variable to save the direction of our rotation
|
||||
// and a timer variable to keep track of move times
|
||||
|
||||
bool moveClockwise = true;
|
||||
unsigned long moveStartTime = 0; // this will save the time (millis()) when we started each new move
|
||||
|
||||
|
||||
void setup() {
|
||||
|
||||
// let's run the stepper at 12rpm (if using 5V power) - the default is ~16 rpm
|
||||
|
||||
stepper.setRpm(12);
|
||||
|
||||
// let's print out the RPM to make sure the setting worked
|
||||
|
||||
Serial.begin(9600);
|
||||
Serial.print("stepper RPM: "); Serial.print(stepper.getRpm());
|
||||
Serial.println();
|
||||
|
||||
// and let's print the delay time (in microseconds) between each step
|
||||
// the delay is based on the RPM setting:
|
||||
// it's how long the stepper will wait before each step
|
||||
|
||||
Serial.print("stepper delay (micros): "); Serial.print(stepper.getDelay());
|
||||
Serial.println(); Serial.println();
|
||||
|
||||
// now let's set up our first move...
|
||||
// let's move a half rotation from the start point
|
||||
|
||||
stepper.newMoveTo(moveClockwise, 2048);
|
||||
/* this is the same as:
|
||||
* stepper.newMoveToDegree(clockwise, 180);
|
||||
* because there are 4096 (default) steps in a full rotation
|
||||
*/
|
||||
moveStartTime = millis(); // let's save the time at which we started this move
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
// we need to call run() during loop()
|
||||
// in order to keep the stepper moving
|
||||
// if we are using non-blocking moves
|
||||
|
||||
stepper.run();
|
||||
|
||||
////////////////////////////////
|
||||
// now the stepper is moving, //
|
||||
// let's do some other stuff! //
|
||||
////////////////////////////////
|
||||
|
||||
// let's check how many steps are left in the current move:
|
||||
|
||||
int stepsLeft = stepper.getStepsLeft();
|
||||
|
||||
// if the current move is done...
|
||||
|
||||
if (stepsLeft == 0){
|
||||
|
||||
// let's print the position of the stepper to serial
|
||||
|
||||
Serial.print("stepper position: "); Serial.print(stepper.getStep());
|
||||
Serial.println();
|
||||
|
||||
// and now let's print the time the move took
|
||||
|
||||
unsigned long timeTook = millis() - moveStartTime; // calculate time elapsed since move start
|
||||
Serial.print("move took (ms): "); Serial.print(timeTook);
|
||||
Serial.println(); Serial.println();
|
||||
|
||||
// let's start a new move in the reverse direction
|
||||
|
||||
moveClockwise = !moveClockwise; // reverse direction
|
||||
stepper.newMoveDegrees (moveClockwise, 180); // move 180 degrees from current position
|
||||
moveStartTime = millis(); // reset move start time
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,90 @@
|
||||
/*
|
||||
* cheapStepper_simple.ino
|
||||
* ///////////////////////////////////////////
|
||||
* using CheapStepper Arduino library v.0.2.0
|
||||
* created by Tyler Henry, 7/2016
|
||||
* ///////////////////////////////////////////
|
||||
*
|
||||
* this sketch illustrates basic step() functionality of the library:
|
||||
* the stepper performs a full rotation, pauses 1 second,
|
||||
* then does a full rotation in the other direction, and so on
|
||||
*
|
||||
* //////////////////////////////////////////////////////
|
||||
*/
|
||||
|
||||
// first, include the library :)
|
||||
|
||||
#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;
|
||||
|
||||
|
||||
void setup() {
|
||||
|
||||
// let's just set up a serial connection and test print to the console
|
||||
|
||||
Serial.begin(9600);
|
||||
Serial.println("Ready to start moving!");
|
||||
}
|
||||
|
||||
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<4096; s++){
|
||||
// this will loop 4096 times
|
||||
// 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 let's get the current step position of motor
|
||||
|
||||
int nStep = stepper.getStep();
|
||||
|
||||
// and if it's divisible by 64...
|
||||
|
||||
if (nStep%64==0){
|
||||
|
||||
// let's print the position to the console
|
||||
|
||||
Serial.print("current step position: "); Serial.print(nStep);
|
||||
Serial.println();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// now we've moved 4096 steps
|
||||
|
||||
// let's wait one second
|
||||
|
||||
delay(1000);
|
||||
|
||||
// and switch directions before starting loop() again
|
||||
|
||||
moveClockwise = !moveClockwise;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user