【DFRobot电机驱动】+直流电机驱动arduino范例程序分析
<div class='showpostmsg'> 本帖最后由 北方 于 2019-9-27 15:49 编辑<p>1、官网提供了一个如下<a href="http://wiki.dfrobot.com.cn/index.php?title=(SKU:DRI0039)Quad_Motor_Driver_Shield_for_Arduino%E5%9B%9B%E8%B7%AF%E7%9B%B4%E6%B5%81%E7%94%B5%E6%9C%BA%E9%A9%B1%E5%8A%A8%E6%89%A9%E5%B1%95%E6%9D%BF" target="_blank">arduino范例</a></p>
<pre>
<code class="language-cpp">*!
* @file QuadMotorDriverShield.ino
* <a href="home.php?mod=space&uid=159083" target="_blank">@brief</a> QuadMotorDriverShield.inoMotor control program
*
* Every 2 seconds to control motor positive inversion
*
* @author linfeng(490289303@qq.com)
* <a href="home.php?mod=space&uid=252314" target="_blank">@version</a>V1.0
* <a href="home.php?mod=space&uid=311857" target="_blank">@date</a>2016-4-5
*/
const int E1 = 3; ///<Motor1 Speed
const int E2 = 11;///<Motor2 Speed
const int E3 = 5; ///<Motor3 Speed
const int E4 = 6; ///<Motor4 Speed
const int M1 = 4; ///<Motor1 Direction
const int M2 = 12;///<Motor2 Direction
const int M3 = 8; ///<Motor3 Direction
const int M4 = 7; ///<Motor4 Direction
void M1_advance(char Speed) ///<Motor1 Advance
{
digitalWrite(M1,LOW);
analogWrite(E1,Speed);
}
void M2_advance(char Speed) ///<Motor2 Advance
{
digitalWrite(M2,HIGH);
analogWrite(E2,Speed);
}
void M3_advance(char Speed) ///<Motor3 Advance
{
digitalWrite(M3,LOW);
analogWrite(E3,Speed);
}
void M4_advance(char Speed) ///<Motor4 Advance
{
digitalWrite(M4,HIGH);
analogWrite(E4,Speed);
}
void M1_back(char Speed) ///<Motor1 Back off
{
digitalWrite(M1,HIGH);
analogWrite(E1,Speed);
}
void M2_back(char Speed) ///<Motor2 Back off
{
digitalWrite(M2,LOW);
analogWrite(E2,Speed);
}
void M3_back(char Speed) ///<Motor3 Back off
{
digitalWrite(M3,HIGH);
analogWrite(E3,Speed);
}
void M4_back(char Speed) ///<Motor4 Back off
{
digitalWrite(M4,LOW);
analogWrite(E4,Speed);
}
void setup() {
for(int i=3;i<9;i++)
pinMode(i,OUTPUT);
for(int i=11;i<13;i++)
pinMode(i,OUTPUT);
}
void loop() {
M1_advance(100);
M2_advance(100);
M3_advance(100);
M4_advance(100);
delay(2000); ///<Delay 2S
M1_back(100);'g1、官网提供了一个如下arduino范例</code></pre>
<pre>
</pre>
<pre>
<code class="language-cpp">*!</code></pre>
<pre>
<code class="language-cpp">* @file QuuadMotorDriverShield.ino</code></pre>
<pre>
<code class="language-cpp">* @brief QuadaMotorDriverShield.inoMotor control pnrogram</code></pre>
<pre>
<code class="language-cpp">*</code></pre>
<pre>
<code class="language-cpp">* Every 2 seconds to control m
M2_back(100);
M3_back(100);
M4_back(100);
delay(2000); ///<Delay 2S
}</code></pre>
<p> </p>
<p>2、连接后测试结果</p>
<p>2.1 本次测试连接了M1,使用5V电源转接,如下图。其中,首先用发光二极管代替电机测试连接状态,测试成功后再换电机连接。</p>
<p></p>
<p></p>
<p> </p>
<p>2.2 更改源代码,只留下和M1相关的代码,如下,</p>
<p></p>
<p>2.3 连接后显示视频结果如下。</p>
<p>使用发光二极管的测试结果</p>
<p></p>
<p>使用5V直流电机的效果如下。</p>
<p></p>
<p>这样的结果说明硬件运行良好,同时可以看到,使用这个扩展板,不需要再程序中使用扩展库,直接使用GPIO的模拟数字输出就可以。直接适用用于各种创客开发。</p>
<p>其中扩展板和主板之间电源接口是共用5V和GND地的。对于扩展板其实是2路供电,一路是控制电源,一路是驱动电机的电源,两者之间是不同用的。</p>
<p><br />
<b><font color="#5E7384">此内容由EEWORLD论坛网友<font size="3">北方</font>原创,如需转载或用于商业用途需征得作者同意并注明出处</font></b><br />
</p>
</div><script> var loginstr = '<div class="locked">查看本帖全部内容,请<a href="javascript:;" style="color:#e60000" class="loginf">登录</a>或者<a href="https://bbs.eeworld.com.cn/member.php?mod=register_eeworld.php&action=wechat" style="color:#e60000" target="_blank">注册</a></div>';
if(parseInt(discuz_uid)==0){
(function($){
var postHeight = getTextHeight(400);
$(".showpostmsg").html($(".showpostmsg").html());
$(".showpostmsg").after(loginstr);
$(".showpostmsg").css({height:postHeight,overflow:"hidden"});
})(jQuery);
} </script><script type="text/javascript">(function(d,c){var a=d.createElement("script"),m=d.getElementsByTagName("script"),eewurl="//counter.eeworld.com.cn/pv/count/";a.src=eewurl+c;m.parentNode.insertBefore(a,m)})(document,523)</script> <p>只能用Arduino吗?用GPIO该如何做呢?</p>
hujj 发表于 2019-10-1 20:32
只能用Arduino吗?用GPIO该如何做呢?
<p>参照芯片手册,只是用数字0/1控制方向,模拟输出控制转速。任何MCU都可以的。</p>
页:
[1]