MotorDriver IIC:修訂版本之間的差異
(→Arduino 扩展库使用方法) |
|||
第 44 行: | 第 44 行: | ||
创建对象: | 创建对象: | ||
− | <source lang="c"> | + | <source lang="c">#define MOTORTYPE YF_IIC_TB ;</source> |
'''方法 Methods:''' | '''方法 Methods:''' | ||
第 50 行: | 第 50 行: | ||
初始化 | 初始化 | ||
− | <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">motorDriver.stopMotor(MAll); // 电机M1/M2/M3/M4 刹车</source> | ||
=== 扩展接线 === | === 扩展接线 === |
2021年8月17日 (二) 08:49的修訂版本
產品簡介
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 擴展庫使用方法
調用庫:
#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 刹车
擴展接線
使用Arduino UNO與IIC電機驅動模塊驅動麥輪接線示例。
參考資料
官方購買:https://item.taobao.com/item.htm?id=626324653253
更多建議和問題歡迎反饋至 YFRobot論壇
購買方式:YFRobot 電子工作室