“(SKU:ARD030300)L298P Shield直流马达驱动”的版本间的差异

来自YwRobot Studio Wiki
跳转至: 导航搜索
样例代码
使用教程
 
(未显示同一用户的2个中间版本)
第26行: 第26行:
  
 
==使用教程==
 
==使用教程==
 +
<font color="#FF7F50">注意:Vin6.5V-12V供电时连接跳线帽,超过12V供电'''拔掉'''跳线帽,此时Arduino需要单独供电</font><br />
 
*[[File:L298P Shield直流马达驱动LINE.jpg|600px|]]
 
*[[File:L298P Shield直流马达驱动LINE.jpg|600px|]]
  
 
===样例代码===
 
===样例代码===
 
<pre style="color:blue">
 
<pre style="color:blue">
//This motor shield use Pin 6,5,7,4 to control the motor
+
//This motor shield use Pin 6,9,7,4 to control the motor
 
// Simply connect your motors to M1+,M1-,M2+,M2-
 
// Simply connect your motors to M1+,M1-,M2+,M2-
 
// Upload the code to Arduino/Roboduino
 
// Upload the code to Arduino/Roboduino
 
// Through serial monitor, type 'a','s', 'w','d','x' to control the motor
 
// Through serial monitor, type 'a','s', 'w','d','x' to control the motor
  
int EN1 = 8;   
+
int EN1 = 6;   
int EN2 = 4;  //Roboduino Motor shield uses Pin 9
+
int EN2 = 9;  //Roboduino Motor shield uses Pin 9
int IN1 = 5;
+
int IN1 = 7;
int IN2 = 6; //Latest version use pin 4 instead of pin 8
+
int IN2 = 4; //Latest version use pin 4 instead of pin 8
 
   
 
   
  

2019年8月7日 (三) 11:44的最新版本

L298P Shield直流马达驱动



产品参数

  • 尺寸:65*55mm
  • 重量:25g
  • 逻辑电压:5V
  • 端口:数字
  • 驱动方式:双路H桥
  • 驱动电压:7-12V (7-18V单独供电)
  • 驱动电流:<2A
  • 平台:Arduino

产品特性

  • 全新原装正品L298P芯片
  • 双出输出,电流最大2A
  • 高速肖特续流基二极管,性能稳定
  • 4IO控制两路马达转向、调速,节省IO
  • 管脚完全兼容Arduino UNO R3
  • 适用于智能机器人小车的电机驱动
  • 可配合我店的MR2智能小车平台使用

使用教程

注意:Vin6.5V-12V供电时连接跳线帽,超过12V供电拔掉跳线帽,此时Arduino需要单独供电

  • L298P Shield直流马达驱动LINE.jpg

样例代码

//This motor shield use Pin 6,9,7,4 to control the motor
// Simply connect your motors to M1+,M1-,M2+,M2-
// Upload the code to Arduino/Roboduino
// Through serial monitor, type 'a','s', 'w','d','x' to control the motor

int EN1 = 6;  
int EN2 = 9;  //Roboduino Motor shield uses Pin 9
int IN1 = 7;
int IN2 = 4; //Latest version use pin 4 instead of pin 8
 


void Motor1(int pwm, boolean reverse)
        {
          analogWrite(EN1,pwm); //set pwm control, 0 for stop, and 255 for maximum speed
         if(reverse)
         { 
          digitalWrite(IN1,HIGH);    
         }
        else
        {
          digitalWrite(IN1,LOW);    
         }
        }  
        
void Motor2(int pwm, boolean reverse)
        {
          analogWrite(EN2,pwm);
         if(reverse)
         { 
          digitalWrite(IN2,HIGH);    
         }
        else
        {
          digitalWrite(IN2,LOW);    
         }
        }  
       
void setup() 
{ 
    int i;
    
    for(i=4;i<=7;i++)  //For Arduino Motor Shield
    pinMode(i, OUTPUT);  //set pin 4,5,6,7 to output mode

    Serial.begin(9600);   
} 


void loop() 
{ 
  int x,delay_en;
  char val;
  while(1)
  {
    val = Serial.read();
    if(val!=-1)
       {
          switch(val)
           {
             case 'w'://Move ahead
                        Motor1(100,true);  //You can change the speed, such as Motor(50,true)
                        Motor2(100,true);
                      
                         break;
             case 'x'://move back
                        Motor1(100,false);
                        Motor2(100,false);
                         break;
             case 'a'://turn left
                        Motor1(100,false);
                        Motor2(100,true);
                         break;       
             case 'd'://turn right
                        Motor1(100,true);
                        Motor2(100,false);
                        break;   
               case 's'://stop
                        Motor1(0,false);
                        Motor2(0,false);
                         break;
                                  
           }     
        
       }
           
  }                           
}

引脚分配图

Pin Function
Digital 4 Motor 2 转向控制,高电平正转,低电平反转
Digital 5 Motor 2 PWM调速控制,范围0-255,0电机停转,255电机最大速度
Digital 6 Motor 1 PWM调速控制,范围0-255,0电机停转,255电机最大速度
Digital 7 Motor 1 转向控制,高电平正转,低电平反转


更多

[YWRobot产品资料下载]

购买 YWRobot商城购买链接