MotorDriver IIC

出自YFRobotwiki
跳轉到: 導覽搜尋
建立縮圖錯誤: 檔案似乎遺失:
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論壇

購買方式: 企業店鋪