Created
June 24, 2015 06:40
-
-
Save wdv4758h/7414de9adc500055e09b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <wiringPi.h> | |
| #include <stdio.h> | |
| #include <sys/time.h> | |
| #include <stdlib.h> | |
| /* | |
| execute with "sudo ./turn 800 1" where 800 is number of steps and 1 is rotation direction. | |
| This will turn a full revolution in 3.2 seconds, adjust delayMicrosenconds to speed up or slow down. Low torque motors may not be able to turn this fast. A 3 stack, NEMA 23 should be able to handle this speed if your load is not huge. | |
| */ | |
| int main (int argc, char *argv[]) { | |
| int stepPin = 12; //Step Motor Pulse | |
| int dirPin = 16; //Step Motor Direction | |
| int i, steps, dir; | |
| // Pins assigned by physical location on P1 header of the RPi. | |
| if (wiringPiSetupPhys() == -1) { | |
| exit (1); | |
| } | |
| // Initialize RPi GPIO Pins | |
| pinMode(stepPin, OUTPUT); | |
| pinMode(dirPin, OUTPUT); | |
| steps = atoi(argv[1]); | |
| dir = atoi(argv[2]); | |
| digitalWrite(dirPin, dir) //direction of rotation | |
| for(i=0; i<steps; i++) { //3200 steps = full revolution, 1600 = 180 degrees, 800 = 90 degrrees | |
| digitalWrite(stepPin, 1); | |
| delayMicroseconds(500); | |
| digitalWrite(stepPin, 0); | |
| delayMicroseconds(500); | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment