EasyManuals Logo

Freenove Ultimate Starter Kit User Manual

Freenove Ultimate Starter Kit
286 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #175 background imageLoading...
Page #175 background image
175
Chapter 16 Stepping Motor
www.freenove.com
support@freenove.com
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//continuous rotation function, the parameter steps specifies the rotation cycles, every
four steps is a cycle
void moveSteps(int dir, int ms, int steps){
int i;
for(i=0;i<steps;i++){
moveOnePeriod(dir,ms);
}
}
void motorStop(){ //function used to stop rotating
int i;
for(i=0;i<4;i++){
digitalWrite(motorPins[i],LOW);
}
}
int main(void){
int i;
if(wiringPiSetup() == -1){ //when initialize wiring failed,print message to screen
printf("setup wiringPi failed !");
return 1;
}
for(i=0;i<4;i++){
pinMode(motorPins[i],OUTPUT);
}
while(1){
moveSteps(1,3,512); //rotating 360° clockwise, a total of 2048 steps in a
circle, namely, 512 cycles.
delay(500);
moveSteps(0,3,512); //rotating 360° anticlockwise
delay(500);
}
return 0;
}
In the code, define four pins of stepping motor and coil power supply order of four steps rotation mode.
const int motorPins[]={1,4,5,6}; //define pins connected to four phase ABCD of stepper
motor
const int CCWStep[]={0x01,0x02,0x04,0x08}; //define power supply order for coil for
rotating anticlockwise
const int CWStep[]={0x08,0x04,0x02,0x01}; //define power supply order for coil for
rotating clockwise
Subfunction moveOnePeriod ((int dir,int ms) will drive the stepping motor rotating four step clockwise or
anticlockwise, four step as a cycle. Where parameter "dir" indicates the rotation direction, if "dir" is 1, the servo
will rotate forward, otherwise it rotates to reverse direction. Parameter "ms" indicates the time between each

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Freenove Ultimate Starter Kit and is the answer not in the manual?

Freenove Ultimate Starter Kit Specifications

General IconGeneral
BrandFreenove
ModelUltimate Starter Kit
CategorySingle board computers
LanguageEnglish