树莓派控制L9110S桥两路直流电机驱动板

实物图:
树莓派控制L9110S桥两路直流电机驱动板_第1张图片
硬件接入:vcc接5v到12v,gnd接负极,A-1A,A-1B,B-1A,B-2A,可以分别接到GPIO口
A-1A输入高电平,A-1B输入低电平,电机正转
反之则电机反转

代码:
#include
#include
#include
#define IN1 2
#define IN2 3
#define IN3 4
#define IN4 5

void ultraInit(void) {
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
}

void setStep(int a,int b,int c,int d){ //写入电平
digitalWrite(IN1, a);
digitalWrite(IN2, b);
digitalWrite(IN3, c);
digitalWrite(IN4, d);

}

void stop() { setStep(0, 0, 0, 0); }

int main(void) {
if (wiringPiSetup() == -1) {
printf(“setup wiringPi failed !”);
return 1;
}
ultraInit();
while (1) {
setStep(1,0,1,0);//前进
setStep(0,1,0,1,)//后退
setStep(1,0,0,0)//左转
setStep(1,0,0,0)//右转
delay(2000);
stop();
delay(2000); // 2s
}
return 0;
}

你可能感兴趣的:(树莓派控制L9110S桥两路直流电机驱动板)