用户
 找回密码
 立即注册

QQ登录

只需一步,快速开始

点击进入授权页面

只需一步,快速开始

  • QQ空间
  • 回复
  • 收藏

该用户从未签到

arduino +MPU6050+mc33886驱动 制作一个手势控制的智能小车
现在代码有了,但那个代码两个L298N驱动两个电机的代码,并且使用的是Arduino Mega2560的板子,现在我想改用arduino UNO的板子,并且电机驱动使用MC33886驱动小车,应该怎样改程序。
原电路图如下:
24bc80ec8a136327828010d9968fa0ec09fac74b.jpg
代码如下:
int pinI1=3;//定义I1接口
int pinI2=4;//定义I2接口
int pinI3=5;
int pinI4=6;
int pinI5=7;
int pinI6=8;
int pinI7=12;
int pinI8=13;
unsigned char Re_buf[11],counter=0;
unsigned char sign=0;
float a[3],w[3],angle[3],T;
void setup() {
pinMode(pinI1,OUTPUT);//定义该接口为输出接口
pinMode(pinI2,OUTPUT);
pinMode(pinI3,OUTPUT);
pinMode(pinI4,OUTPUT);
pinMode(pinI5,OUTPUT);
pinMode(pinI6,OUTPUT);
pinMode(pinI7,OUTPUT);
pinMode(pinI8,OUTPUT);
Serial.begin(115200);
}
void not_move()
{
analogWrite(pinI1,0);
analogWrite(pinI2,0);
analogWrite(pinI3,0);
analogWrite(pinI4,0);
analogWrite(pinI5,0);
analogWrite(pinI6,0);
analogWrite(pinI7,0);
analogWrite(pinI8,0);
delay(10);
}
voidforward()
{
analogWrite(pinI1,100);
analogWrite(pinI2,0);
analogWrite(pinI3,100);
analogWrite(pinI4,0);
analogWrite(pinI5,100);
analogWrite(pinI6,0);
analogWrite(pinI7,100);
analogWrite(pinI8,0);
delay(10);
}
void backward()
{
analogWrite(pinI1,0);
analogWrite(pinI2,100);
analogWrite(pinI3,0);
analogWrite(pinI4,100);
analogWrite(pinI5,0);
analogWrite(pinI6,100);
analogWrite(pinI7,0);
analogWrite(pinI8,100);
delay(10);
}

void turn_left_forward()
{
analogWrite(pinI1,100);
analogWrite(pinI2,0);
analogWrite(pinI3,100);
analogWrite(pinI4,0);
analogWrite(pinI5,0);
analogWrite(pinI6,0);
analogWrite(pinI7,0);
analogWrite(pinI8,0);
delay(10);
}
void turn_left_backward()
{
analogWrite(pinI1,0);
analogWrite(pinI2,100);
analogWrite(pinI3,0);
analogWrite(pinI4,100);
analogWrite(pinI5,0);
analogWrite(pinI6,0);
analogWrite(pinI7,0);
analogWrite(pinI8,0);
delay(10);
}

void turn_right_forward()
{
analogWrite(pinI1,0);
analogWrite(pinI2,0);
analogWrite(pinI3,0);
analogWrite(pinI4,0);
analogWrite(pinI5,100);
analogWrite(pinI6,0);
analogWrite(pinI7,100);
analogWrite(pinI8,0);
delay(10);
}

