Hardware Reference
In-Depth Information
3.
Make sure there is a ground-wire connection between your
Raspberry Pi's ground and the stepper-motor power supply's
ground. Don't try operating without this critical link.
4.
With everything still off, and observing care for static
electricity, connect the GPIO pins to each of the ULN2003A
driver inputs 1B through 4B (IN1 through IN4).
Now turn everything on and keep alert, just in case. The Raspberry Pi should begin
booting with no visible activity on the stepper motor (or LEDs). If there is, you might have
a GPIO wiring error. Turn off the stepper-motor power supply if you can and bring the Pi
down and recheck.
Assuming all went well, point your motor at 12 o'clock and start the program:
$ ./unipolar
If the motor struggles or moves erratically when you give it movement commands,
you may need to correct the motor wiring. Use the + and - commands to check whether
the motor steps properly in one direction.
1 /
∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗
2
unipolar.c : Drive unipolar stepper motor
3
/
∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗
4
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <fcntl.h>
8 #include <unistd.h>
9 #include <errno.h>
10 #include <math.h>
11 #include <ctype.h>
12 #include <termio.h>
13 #include <sys/mman.h>
14 #include <signal.h>
15 #include <assert.h>
16
17 #include "gpio_io.c" /
GPIO routines
/
18 #include "timed_wait.c" /
timed_wait ()
/
19
20 static const int steps_per_360 = 100; /
Full steps per rotation
/
21
22 /
GPIO Pins : A B C D
/
23 static const int gpios[] = { 17, 24, 22, 23 };
24
25 static float step_time = 0.1; /
Seconds
/
26 static int drive_mode = 0; /
Drive mode 0, 1, or 2
/
27 static int step_no = 0; /
Step number
/
28 static int steps_per_r = 100; /
Steps per rotation
/
Search WWH ::




Custom Search