MotorDriver IIC:修訂版本之間的差異
(由2名用戶作出的24個中途修訂版本未被顯示) | |||
第 1 行: | 第 1 行: | ||
− | [[File: | + | [[File:IIC电机驱动-800.jpg|350px|thumb|right|motor driver]] |
=== 产品简介 === | === 产品简介 === | ||
第 24 行: | 第 24 行: | ||
=== 功能说明 === | === 功能说明 === | ||
− | + | [[File:MotorDriver IIC.png|800px]] | |
− | IIC电机驱动模块 | + | IIC电机驱动模块 与Arduino UNO排母对齐插入,无需外接导线。 |
供电部分由上部IIC电机驱动板输入,底部主板无需再输入电源。 | 供电部分由上部IIC电机驱动板输入,底部主板无需再输入电源。 | ||
第 34 行: | 第 34 行: | ||
=== Arduino 扩展库 === | === Arduino 扩展库 === | ||
− | Arduino library : https://github.com/YFROBOT-TM/Yfrobot-Motor-Driver-Library | + | |
+ | Arduino library : https://github.com/YFROBOT-TM/Yfrobot-Motor-Driver-Library '''库文件下载最新版本,Arduino IDE软件版本要求1.8以上。''' | ||
+ | |||
==== Arduino 扩展库使用方法 ==== | ==== Arduino 扩展库使用方法 ==== | ||
第 44 行: | 第 46 行: | ||
创建对象: | 创建对象: | ||
− | <source lang="c"> | + | <source lang="c">#define MOTORTYPE YF_IIC_TB ;</source> |
'''方法 Methods:''' | '''方法 Methods:''' | ||
第 50 行: | 第 52 行: | ||
初始化 | 初始化 | ||
− | <source lang="c"> | + | <source lang="c">motorDriver.begin();;</source> |
设置电机反向,参数:1-默认,-1-反向 | 设置电机反向,参数:1-默认,-1-反向 | ||
− | <source lang="c"> | + | <source lang="c">const int offsetm1 = 1; |
− | + | const int offsetm2 = -1; | |
− | + | const int offsetm3 = 1; | |
+ | const int offsetm4 = -1;// M1/M3 默认方向 M2/M4反向</source> | ||
驱动单个电机,参数:电机序号 M1,M2,M3,M4;电机速度 -4096~4096 | 驱动单个电机,参数:电机序号 M1,M2,M3,M4;电机速度 -4096~4096 | ||
− | <source lang="c"> | + | <source lang="c">motorDriver.setSingleMotor(M1, 4096); // M1电机全速正转</source> |
− | <source lang="c"> | + | <source lang="c">motorDriver.setSingleMotor(M1, 0); // M1电机停止</source> |
驱动4路电机,参数:电机速度 -4096~4096 | 驱动4路电机,参数:电机速度 -4096~4096 | ||
− | <source lang="c"> | + | <source lang="c">motorDriver.setMotor(0, 4096, 2048, 1024); // 电机M1停止,电机M2 全速正转,电机M3 50%正转,电机M4 25%正转</source> |
− | <source lang="c"> | + | <source lang="c">motorDriver.setMotor(0, 0, 0, 0); // 电机M1/M2/M3/M4停止</source> |
− | <source lang="c"> | + | <source lang="c">motorDriver.setAllMotor(4096); // 电机M1/M2/M3/M4 全速正转</source> |
− | <source lang="c"> | + | <source lang="c">motorDriver.setAllMotor(0); // 电机M1/M2/M3/M4停止</source> |
电机刹车/急停 | 电机刹车/急停 | ||
− | <source lang="c"> | + | <source lang="c">motorDriver.stopMotor(M1); // 电机M1 刹车</source> |
− | <source lang="c"> | + | <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 UNO与IIC电机驱动模块驱动麦轮接线示例。 | ||
+ | |||
+ | '''注意:电机驱动仅适合arduino部分型号使用,购买前请联系客服询问具体的型号,不支持其它类型的板子,如:STM32,51,树莓派,ESP32,掌控板,microBit等。模块可以使用的驱动电流持续1.2A,峰值3.2A,这要求不能使用超电流使用,建议使用TT马达,N20电机,GA25电机(注意型号和参数),GB37电机低功率,GB520低功率。''' | ||
+ | |||
[[File:Mecanum wheel 4wd c.png|600px]] | [[File:Mecanum wheel 4wd c.png|600px]] | ||
+ | [[File:IIC电机驱动连接示意图.jpg|600px]] | ||
=== 参考资料 === | === 参考资料 === | ||
− | + | ||
* [https://yfrobot.gitee.io/wiki/doc/PCA9685_datasheet.pdf PCA9685 datasheet] | * [https://yfrobot.gitee.io/wiki/doc/PCA9685_datasheet.pdf PCA9685 datasheet] | ||
* [https://yfrobot.gitee.io/wiki/doc/tb6612fng_datasheet.pdf TB6612FNG 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电机驱动模块]''' | ||
---- | ---- | ||
第 100 行: | 第 193 行: | ||
更多建议和问题欢迎反馈至 [http://www.yfrobot.com YFRobot论坛] | 更多建议和问题欢迎反馈至 [http://www.yfrobot.com YFRobot论坛] | ||
− | 购买方式:[http:// | + | 购买方式: [http://yfanmcu.taobao.com/ 企业店铺] |
2024年6月20日 (四) 15:37的最新修訂版本
產品簡介
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
功能說明
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低功率。
參考資料
官方購買:IIC電機驅動模塊
更多建議和問題歡迎反饋至 YFRobot論壇
購買方式: 企業店鋪