Using Raspberry Pi to control stepper motor--C language

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.