This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
projects:a4sim:servos:x27168 [2019/08/21 01:03] dwheele [X27 168 Automotive Gauge Mini Servo] |
projects:a4sim:servos:x27168 [2020/02/22 17:07] (current) admin ↷ Links adapted because of a move operation |
||
|---|---|---|---|
| Line 32: | Line 32: | ||
| Motor Thickness (w/o pins): 9mm / 0.35" | Motor Thickness (w/o pins): 9mm / 0.35" | ||
| - | {{ :projects:a4sim: | + | {{ a4sim: |
| + | |||
| + | ==== Working example ==== | ||
| + | |||
| + | <code c> | ||
| + | /* | ||
| + | | ||
| + | |||
| + | This program drives a unipolar or bipolar stepper motor. | ||
| + | The motor is attached to digital pins 8 - 11 of the Arduino. | ||
| + | |||
| + | The motor will step one step at a time, very slowly. | ||
| + | test that you've got the four wires of your stepper wired to the correct | ||
| + | pins. If wired correctly, all steps should be in the same direction. | ||
| + | |||
| + | Use this also to count the number of steps per revolution of your motor, | ||
| + | if you don't know it. Then plug that number into the oneRevolution | ||
| + | | ||
| + | |||
| + | | ||
| + | by Tom Igoe | ||
| + | |||
| + | */ | ||
| + | |||
| + | #include < | ||
| + | |||
| + | const int stepsPerRevolution = 600; // change this to fit the number of steps per revolution | ||
| + | // for your motor | ||
| + | |||
| + | // initialize the stepper library on pins 8 through 11: | ||
| + | Stepper myStepper(stepsPerRevolution, | ||
| + | |||
| + | int stepPosition = 0; // number of steps the motor has taken | ||
| + | int stepPoints[] = {100, 300, 200, 250, 50}; | ||
| + | int sPtr = 0; | ||
| + | |||
| + | void setup() { | ||
| + | // initialize the serial port: | ||
| + | // Serial.begin(19200); | ||
| + | // myStepper.step(-600); | ||
| + | |||
| + | // Deleted Serial writing, it might be interfering. | ||
| + | // setSpeed of 10 seems to work. Trying 30. | ||
| + | // 8/21/2019 | ||
| + | myStepper.setSpeed(60); | ||
| + | stepPosition = 0; | ||
| + | |||
| + | int i; | ||
| + | for (i = 0;i < 600;i += 10) { | ||
| + | myStepper.step(-10); | ||
| + | delay(40); | ||
| + | } | ||
| + | delay(500); | ||
| + | } | ||
| + | |||
| + | void loop() { | ||
| + | int newLoc = stepPoints[sPtr]; | ||
| + | sPtr++; | ||
| + | if (sPtr >= 5) { | ||
| + | sPtr = 0; | ||
| + | } | ||
| + | int stepAmount = newLoc - stepPosition; | ||
| + | myStepper.step(stepAmount); | ||
| + | stepPosition = newLoc; | ||
| + | delay(10); | ||
| + | } | ||
| + | </ | ||