How to connect the circuit see another blog post:"using Raspberry Pi to control stepper motor--pythony language"
/******************************************************* File name:stepmotor.c* Author:jason Dai* date:20 15/01/26******************************************************/#include <wiringPi.h> #include <stdio.h > #define IN1 0//WIRINGPI GPIO0 (pin11) #define IN2 1#define IN3 2#define IN4 3void setstep (int A, int b, int c, int d) {Digitalwrite (IN1, a);d igitalwrite (IN2, b);d Igitalwrite (IN3, c);d Igitalwrite (IN4, d);} void Stop () {setstep (0, 0, 0, 0);} void forward (int t, int steps) {int i;for (i = 0; i < steps; i++) {setstep (1, 0, 0, 0);d Elay (t); SetStep (0, 1, 0, 0);d Elay ( t); setstep (0, 0, 1, 0);d Elay (t); SetStep (0, 0, 0, 1);d Elay (t);}} void backward (int t, int steps) {int i;for (i = 0; i < steps; i++) {setstep (0, 0, 0, 1);d Elay (t); SetStep (0, 0, 1, 0);d Elay (t); SetStep (0, 1, 0, 0);d Elay (t); SetStep (1, 0, 0, 0);d Elay (t);}} int main (void) {if ( -1 = = Wiringpisetup ()) {printf ("Setup wiringpi failed!"); return 1;} /* Set mode to Output */pinmode (IN1, Output);p inmode (IN2, Output);pInmode (IN3, Output);p inmode (IN4, Output), while (1) {printf ("forward...\n"), Forward (3, N);p rintf ("stop...\n"); stop ();d Elay (2000); 2sprintf ("backward...\n"); Backward (3, 512); Steps----angleprintf ("stop...\n"), Stop ();d Elay (2000); 2s}return 0;}
Compile:
GCC Stepmotor.c-o STEPMOTOR-LWIRINGPI
Run:
./stepmotor
Using Raspberry Pi to control stepper motor--C language