L298P双路2A直流电机驱动

简介

这是一款基于L298芯片的Arduino平台双路电机驱动扩展板,可以直接插入Arudino控制板使用。控制端口为4个,减少了对Arduino数字端口的开销,而且控制程序也更为简单。扩展板采用跳线选择Arduino VIN供电还是外接电源供电。

warning_yellow.png

注意 此款扩展板与扩展板V7.1存在引脚冲突,使用时需将扩展板冲突引脚剪断

注意 此款扩展板电机控制引脚为10,11,12,13,与常用4,5,6,7引脚的库函数存在区别 |

产品参数

应用

引脚说明

En Mn 状态
L X Mn禁止
H L Mn正转(Mn+为正)
H H Mn反转(Mn+为负)

注1:n=1,2。 注2:H表示高电平1;L表示低电平0;X表示任意电平。

使用教程

控制直流电机

目标:对直流电机进行调速和方向控制

步骤一:硬件清单

步骤二:软件清单

步骤三:连线图

步骤四:操作步骤

  1. 打开Arduino IDE
  2. 将下面的代码上传到UNO
  3. 库安装
 /**set control port**/
 const int E1Pin = 10;
 const int M1Pin = 12;
 const int E2Pin = 11;
 const int M2Pin = 13;

 /**inner definition**/
 typedef struct
 {
    byte enPin;
    byte directionPin;
 }MotorContrl;

 const int M1 = 0;
 const int M2 = 1;
 const int MotorNum = 2;

 const MotorContrl MotorPin[] ={ {E1Pin,M1Pin}, {E2Pin,M2Pin} } ;

 const int Forward = LOW;
 const int Backward = HIGH;

 /**program**/
 void setup()
 {
   initMotor();
 }
 void loop()
 {
   int value;
   /**test M1 **/
   setMotorDirection( M1, Forward );
   setMotorSpeed( M1, 100 );
   delay(1000);
   setMotorSpeed( M1, 0 );
   delay(100);

   setMotorDirection( M1, Backward );
   setMotorSpeed( M1, 50 );
   delay(1000);
   setMotorSpeed( M1, 0 );
   delay(100);

   /**test M2**/
   setMotorDirection( M2, Backward );
   for(value = 0 ; value <= 100; value+=5)
   {
     setMotorSpeed( M2, value );
     delay(100);
   }
   setMotorSpeed( M2, 0 );
   setMotorDirection( M2, Forward );
   for(value = 0 ; value <= 100; value+=5)
   {
     setMotorSpeed( M2, value );
     delay(100);
   }
   setMotorSpeed( M2, 0 );
 }

 /**functions**/
 void initMotor( )
 {
    int i;
    for ( i = 0; i < MotorNum; i++ )
    {
      digitalWrite(MotorPin[i].enPin, LOW);

      pinMode(MotorPin[i].enPin, OUTPUT);
      pinMode(MotorPin[i].directionPin, OUTPUT);
    }
 }

 /**  motorNumber: M1, M2
        direction:          Forward, Backward **/
 void setMotorDirection( int motorNumber, int direction )
 {
     digitalWrite( MotorPin[motorNumber].directionPin, direction);
 }

 /** speed:  0-100   * */
 inline void setMotorSpeed( int motorNumber, int speed )
 {
     analogWrite(MotorPin[motorNumber].enPin, 255.0 * (speed/100.0) );   //PWM
 }

步骤五:实验结果

疑难解答

更多问题及有趣的应用,请访问论坛

更多

<File:nextredirectltr.png>DFRobot商城购买链接

category: Product Manual category: DRI Series category: Motor Controllers category: Shields <!--Hidden Categories--!> [[category: Source]