“MotorDriver IIC”的版本间的差异

来自YFRobotwiki
跳转至: 导航搜索
Arduino 扩展库
 
(未显示2个用户的35个中间版本)
第1行: 第1行:
  
[[File:MotorDriver_IIC_Module.png |350px|thumb|right|motor driver]]
+
[[File:Arduino与IIC电机驱动-3.jpg |350px|thumb|right|motor driver]]
  
== 简介 ==
+
===  产品 简介 ===
  
 
IIC-四路电机驱动模块是采用堆叠式设计,可直接插于Arduino UNO主控板或其兼容板上的电机驱动模块。它集成了PCA9685芯片(一个I2C总线控制的16通道PWM控制器)、2片TB6612电机驱动芯片,只占用Arduino IIC端口(A4-SDA/A5-SCL)即可控制4路电机,IIC地址0x40。
 
IIC-四路电机驱动模块是采用堆叠式设计,可直接插于Arduino UNO主控板或其兼容板上的电机驱动模块。它集成了PCA9685芯片(一个I2C总线控制的16通道PWM控制器)、2片TB6612电机驱动芯片,只占用Arduino IIC端口(A4-SDA/A5-SCL)即可控制4路电机,IIC地址0x40。
第8行: 第8行:
 
IIC-四路电机驱动模块可直接连接M1、M2、M3、M4,4路电机,接口顺序:电机正极、电机负极、编码器负极、编码器正极、A相、B相;兼容本店多款电机:25、37、N20;且扩展5路IIC接口、1路VGTR串行通信接口、 6路3PGVS标准传感器接口、1路串行通信接口,扩展性强。
 
IIC-四路电机驱动模块可直接连接M1、M2、M3、M4,4路电机,接口顺序:电机正极、电机负极、编码器负极、编码器正极、A相、B相;兼容本店多款电机:25、37、N20;且扩展5路IIC接口、1路VGTR串行通信接口、 6路3PGVS标准传感器接口、1路串行通信接口,扩展性强。
  
== 参数 ==
+
 
 +
===  规格 参数 ===
  
 
* 逻辑供电电压:5V DC
 
* 逻辑供电电压:5V DC
第20行: 第21行:
 
* 电源指示灯x1
 
* 电源指示灯x1
  
== 功能 ==
+
 
 +
=== 功能 说明 ===
  
 
[[File:MotorDriver IIC.png|800px]]
 
[[File:MotorDriver IIC.png|800px]]
  
== Arduino 扩展库 ==
+
IIC电机驱动模块与Arduino UNO排母对齐插入,无需外接导线。
Arduino library : https://github.com/YFROBOT-TM/Yfrobot-Motor-Driver-Library
+
  
=== Arduino 扩展库使用方法 ===
+
  供电部分由上部IIC电机驱动板输入,底部主板无需再输入电源。
调用库:
+
  
<nowiki>#include <MotorDriver_PCA9685.h>  // 包含头文件</nowiki>
+
编码器端口电源部分由底部主板的5V端口输入,信号读取也同样是arduino端口读取,不是arduino适配的型号不建议使用此模块做驱动。
 +
 
 +
 
 +
=== Arduino 扩展库 ===
 +
 
 +
Arduino library : https://github.com/YFROBOT-TM/Yfrobot-Motor-Driver-Library  '''库文件下载最新版本,Arduino IDE软件版本要求1.8以上。'''
 +
 
 +
 
 +
==== Arduino 扩展库使用方法 ====
 +
调用库:
 +
<source lang="c">
 +
#include <MotorDriver.h>  // 包含头文件
 +
</source>
  
 
 创建对象:
 
 创建对象:
  
MotorDriver_PCA9685 motorDirver = MotorDriver_PCA9685();
+
<source lang="c">#define MOTORTYPE YF_IIC_TB ;</source>
  
 
'''方法 Methods:'''
 
'''方法 Methods:'''
第40行: 第52行:
 
 初始化
 
 初始化
  
motorDirver.begin();
+
<source lang="c">motorDriver.begin();;</source>
  
 设置 单个 电机反向,参数 :0-默认 ,1-反向
