(SKU:DFR0508)FireBeetle Covers-DC Motor&Stepper Driver
目录 |
简介
DFRobot FireBeetle萤火虫系列是专为物联网设计的低功耗开发组件。此款FireBeetle Covers-DC Motor&Stepper Driver模块,是针对FireBeetle系列主控而设计的电机驱动器。它可以同时驱动四路直流电机或者两路二相四线步进电机,通过连接标注的I2C接口到主控,可以对各个电机接口进行配置和驱动。此款FireBeetle电机驱动板,采用了STM8S105作为电机驱动微处理器,负责解析由上位机发送的指令,通过计算后转换成电机驱动信号,支持最高刷新频率(数据更新频率)1ms/次。采用了两颗TB6612FNG高性能电机驱动芯片,静态下,功耗仅30mA,电机驱动能力高达1.2A@5V,峰值电流高达3.2A@5V,电机驱动支持4~12V宽电压(电机驱动供电)输入。其次,FireBeetle电机驱动板还提供了4路独立舵机驱动接口,可以直接通过主控来驱动舵机。
技术规格
- 驱动主控:STM8S105
- 控制电路工作电压:3.3-5V (连接到FireBeetle的VCC)
- 控制电路工作电流:30mA
- 电机驱动芯片:TB6612FNG
- 电机驱动电压:4-12V
- 电机驱动能力:1.2A平均电流@5V
- 峰值电流:3.2A@5V
- 通信接口:I2C接口
- 设备地址:0x18
- 最大刷新频率:1ms
- 工作模式:4路直流电机或2路步进电机
- 支持4路舵机驱动
- 一个状态指示灯
- 外形尺寸: 58mm x 29mm
- 安装孔尺寸:3.1mm x 6mm
- 安装孔位置: 53mm x 24mm
- 安装孔尺寸:内径3.1mm/外径6mm
注意:
|
功能示意图
- 提供四路舵机驱动口(D6-D9)
- 提供四路普通电机驱动口(M1A/M1B, M2A/M2B,M3A/M3B, M4A/M4B)或者两路步进电机驱动口(M1A/M1B/M2A/M2B, M3A/M3B/M4A/M4B)
- eg.(M1A/M1B, M2A/M2B)作为普通电机驱动口,(M3A/M3B/M4A/M4B)作为步进电机驱动口
PinOut
STATUS状态指示灯说明
- 状态1:LED灯闪烁(频率30Hz),说明电机驱动芯片正在等待主机发送初始化指令。
- 状态2:LED常亮,说明电机驱动芯片正常工作(控制电机运转并且等待主机发送新的指令)。
- 状态3:LED熄灭,说明电机驱动芯片出现通讯异常。
注:NC不连接,VCC为电源电压输出(5V-USB供电时, 3.7V-锂电池供电时)
使用教程
准备
这里采用的是FireBeetle系列下的ESP8266主板作为示例,也可以采用其他arduino主控,如UNO,Mega等。
硬件
1 x ESP32/ESP8266控制板
1 x FireBeetle Covers-DC Motor&Stepper Driver模块
1 x 混合式步进电机-42BYGH1861A-C 点此链接购买
1 x 直流电机
软件
Arduino IDE 1.6+, 点击下载Arduino IDE
请先下载FireBeetle Covers-DC Motor&Stepper Driver库 如何安装库文件,点击链接
如何驱动一个直流电机?
FireBeetle Covers-DC Motor&Stepper Driver具备同时驱动四个独立的直流电机的能力,模块上已经清晰的标识出四个电机的接口:M1A和M1B控制一个直流电机,以此类推。该实验阐述了如何通过arduino主板控制一个直流电机。
硬件连接
将直流电机连接到M1A和M1B上,电机正极接M1A,电机负极接M1B。给电机驱动芯片供电4~12V,逻辑供电3.3V~5V,也可以直接插接在FireBeetle主控上进行供电(仍然需要给电机驱动外接电源4~12V)。
样例代码
/*! * @file Motor.ino * @brief DFRobot's Motor Drive * @n The example demonstrates four groups D.C motors work together at the same time, contains operations such as rotation, speed adjustment, brakes and so on. * @copyright [DFRobot](http://www.dfrobot.com), 2016 * @copyright GNU Lesser General Public License * @author [LiXin] * @version V1.0 * @date 2017-7-31 * @https://github.com/DFRobot/DFRobot_MotorStepper */ #include "Arduino.h" #include "Wire.h" #include "DFRobot_MotorStepper.h" /*****************Keywords instruction*****************/ //M1--->motor_Group_1--->[M1A(+),M1B(-)] //M2--->motor_Group_2--->[M2A(+),M1B(-)] //M3--->motor_Group_3--->[M3A(+),M3B(-)] //M4--->motor_Group_4--->[M4A(+),M4B(-)] //CW: rotate in positive direction //CCW: rotate in reverse //A0: Chip Selection Address 1 //A1: Chip Selection Address 2 //A2: Chip Selection Address 3 //A3: Chip Selection Address 4 /*****************Function instruction*****************/ //void start(uint8_t dir) //*This function can be used to start the motor //*dir: Set Orientation CW or CCW //void speed(uint16_t val) //*This function is used to set the motor speed //*val: Set the speed 0<=val<=4096 //void stop() //*This function is used to stop the motor turning DFRobot_Motor motor1(M1,A0); void setup() { //initialize serial communication at 9600 bits per second: Serial.begin(115200); //join i2c bus (address optional for master) Wire.begin(); //Initialize D.C motor drive chip (Group1) motor1.init(); } void loop() { //Setting initial velocity(Min:0 Max:4096) motor1.speed(4096); //Motor1 rotate in positive direction motor1.start(CW); delay(2000); //All motors rotate in reverse motor1.start(CCW); delay(2000); //All motors brake and stop rotating motor1.stop(); delay(2000); } |
程序功能:第一组直流电机顺时针转动2秒,然后逆时针转动2秒,最后停止2秒,如此循环。
函数功能:
1.创建一个电机对象
DFRobot_Motor motor1(M1) M1表示第一组直流电机(M1A(+),M1B(-))
2.初始化电机驱动,读取产品id和版本id并且打印到串口
init()
3.设置电机速度
speed(val) 0<=val<=4096(4096时,速度最大)
4.设置方向,并开始转动
start(dir) dir=CW:正转(顺时针) dir=CCW:反转(逆时针)
如何驱动一个步进电机?
FireBeetle Covers-DC Motor&Stepper Driver驱动板具备同时驱动两个独立的两相四线步进电机,电机接口采用直流电机接口,通过I2C软件配置。示例中,阐述了如何通过arduino主板控制一个两相四线的步进电机。
硬件连接
如图所示,将步进电机连接到STEPPER1上,给电机驱动供电4~12V。
样例代码
/*! * @file Stepper.ino * @brief DFRobot's Motor Drive * @n The example demonstrates two groups of stepping motors (Group A and Group B) work together at the same time, including operations such as precision control of rotation angles, rotation directions etc. * @copyright [DFRobot](http://www.dfrobot.com), 2016 * @copyright GNU Lesser General Public License * @author [LiXin] * @version V1.0 * @date 2017-7-31 * @https://github.com/DFRobot/DFRobot_MotorStepper */ #include "Arduino.h" #include "Wire.h" #include "DFRobot_MotorStepper.h" /*****************Keywords instruction*****************/ //SA--->Stepper_Group_A--->[M1A(A+),M1B(A-),M2A(B+),M2B(B-)] //SB--->Stepper_Group_B--->[M3A(A+),M3B(A-),M4A(B+),M4B(B-)] //CW: rotate in positive direction //CCW: rotate in reverse //A0: Chip Selection Address 1 //A1: Chip Selection Address 2 //A2: Chip Selection Address 3 //A3: Chip Selection Address 4 /*****************Function instruction*****************/ //void start(float angle, uint16_t speed, uint8_t dir) //*This function can be used to start the motor //*angle: Set the Angle Min:0°(If the Angle is equal to 0°,The motor will not stop spinning) //*speed: Set the speed Min:8 //*dir: Set Orientation CW or CCW //void getDir() //*This function can get the current rotation direction of the motor DFRobot_Stepper stepperA(SA,A0); void reverse_SA() { stepperA.start(0, 12, !stepperA.getDir()); } void setup() { //initialize serial communication at 9600 bits per second: Serial.begin(115200); //join i2c bus (address optional for master) Wire.begin(); //Initialize drive chips of stepping motors (Group A and Group B) stepperA.init(); //Setting stepping motor Group A rotate in positive direction stepperA.start(0, 20, CW); } void loop() { //Stepping motor (Group A) rotate in reverse in every 2 seconds reverse_SA(); delay(2000); } |
程序功能:A组步进电机(即:M1A(A+),M1B(A-),M2A(B+),M2B(B-))每隔2秒反向一次
函数功能:
1.创建一个步进电机对象
DFRobot_Stepper stepperA(SA) SA表示A组步进电机(M1A(A+),M1B(A-),M2A(B+),M2B(B-))
2.初始化电机驱动,读取产品id和版本id并且打印到串口
init()
3.步进电机设置旋转角度、速度以及旋转方向,并开始转动
start(angle, speed, dir) angle:设置旋转的分辨率,电机最大分辨率为0.9°,即电机步进的角度最小为0.9°,如果设置0.1°,则电机不会旋转,如果设置1°,则电机只会旋转0.9°。 Min:0°(如果设置角度为0,则电机会一直旋转)。 speed:设置速度,速度范围为0~1023,设置0时速度为0r/min,设置1023时速度最大,最大速度为200r/min dir: 设置方向,dir=CW:正转(顺时针) dir=CCW:反转(逆时针)
4.A组步进电机反向函数
reverse_SA()
如何同时驱动直流电机和步进电机?
在使用步进电机的同时,FireBeetle电机驱动板的另外两个直流电机驱动任然可以独立工作。示例中描述了如何同时控制步进电机和直流电流。
硬件连接
如下图所示,将步进电机连接到STEPPER1上,直流电机连接到M4。
样例代码
/*! * @file Motor_Stepper.ino * @brief DFRobot's Motor Drive * @n The example demonstrates one group of stepping motor and 2 groups of D.C motors work together at the same time, contains direction control of D.C motors and stepping motor. * @copyright [DFRobot](http://www.dfrobot.com), 2016 * @copyright GNU Lesser General Public License * @author [LiXin] * @version V1.0 * @date 2017-7-31 * @https://github.com/DFRobot/DFRobot_MotorStepper */ #include "Arduino.h" #include "Wire.h" #include "DFRobot_MotorStepper.h" /*****************Keywords instruction*****************/ //M3--->motor_Group_3--->[M3A(+),M3B(-)] //M4--->motor_Group_4--->[M4A(+),M4B(-)] //SA--->Stepper_Group_A--->[M1A(A+),M1B(A-),M2A(B+),M2B(B-)] //CW: rotate in positive direction //CCW: rotate in reverse //A0: Chip Selection Address 1 //A1: Chip Selection Address 2 //A2: Chip Selection Address 3 //A3: Chip Selection Address 4 /*****************Function instruction*****************/ //void start(float angle, uint16_t speed, uint8_t dir) //*This function can be used to start the motor //*angle: Set the Angle Min:0°(If the Angle is equal to 0°,The motor will not stop spinning) //*speed: Set the speed Min:8 //*dir: Set Orientation CW or CCW //void getDir() //*This function can get the current rotation direction of the motor DFRobot_Stepper stepperA(SA,A0); DFRobot_Motor motor4(M4,A0); void reverse_4() { motor4.start(!motor4.getDir()); } void reverse_SA() { stepperA.start(0, 12, !stepperA.getDir()); } void setup() { //initialize serial communication at 9600 bits per second: Serial.begin(115200); //join i2c bus (address optional for master) Wire.begin(); //Initialize motor drive chip of stepping motor (Group A) and ¾ group of D.C motor stepperA.init(); motor4.init(); //Set the initial direction motor4.start(CW); stepperA.start(0, 12, CW); delay(1500); } void loop() { static int i=0; //motor4 reverse in every 1.5 seconds reverse_4(); //Stepping motor (Group A) reverse in every 3 seconds if((++i%2) == 0) { reverse_SA(); i=0; } delay(1500); } |
程序功能:A组步进电机(即:M1A(A+),M1B(A-),M2A(B+),M2B(B-))每隔3秒反向一次,第4组直流电机(即:M4A(+),M4B(-))每隔1.5秒反向一次
函数功能:
1.创建一个步进电机对象
DFRobot_Stepper stepperA(SA) SA表示A组步进电机(M1A(A+),M1B(A-),M2A(B+),M2B(B-))
2.创建一个直流电机对象
DFRobot_Motor motor4(M4) M4表示第四组直流电机(M4A(+),M4B(-))
3.初始化电机驱动,读取产品id和版本id并且打印到串口
init()
4.直流电机设置方向,并开始转动
start(dir) dir=CW:正转(顺时针) dir=CCW:反转(逆时针)
5.步进电机设置旋转角度、速度以及旋转方向,并开始转动
start(angle, speed, dir) angle:设置旋转的分辨率,电机最大分辨率为0.9°,即电机步进的角度最小为0.9°,如果设置0.1°,则电机不会旋转,如果设置1°,则电机只会旋转0.9°。 Min:0°(如果设置角度为0,则电机会一直旋转)。 speed:设置速度,速度范围为0~1023,设置0时速度为0r/min,设置1023时速度最大,最大速度为200r/min dir: 设置方向,dir=CW:正转(顺时针) dir=CCW:反转(逆时针)
6.第四组直流电机反向函数
reverse_4()
7.A组步进电机反向函数
reverse_SA()
API函数和宏定义说明
宏定义:
对象: M1--->第一组直流电机--->[M1A(+),M1B(-)] M2--->第二组直流电机--->[M2A(+),M1B(-)] M3--->第三组直流电机--->[M3A(+),M3B(-)] M4--->第四组直流电机--->[M4A(+),M4B(-)] SA--->A组步进电机------>[M1A(A+),M1B(A-),M2A(B+),M2B(B-)] SB--->B组步进电机------>[M3A(A+),M3B(A-),M4A(B+),M4B(B-)] 关键词: CW: 正转(顺时针) CCW: 反转(逆时针 片选地址 A0: 芯片片选地址一 A1: 芯片片选地址二 A2: 芯片片选地址三 A3: 芯片片选地址四 |
函数:
该库用于控制直流电机和步进电机,包括正自旋、反向、调速、停止控制直流电机和步进电机驱动硬件等。 1.打开直流电机和步进电机驱动硬件,并且读取产品ID和版本ID void init(); 2.关闭直流电机和步进电机驱动硬件 void shutdown(); 3.电机停止转动 void stop(); 4.直流电动机设定方向并开始旋转 void start(uint8_t dir); dir: 设置方向 CW or CCW 5.设置步进电机旋转角度,速度,方向,并开始旋转 void start(float angle, uint16_t speed, uint8_t dir); angle: 设置旋转的分辨率;电机最大分辨率为0.9°,即电机步进的角度最小为0.9°,如果设置0.1°,则电机不会旋转,如果设置1°,则电机只会旋转0.9°。 Min:0°(如果角度设置为0,电机就会一直旋转) speed: 设置旋转速度,速度范围为0~1023,设置0时速度为0r/min,设置1023时速度最大,最大速度为200r/min dir: 设置方向 CW or CCW 6.直流电机和步进电机调速 void speed(uint16_t val); val: 设置速度 motor:0<=val<=4096 stepper:0<=val<=1023 |
尺寸图
- pin脚间距:2.54mm
- 安装孔间距:24mm/53mm
- 安装孔尺寸:3.1mm
- 主板尺寸:29.00mm×58.00mm
- 板厚:1.6mm
常见问题
问: FireBeetle Board-ESP32主控如何使用arduino编程来控制舵机? |
- 答: 对于ESP32来说,它本身是不能兼容Arduino IDE自带的舵机库文件的,你可以下载DF给出的兼容库,进行舵机驱动。注意:ESP8266暂时不能驱动舵机库文件,我们将会在后期支持。
问: 插上电机扩展板后,无法下载程序 |
- 答: V1.0板的FireBeetle-ESP32在复位电路上与扩展板存在冲突,需要拔下扩展板下载程序,烧录程序。我们已经在后续的FireBeetle上修复了这个问题。
更多问题及有趣的应用,可以 访问论坛 进行查阅或发帖。 |