voidturn_right_backward()
{
analogWrite(pinI1,0);
analogWrite(pinI2,0);
analogWrite(pinI3,0);
analogWrite(pinI4,0);
analogWrite(pinI5,0);
analogWrite(pinI6,100);
analogWrite(pinI7,0);
analogWrite(pinI8,100);
delay(10);
}
void loop() {

if(sign)
{
sign=0;
if(Re_buf[0]==0x55) //检查帧头
{
switch(Re_buf [1])
{
case 0x51:
a[0] = (short(Re_buf [3]<<8| Re_buf[2]))/32768.0*16;
a[1] = (short(Re_buf [5]<<8| Re_buf[4]))/32768.0*16;
a[2] = (short(Re_buf [7]<<8| Re_buf[6]))/32768.0*16;
T = (short(Re_buf [9]<<8| Re_buf[8]))/340.0+36.25;
break;
case 0x52:
w[0] = (short(Re_buf [3]<<8| Re_buf[2]))/32768.0*2000;
w[1] = (short(Re_buf [5]<<8| Re_buf[4]))/32768.0*2000;
w[2] = (short(Re_buf [7]<<8| Re_buf[6]))/32768.0*2000;
T = (short(Re_buf [9]<<8| Re_buf[8]))/340.0+36.25;
break;
case 0x53:
angle[0] = (short(Re_buf[3]<<8| Re_buf [2]))/32768.0*180;
angle[1] = (short(Re_buf [5]<<8| Re_buf[4]))/32768.0*180;
angle[2] = (short(Re_buf [7]<<8| Re_buf[6]))/32768.0*180;
T = (short(Re_buf [9]<<8| Re_buf[8]))/340.0+36.25;


if(abs(angle[1])>=25)
{
if(angle[1]>=25)
{ if(angle[1]>=70) { not_move();}
else if(abs(angle[0])<=25){not_move();}
else if(angle[0]>25) {turn_right_forward();}
else {turn_right_backward();}
}
else
{ if(angle[1]<=-70) {not_move();}
elseif(abs(angle[0])<=25) {not_move();}
else if(angle[0]>25) {turn_left_forward();}
else {turn_left_backward();}
}
}
else if(abs(angle[0])>=25)
if(angle[0]>=25) {forward();}
else{backward();}
else {not_move();}

}
}
}
}

void serialEvent() {
while (Serial.available()) {

//char inChar = (char)Serial.read();Serial.print(inChar); //Output Original Data, use this code

Re_buf[counter]=(unsignedchar)Serial.read();
if(counter==0&&Re_buf[0]!=0x55)return; //第0号数据不是帧头
counter++;
if(counter==11) //接收到11个数据
{
counter=0; //重新赋值,准备下一帧数据的接收
sign=1;

}

}
}
小车可以运行,但现在改成arduino UNO的板子,再使用MC33886的板子,不知道如何修改程序的管脚代码,希望有懂得大神可以解答一下。
实物图如下:
f8725b8b4710b912b70a2614c4fdfc03904522f0.jpg

这是驱动图片,因该如何连接ARDUINO UNO 管脚,代码应该怎样修改

回帖奖励 +1 金币

按照2560的pin脚布局,挨个接到uno上即可。 这些是兼容的
int pinI1=3;//定义I1接口
int pinI2=4;//定义I2接口
int pinI3=5;
int pinI4=6;
int pinI5=7;
int pinI6=8;
int pinI7=12;
int pinI8=13;
您好,邬指导,您的意思是我不用再改后面的程序,只是把管脚重新接一下对吗?可是我想知道我的电机驱动应该怎么接,我是直接接到MC33886的四个驱动管脚上吗,另外程序还有需要删除的吗?
邬指导 发表于 2016-5-17 14:58
按照2560的pin脚布局,挨个接到uno上即可。 这些是兼容的
int pinI1=3;//定义I1接口
int pinI2=4;//定义I2 ...

您好,邬指导,您的意思是我不用再改后面的程序,只是把管脚重新接一下对吗?可是我想知道我的电机驱动应该怎么接,我是直接接到MC33886的四个驱动管脚上吗,另外程序还有需要删除的吗?
MC33886没玩过,帮不上你。l298n玩过
邬指导 发表于 2016-5-17 20:02
MC33886没玩过,帮不上你。l298n玩过

我打算换成L298N的,麻烦你了,谢谢!
洛水一梦24 发表于 2016-5-17 20:11
我打算换成L298N的,麻烦你了,谢谢!

自己对比一下2560和uno的pin,很多是兼容 的。

你照着同样的pin插入,比如pin7你就插pin7.这样代码基本不用动了
邬指导 发表于 2016-5-17 20:14
自己对比一下2560和uno的pin,很多是兼容 的。

你照着同样的pin插入,比如pin7你就插pin7.这样代码基本 ...

嗯嗯,我试着连接一下。
g15856730440 来自手机 新手上路 2018-6-14 17:58
9#
我也说一句如何改为远程遥控
发新帖
发表评论
高级模式  
您需要登录后才可以回帖 登录 | 立即注册  
关闭

推荐主题 上一条 /2 下一条