+
 设置电机反向,参数 :1-默认 ,-1-反向
  
motorDirver.setMotorDirReverse(0, 1, 0, 1);// M1/M3 默认方向 M2/M4反向
+
<source lang="c">const int offsetm1 = 1;
 
+
const int offsetm2 = -1;
设置所有电机反向, 0-默认,1-反向
+
const int offsetm3 = 1;
 
+
const int offsetm4 = -1;// M1/M3 默认方向 M2/M4反向</source>
motorDirver.setMotorDirReverse(0); // 所有电机默认方向
+
  
 
 驱动单个电机,参数:电机序号 M1,M2,M3,M4;电机速度 -4096~4096
 
 驱动单个电机,参数:电机序号 M1,M2,M3,M4;电机速度 -4096~4096
  
motorDirver.setSingleMotor(M1, 4096);  // M1电机全速正转
+
<source lang="c">motorDriver.setSingleMotor(M1, 4096);  // M1电机全速正转</source>
  
motorDirver.setSingleMotor(M1, 0);  // M1电机停止
+
<source lang="c">motorDriver.setSingleMotor(M1, 0);  // M1电机停止</source>
  
 
 驱动4路电机,参数:电机速度 -4096~4096
 
 驱动4路电机,参数:电机速度 -4096~4096
  
motorDirver.setMotor(0, 4096, 2048,1024);  // 电机M1停止,电机M2 全速正转,电机M3 50%正转,电机M4 25%正转
+
<source lang="c">motorDriver.setMotor(0, 4096, 2048, 1024);  // 电机M1停止,电机M2 全速正转,电机M3 50%正转,电机M4 25%正转</source>
  
motorDirver.setMotor(0, 0, 0, 0);  // 电机M1/M2/M3/M4停止
+
<source lang="c">motorDriver.setMotor(0, 0, 0, 0);  // 电机M1/M2/M3/M4停止</source>
 +
 
 +
<source lang="c">motorDriver.setAllMotor(4096); // 电机M1/M2/M3/M4 全速正转</source>
 +
 
 +
<source lang="c">motorDriver.setAllMotor(0);  // 电机M1/M2/M3/M4停止</source>
  
 
 电机刹车/急停
 
 电机刹车/急停
  
motorDirver.stopMotor(M1);  // 电机M1 刹车
+
<source lang="c">motorDriver.stopMotor(M1);  // 电机M1 刹车</source>
 +
 
 +
<source lang="c">motorDriver.stopMotor(MAll);  // 电机M1/M2/M3/M4 刹车</source>
 +
 
 +
===示例代码===
 +
 
 +
<source lang="c">
 +
/***************************************************
 +
  Motor Test - IIC Motor Drive
 +
 
 +
  motor driver library: https://github.com/YFROBOT-TM/Yfrobot-Motor-Driver-Library
 +
  motor driver iic Introduction: http://www.yfrobot.com.cn/wiki/index.php?title=MotorDriver_IIC
 +
  motor driver iic:https://item.taobao.com/item.htm?id=626324653253
 +
 
 +
  YFROBOT ZL
 +
  08/13/2020
 +
****************************************************/
 +
#include <MotorDriver.h>
 +
 
 +
#define MOTORTYPE YF_IIC_TB  //
 +
uint8_t SerialDebug = 1; // 串口打印调试 0-否 1-是
 +
 
 +
// these constants are used to allow you to make your motor configuration
 +
// line up with function names like forward.  Value can be 1 or -1
 +
const int offsetm1 = 1;
 +
const int offsetm2 = -1;
 +
const int offsetm3 = 1;
 +
const int offsetm4 = -1;
 +
 
 +
// Initializing motors.
 +
MotorDriver motorDriver = MotorDriver(MOTORTYPE);
 +
 
 +
void setup() {
 +
  Serial.begin(9600);
 +
  Serial.println("Motor Drive test!");
 +
  motorDriver.begin();
 +
  motorDriver.motorConfig(offsetm1, offsetm2, offsetm3, offsetm4);
 +
  delay(1000);  // wait 2s
 +
  Serial.println("Start...");
 +
}
 +
 
 +
