最近新购了一块DFRduino RoMeo V1.1的卡(即DFRobot Arduino RoMeo 328集成2路电机驱动按键扩展板),想要通过PWM控制电机的正反转,但不清楚其管脚定义。
现在出现的问题就是用 I/O控制的是容易出现 给一个高电平(不是一直保持的)以后电机就一直转;点停止管脚以后电机还是一直转 点启动以后电机一直转,用线点任意管脚都可以启动电机。下面附上我们的程序希望能我们指导
- int ledPin = 13; // LED connected to digital pin 13
- int inPin = 9; // pushbutton connected to digital pin 7
- int val = 0; // variable to store the read value
- int outpin=4;
- int outpin1=5;
- int outpin2=6;
- int outpin3=7;
- int indd=2;
- int a=0;
- void setup()
- {
- pinMode(ledPin, OUTPUT); // sets the digital pin 13 as output
- pinMode(inPin, INPUT); // sets the digital pin 7 as input
- pinMode(outpin, OUTPUT);
- pinMode(outpin1, OUTPUT);
- pinMode(outpin2, OUTPUT);
- pinMode(outpin3, OUTPUT);
- pinMode(indd, OUTPUT);
- }
- void loop()
- {
- val = digitalRead(inPin); // read the input pin
- a = digitalRead(indd);
- digitalWrite(ledPin, val); // sets the LED to the button's value
- digitalWrite(outpin, HIGH);
- delay(100);
- digitalWrite(outpin1,LOW);
- delay(100);
- // digitalWrite(outpin2, HIGH); // control the motor move or not_wake
- if(1==val)
- {
-
- digitalWrite(outpin2, HIGH); //MaxVel:255
- delay(100);
- digitalWrite(outpin3, HIGH); // control the motor move direction_wake
- delay(100);
- }
- if(1==a)
- {
- val=0;
- digitalWrite(outpin2, LOW); //MaxVel:255
- digitalWrite(outpin3, LOW); // control the motor move direction_wake
-
- }
- }
复制代码
|
现在的问题是:只有一个输入端时,可很好的控制电机正反转(如您的代码),但通过两个端口时,就不行了。拉高不同输入端时,要么电机不能反转,要么电机运行不连续,通过监控,会看到0,1间断出现。
代码如下:[code]int E2 = 6; //M2 Speed Control
int M2 = 7; //M2 Direction Control
int X = 8; //YES 10,9,8,3,2
int Y = 2;
void stop(void) //Stop
{
digitalWrite(E2,LOW);
}
void advance(char b) //Move forward
{
analogWrite (E2,b);
digitalWrite(M2,HIGH);
}
void back_off (char b) //Move backward
{
analogWrite (E2,b);
digitalWrite(M2,LOW);
}
void setup(){
//start serial connection
Serial.begin(9600);
//configure pin2 as an input and enable the internal pull-up resistor
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(Y, INPUT);
pinMode(X, INPUT);
pinMode(13, OUTPUT);
}
void loop(){
//read the pushbutton value into a variable
int sensorVal = digitalRead(Y);
int val = digitalRead(X);
//print out the value of the pushbutton
Serial.println(val);
// Keep in mind the pullup means the pushbutton's
// logic is inverted. It goes HIGH when it's open,
// and LOW when it's pressed. Turn on pin 13 when the
// button's pressed, and off when it's not:
if(sensorVal == HIGH)
{
digitalWrite(13, HIGH);
advance(255); //move forward in max speed
}
else{
stop();
digitalWrite(13, LOW);
}
if(val == HIGH)
{
digitalWrite(13, HIGH);
back_off(255); //move forward in max speed
}
else{
stop();
digitalWrite(13, LOW);
}
}[/code]板卡接线如下:
int E2 = 6; //M2 Speed Control
int M1 = 4; //M1 Direction Control
int M2 = 7; //M1 Direction Control
int KEY_IN = 9;
void stop(void) //Stop
{
digitalWrite(E1,LOW);
digitalWrite(E2,LOW);
}
void advance(char a,char b) //Move forward
{
analogWrite (E1,a); //PWM Speed Control
digitalWrite(M1,HIGH);
analogWrite (E2,b);
digitalWrite(M2,HIGH);
}
void back_off (char a,char b) //Move backward
{
analogWrite (E1,a);
digitalWrite(M1,LOW);
analogWrite (E2,b);
digitalWrite(M2,LOW);
}
void turn_L (char a,char b) //Turn Left
{
analogWrite (E1,a);
digitalWrite(M1,LOW);
analogWrite (E2,b);
digitalWrite(M2,HIGH);
}
void turn_R (char a,char b) //Turn Right
{
analogWrite (E1,a);
digitalWrite(M1,HIGH);
analogWrite (E2,b);
digitalWrite(M2,LOW);
}
void setup(void)
{
int i;
for(i=4;i<=7;i++)
pinMode(i, OUTPUT);
pinMode(KEY_IN,INPUT);
pinMode(13, OUTPUT);
}
void loop(void)
{
int temp = 0;
temp = digitalRead(KEY_IN);
if(temp == HIGH)
{
advance (255,255); //move forward in max speed
digitalWrite(13,HIGH);
}
else
{
stop();
digitalWrite(13,LOW);
}
}[/code]
我买的是这个板
电机一直转的
现在是给一个电平就一直转个不停啊
急需知道了啊
数字管脚的定义0(RX),1(TX),2,3,4,5,6,7 ,8,9*,10*,11*,12,13,GND,AREF. 排线座是绿色的
我们现在按照您给的程序来驱动电机了
但是仍然是原来那个样子,定义的就9的管脚在给它一个+5V的电源以后就一直转动,即使把电源去掉以后就也是一直转,一直的都转着停止不了,
不知道这样的问题解决
希望能帮我们解决这个问题。
上面是WIKI的地址,确保你的版本是V1.1,板子上面是彩色排母。
电机控制"PWM模式"的几个管脚为
引脚 功能
4 电机1方向控制
5 电机1PWM控制
6 电机2PWM控制
7 电机2方向控制
你的定义为[code]int inPin = 9; // pushbutton connected to digital pin 7
int val = 0; // variable to store the read value
int outpin=4; //程序里面一直为高电机1方向控制正转
int outpin1=5; //电机1PWM控制 程序一直为低,第一个电机将一直不转动
int outpin2=6;
int outpin3=7;
int indd=2;
if(1==val) //如果输入9脚是高电平 电机2最大速度正转,
{
digitalWrite(outpin2, HIGH); //MaxVel:255
delay(100);
digitalWrite(outpin3, HIGH); // control the motor move direction_wake
delay(100);
}
else //增加判断语句 否则就停止转动
{
digitalWrite(outpin2, LOW); //停止转动
}
if(1==a) // indd输入管脚不知道你是用来做什么功能
{
val=0;
digitalWrite(outpin2, LOW); //MaxVel:255
digitalWrite(outpin3, LOW); // control the motor move direction_wake
}[/code]