(SKU:DFR0432)WBG-01追风无线手柄

来自DFRobot Product Wiki
跳转至: 导航搜索
WBG-01

目录

概述

你想你的遥控器单手就可以遥控你自己的机器人吗?

DFRobot新推出的BLE 4.0无线遥控手柄是基于TI的CC2540蓝牙芯片专为DIY玩家量身打造的一款无线手柄遥控器,是之前手柄的简化版。手柄完成按键运算处理同时还直接支持无线发送。

性能描述


按键定义

Fig1: BLE Wireless Gamepad Key Out
  • 两个功能控制按键,用于电源控制、扫描设备、解除绑定功能
    1. 电源键:用于控制电源开关,断开当前连接
    2. @功能键:用于开启扫描设备、解除绑定
    3. 侧拨功能开关:切换单手/双手操作模式
Warning yellow.png

注:图示中E为F1按键,F为F2按键


控制器应用

电源

这是手柄与其他器件通信的最重要步骤之一。你必须确保你接通电源的电力终端使用正确的极性。反接会损坏手柄。 “人为造成损坏我们将不负责保修,可以提供有偿维修。请确保你使用正确适用的电源。否则,后果自负!”

Warning yellow.png

注:手柄在不用时,10分钟后会自动断电,是正常情况,以防止长时间放电导致电池损坏!!!

功能

    1. "kiss"连接:将手柄靠近设备(如bluno),自动连接
    2. 连接后自动绑定设备MAC
    3. 长按功能@键解除绑定
    4. 轻按功能@键开启扫描功能
    5. 轻按电源键断开当前连接
    6. 长按电源键关闭手柄电源
具体使用方法请参考《追风使用说明书》!

教程

手柄BLE透传协议

此协议完全兼容BLE wireless Gamepad手柄协议,与其他从机设备相连接,传输的按键数据格式,以供小伙伴们参考使用!!!

"数据传输协议"
帧头 地址 长度 命令 数字按键 预留字节 模拟按键 校验和
0x55 0xaa 1 字节 1 字节 1 字节 2 字节 2 字节 4 字节 1 字节

说明:

  • 帧 头:0x55
  • 帧 头:0xaa
  • 地 址:1字节(默认发送的是0x01)
  • 长 度:1字节(数据帧长度0x0e)
  • 命 令:1字节(0x00/0x01)
  • 数字按键:2字节(具体参考下面真值表)
  • 预留字节:2字节(默认发送0x00 0x00)
  • 模拟按键:4字节(具体参考下面说明)
  • 校 验 和:1字节(异或校验)
Warning yellow.png

注:当检测到任何按键处于按下状态时,命令字节会变为0x01,并发送数据;当检测到所有按键处于松开状态时,命令字节会变为0x00,并发送数据。

数字按键

WBG-01追风无线手柄采用的通信协议完全兼容BLE wireless Gamepad协议,但由于数字按键和模拟俺就没有那么多,因此,手柄输出的数据映射到协议的位置解析如下。
"数字按键真值表"
按键 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
F1 1
F2 1
A 1
B 1
C 1
D 1
  • 从上面的真值表可以看出,当按下F1键时,数字按键输出:0x01 0x00
  • 如果同时按下F1、F2键时,数字按键输出:0x03 0x00
  • 同理,按下A、B、C、D键时会输出对应的键值
Fig2: 数字按键输出示意图
Warning yellow.png

注:数字按键输出的数据不受单/双手操作模式的影响

模拟按键

模拟量输出只占“模拟键值”的前两个字节,模拟量的数据受单/双手操作的影响。具体分析如下:
单手操作模式
  • 向上/向下推(F1、F2按键方向为向上,即Fig1图示中的单手操作模式),第一个字节输出00~ff,向上递增,向下递减
  • 向左/向右(模式切换方向为向左),第二个字节输出00~ff,向右递增,向左递减
双手操作模式
  • 向上/向下推(模式切换键方向为向下),第一个字节输出00~ff,向上递增,向下递减
  • 向左/向右(F1、F2按键方向为向上,即Fig1图示中的双手操作模式),第二个字节输出00~ff,向右递增,向左递减

校验和

追风手柄采用的校验和为异或计算,计算代码如下:
for(uint8_t i = 0; i < 13; i++){
  checkSum ^= rec[i];
}
注:其中rec为接收数据包缓存,checkSum为校验和。

使用范例

采用simpleBLEGamepad库文件, 库文件下载请点击我

simpleButtonBlink