void loop() {
 +
  motorDriver.setSingleMotor(M1, 4096);  // 电机M1全速正转
 +
  delay(500);
 +
  motorDriver.setSingleMotor(M1, 0);  // 电机M1停止
 +
  delay(500);
 +
  motorDriver.setSingleMotor(M2, -2048);  // 电机M2 50%速度反转
 +
  delay(500);
 +
  motorDriver.setSingleMotor(M2, 0);  // 电机M2停止
 +
  delay(500);
 +
  motorDriver.setSingleMotor(M3, 4096);  // 电机M3全速正转
 +
  delay(500);
 +
  motorDriver.setSingleMotor(M3, 0);  // 电机M3停止
 +
  delay(500);
 +
  motorDriver.setSingleMotor(M4, -2048);  // 电机M4 50%速度反转
 +
  delay(500);
 +
  motorDriver.setSingleMotor(M4, 0);  // 电机M4停止
 +
  delay(1000);
 +
 
 +
  motorDriver.setMotor(0, 4096, 2048, 1024); // 电机M1停止,电机M2 全速正转,电机M3 50%正转,电机M4 25%正转
 +
  delay(500);
 +
  motorDriver.setMotor(0, 0, 0, 0);  // 电机M1/M2/M3/M4停止
 +
  delay(500);
 +
  motorDriver.setMotor(0, -1024, -2048, -4096);  // 电机M1停止,电机M2 25%反转,电机M3 50%反转,电机M4 全速反转,
 +
  delay(500);
 +
  motorDriver.setMotor(0, 0, 0, 0);  // 电机M1/M2/M3/M4停止
 +
  delay(1000);
 +
 
 +
  motorDriver.setAllMotor(4096);  // 电机M1/M2/M3/M4 全速正转
 +
  delay(500);
 +
  motorDriver.setAllMotor(0);  // 电机M1/M2/M3/M4 停止
 +
  delay(500);
 +
  motorDriver.setAllMotor(-4096);  // 电机M1/M2/M3/M4 全速反转
 +
  delay(500);
 +
  motorDriver.setAllMotor(0);  // 电机M1/M2/M3/M4 停止
 +
  delay(1000);
 +
 
 +
  motorDriver.setMotor(4096, 4096, 4096, 4096);      // 电机M1/M2/M3/M4 全速正转
 +
  delay(500);
 +
  motorDriver.stopMotor(M1);    // 电机M1 刹车
 +
  delay(500);
 +
  motorDriver.setMotor(-4096, -4096, -4096, -4096);  // 电机M1/M2/M3/M4 全速反转
 +
  delay(500);
 +
  motorDriver.stopMotor(MAll);  // 电机M1/M2/M3/M4 刹车
 +
  delay(1500);
 +
}
 +
</source>
 +
 
 +
 
 +
== 扩展接线 ==
 +
 
 +
使用Arduino UNO与IIC电机驱动模块驱动麦轮接线示例。
 +
 
 +
'''注意:电机驱动仅适合arduino部分型号使用,购买前请联系客服询问具体的型号,不支持其它类型的板子,如:STM32,51,树莓派,ESP32,掌控板,microBit等。模块可以使用的驱动电流持续1.2A,峰值3.2A,这要求不能使用超电流使用,建议使用TT马达,N20电机,GA25电机(注意型号和参数),GB37电机低功率,GB520低功率。'''
 +
 
 +
 
 +
[[File:Mecanum wheel 4wd c.png|600px]]
 +
 
 +
 
 +
=== 参考资料 ===
 +
 
 +