功能简介:下载示例代码到bluno主板上,连接手柄,按下手柄上A、B、C、D任意键,Blink灯亮,松开按键后熄灭。
/***************************************************
 This library is designed for the Bluno product line and simpleBLEGamepad iOS and android app from DFRobot.

 DFRobot Bluno product line: http://www.dfrobot.com/index.php?route=product/search&description=true&search=bluno
	—— First of its kind in intergrating BT 4.0(BLE) module into Arduino Uno, ideal prototyping platform for both software and hardware developers to go BLE.
 simpleBLEGamepad iOS application :	 https://itunes.apple.com/us/app/simpleBLEGamepad-bluetooth-4.0-controller/id950937437?mt=8
	—— A universal Bluetooth remote controller

 ***************************************************
 Example introduction:
	Get the button state and the joystick on your phone.
	Open the Serail port and check the real time value via the Serial monitor.

 Created 2016-04-29
 By Andy <Andy.zhou@dfrobot.com>


 GNU Lesser General Public License.
 See <http://www.gnu.org/licenses/> for details.
 All above must be included in any redistribution
 ****************************************************/

/***********Notice and Trouble shooting***************

1. Highly recommend you to config the bluno controllers to work at 9600 baudrate before running the code!
	—— More details about how to config the baudrate: please check the link below:
		http://www.dfrobot.com/wiki/index.php/Bluno_SKU:DFR0267#Configure_the_BLE_through_AT_command
	Please use "AT+UART=9600" command!

******************************************************/
	
#include "simpleBLEGamepad.h"

#define SWITCH_BUTTON_A		0
#define SWITCH_BUTTON_B		1
#define SWITCH_BUTTON_C		2
#define SWITCH_BUTTON_D		3
#define SWITCH_BUTTON_F1	4
#define SWITCH_BUTTON_F2	5

simpleBLEGamepad simpleBLEGamepad_t(Serial);		//init the bluetooth Serial port

int joystickX, joystickY;				//joysticks bufer
int buttonState[6];					//buttons buffer

const int ledPin = 13;					//the pin of the pilot lamp

void setup() {
	//init simpleBLEGamepad and default baudrate is 9600 bps!!!
	simpleBLEGamepad_t.begin();			

	//init LED
	pinMode( ledPin, OUTPUT );		

	//default pinMode is LOW
	digitalWrite( ledPin, LOW );
}

void loop() {
	/*
	 * check if any new command from bluetooth communication
	 * Note: available function must be used in the loop function to keep the serial data receiver running
   *	     Without this function, whole features will be invalid
	 */
	if ( simpleBLEGamepad_t.available() ) {
		joystickX	=	simpleBLEGamepad_t.readJoystickX();	//get the joystickX value
		joystickY = simpleBLEGamepad_t.readJoystickY();			//get the joystickY value

    //read button state when there's valid command from bluetooth
    buttonState[SWITCH_BUTTON_A] = simpleBLEGamepad_t.readSwitch_A();
    buttonState[SWITCH_BUTTON_B] = simpleBLEGamepad_t.readSwitch_B();
    buttonState[SWITCH_BUTTON_C] = simpleBLEGamepad_t.readSwitch_C();
    buttonState[SWITCH_BUTTON_D] = simpleBLEGamepad_t.readSwitch_D();
    buttonState[SWITCH_BUTTON_F1] = simpleBLEGamepad_t.readSwitch_F1();
    buttonState[SWITCH_BUTTON_F2] = simpleBLEGamepad_t.readSwitch_F2();

    Serial.print( "Joystick Value: " );						//debug bluetooth data received
    Serial.print( joystickX );
    Serial.print("  ");
    Serial.print( joystickY );
    for ( int i = 0; i < 6; i++ ) {
      if (buttonState[i] == PRESSED) {
        Serial.print(" ID: ");
        Serial.print(i+1);
        Serial.print("\t ");
        Serial.print("Pressed!");
      }
    /*
      if (buttonState[i] == RELEASED){
        Serial.print("ID: ");
        Serial.print(i);
        Serial.print("\t ");
        Serial.println("Pressed!");Serial.println("Released!");
      }
    */
    }
    Serial.println("");
    
    // When 4 buttons of the control panel is pressed, illuminate the onboard LED of the Arduino!
    // Turn off the LED when none button pressed!
    if (buttonState[SWITCH_BUTTON_A] == PRESSED ||
				buttonState[SWITCH_BUTTON_B] == PRESSED ||
				buttonState[SWITCH_BUTTON_C] == PRESSED ||
				buttonState[SWITCH_BUTTON_D] == PRESSED) {
      digitalWrite(ledPin, HIGH);
    }else
			digitalWrite(ledPin, LOW);
  }
}

资料连接

  • “蓝牙4.0适配器”软件安装包
  • BLE 4.0无线遥控手柄使用说明

Nextredirectltr.png购买 BLE Wireless Gamepad无线手柄 (SKU:DFR0304)

常见问题

还没有客户对此产品有任何问题,欢迎通过qq或者论坛联系我们!

更多问题及有趣的应用,可以 访问论坛 进行查阅或发帖。


更多


DFshopping car1.png [Link DFRobot商城购买链接]

个人工具
名字空间

变换
操作
导航
工具箱