* [https://yfrobot.gitee.io/wiki/doc/PCA9685_datasheet.pdf PCA9685 datasheet]
 +
* [https://yfrobot.gitee.io/wiki/doc/tb6612fng_datasheet.pdf TB6612FNG datasheet]
 +
 
 +
 
 +
'''官方购买:[https://item.taobao.com/item.htm?spm=a1z10.3-c-s.w4002-11773248163.12.538163a5H9VnQK&id=627007991368 IIC电机驱动模块]'''
 +
----
 +
 
 +
 
 +
[[首页 | 返回首页]]
 +
 
 +
更多建议和问题欢迎反馈至 [http://www.yfrobot.com YFRobot论坛]
  
motorDirver.stopMotor(MAll); // 电机M1/M2/M3/M4 刹车
+
  购买方式: [http://yfanmcu.taobao.com企业店铺]

2021年8月17日 (二) 09:52的最后版本

生成缩略图出错:文件可能丢失:
motor driver

产品简介

IIC-四路电机驱动模块是采用堆叠式设计,可直接插于Arduino UNO主控板或其兼容板上的电机驱动模块。它集成了PCA9685芯片(一个I2C总线控制的16通道PWM控制器)、2片TB6612电机驱动芯片,只占用Arduino IIC端口(A4-SDA/A5-SCL)即可控制4路电机,IIC地址0x40。

IIC-四路电机驱动模块可直接连接M1、M2、M3、M4,4路电机,接口顺序:电机正极、电机负极、编码器负极、编码器正极、A相、B相;兼容本店多款电机:25、37、N20;且扩展5路IIC接口、1路VGTR串行通信接口、 6路3PGVS标准传感器接口、1路串行通信接口,扩展性强。


规格参数

  • 逻辑供电电压:5V DC
  • VIN电机供电电压:2.5V~13.5V DC(推荐6V~12VDC)
  • VS供电电压:跳线帽短接则为5V,不短接可外接4.8V~6V
  • IIC协议控制电机(IIC地址:0x40)
  • 5路IIC扩展口(V/G/D-sda/C-scl)
  • 1路UART串口通信扩展口(V/G/T-txd/R-rxd)
  • 6路GVS I/O扩展口(V由VS供电,通过跳线帽选择如何连接电源)
  • 4路电机接口(电机正极/电机负极/编码器负极/编码器正极/A相/B相)
  • 电源指示灯x1


功能说明

MotorDriver IIC.png

IIC电机驱动模块与Arduino UNO排母对齐插入,无需外接导线。

供电部分由上部IIC电机驱动板输入,底部主板无需再输入电源。

编码器端口电源部分由底部主板的5V端口输入,信号读取也同样是arduino端口读取,不是arduino适配的型号不建议使用此模块做驱动。


Arduino 扩展库

Arduino library : https://github.com/YFROBOT-TM/Yfrobot-Motor-Driver-Library 库文件下载最新版本,Arduino IDE软件版本要求1.8以上。


Arduino 扩展库使用方法

调用库:

#include <MotorDriver.h>   // 包含头文件

创建对象:

#define MOTORTYPE YF_IIC_TB ;

方法 Methods:

初始化

motorDriver.begin();;

设置电机反向,参数:1-默认,-1-反向

const int offsetm1 = 1;
const int offsetm2 = -1;
const int offsetm3 = 1;
const int offsetm4 = -1;// M1/M3 默认方向 M2/M4反向

驱动单个电机,参数:电机序号 M1,M2,M3,M4;电机速度 -4096~4096

motorDriver.setSingleMotor(M1, 4096);   // M1电机全速正转
motorDriver.setSingleMotor(M1, 0);   // M1电机停止

驱动4路电机,参数:电机速度 -4096~4096

motorDriver.setMotor(0, 4096, 2048, 1024);  // 电机M1停止,电机M2 全速正转,电机M3 50%正转,电机M4 25%正转
motorDriver.setMotor(0, 0, 0, 0);  // 电机M1/M2/M3/M4停止
motorDriver.setAllMotor(4096); // 电机M1/M2/M3/M4 全速正转
motorDriver.setAllMotor(0);  // 电机M1/M2/M3/M4停止

电机刹车/急停

motorDriver.stopMotor(M1);  // 电机M1 刹车
motorDriver.stopMotor(MAll);  // 电机M1/M2/M3/M4 刹车

示例代码

/***************************************************
  Motor Test - IIC Motor Drive
 
  motor driver library: https://github.com/YFROBOT-TM/Yfrobot-Motor-Driver-Library
  motor driver iic Introduction: http://www.yfrobot.com.cn/wiki/index.php?title=MotorDriver_IIC
  motor driver iic:https://item.taobao.com/item.htm?id=626324653253
 
  YFROBOT ZL
  08/13/2020
 ****************************************************/
#include <MotorDriver.h>
 
#define MOTORTYPE YF_IIC_TB   //
uint8_t SerialDebug = 1; // 串口打印调试 0-否 1-是
 
// these constants are used to allow you to make your motor configuration
// line up with function names like forward.  Value can be 1 or -1
const int offsetm1 = 1;
const int offsetm2 = -1;
const int offsetm3 = 1;
const int offsetm4 = -1;
 
// Initializing motors.
MotorDriver motorDriver = MotorDriver(MOTORTYPE);
 
void setup() {
  Serial.begin(9600);
  Serial.println("Motor Drive test!");
  motorDriver.begin();
  motorDriver.motorConfig(offsetm1, offsetm2, offsetm3, offsetm4);
  delay(1000);   // wait 2s
  Serial.println("Start...");
}
 
void loop() {
  motorDriver.setSingleMotor(M1, 4096);  // 电机M1全速正转
  delay(500);
  motorDriver.setSingleMotor(M1, 0);  // 电机M1停止
  delay(500);
  motorDriver.setSingleMotor(M2, -2048);  // 电机M2 50%速度反转
  delay(500);
  motorDriver.setSingleMotor(M2, 0);  // 电机M2停止
  delay(500);
  motorDriver.setSingleMotor(M3, 4096);  // 电机M3全速正转
  delay(500);
  motorDriver.setSingleMotor(M3, 0);  // 电机M3停止
  delay(500);
  motorDriver.setSingleMotor(M4, -2048);  // 电机M4 50%速度反转
  delay(500);
  motorDriver.setSingleMotor(M4, 0);  // 电机M4停止
  delay(1000);
 
  motorDriver.setMotor(0, 4096, 2048, 1024); // 电机M1停止,电机M2 全速正转,电机M3 50%正转,电机M4 25%正转
  delay(500);
  motorDriver.setMotor(0, 0, 0, 0);  // 电机M1/M2/M3/M4停止
  delay(500);
  motorDriver.setMotor(0, -1024, -2048, -4096);  // 电机M1停止,电机M2 25%反转,电机M3 50%反转,电机M4 全速反转,
  delay(500);
  motorDriver.setMotor(0, 0, 0, 0);  // 电机M1/M2/M3/M4停止
  delay(1000);
 
  motorDriver.setAllMotor(4096);   // 电机M1/M2/M3/M4 全速正转
  delay(500);
  motorDriver.setAllMotor(0);  // 电机M1/M2/M3/M4 停止
  delay(500);
  motorDriver.setAllMotor(-4096);  // 电机M1/M2/M3/M4 全速反转
  delay(500);
  motorDriver.setAllMotor(0);  // 电机M1/M2/M3/M4 停止
  delay(1000);
 
  motorDriver.setMotor(4096, 4096, 4096, 4096);       // 电机M1/M2/M3/M4 全速正转
  delay(500);
  motorDriver.stopMotor(M1);    // 电机M1 刹车
  delay(500);
  motorDriver.setMotor(-4096, -4096, -4096, -4096);   // 电机M1/M2/M3/M4 全速反转
  delay(500);
  motorDriver.stopMotor(MAll);  // 电机M1/M2/M3/M4 刹车
  delay(1500);
}


扩展接线

使用Arduino UNO与IIC电机驱动模块驱动麦轮接线示例。

注意:电机驱动仅适合arduino部分型号使用,购买前请联系客服询问具体的型号,不支持其它类型的板子,如:STM32,51,树莓派,ESP32,掌控板,microBit等。模块可以使用的驱动电流持续1.2A,峰值3.2A,这要求不能使用超电流使用,建议使用TT马达,N20电机,GA25电机(注意型号和参数),GB37电机低功率,GB520低功率。


Mecanum wheel 4wd c.png


参考资料


官方购买:IIC电机驱动模块



返回首页

更多建议和问题欢迎反馈至 YFRobot论坛

购买方式: 企业店铺