【问题标题】:Is there any way to send this Keyboard.Press(); command wireless to my PC via Bluetooth?有没有办法发送这个 Keyboard.Press();通过蓝牙命令无线连接到我的电脑?
【发布时间】:2016-03-01 04:43:08
【问题描述】:

我已经能够通过蓝牙实现我的 Arduino Micro 板的无线数据发送。我使用以下代码将传感器数据从 arduino 板发送到 PC。但我希望它能够做一个 Keyboard.Press();根据我从连接到微型板上的传感器收到的数据。

有没有办法发送这个 Keyboard.Press();通过蓝牙命令无线连接到我的电脑?

我使用 Arduino Micro 和 HC-05 将数据无线发送到 PC。

#include <SoftwareSerial.h>
#include "Wire.h"
#include "I2Cdev.h"
#include "MPU9250.h"

MPU9250 accelgyro;
I2Cdev   I2C_M;

int16_t ax, ay, az;
int16_t gx, gy, gz;
int16_t mx, my, mz;
float Axyz[3];

const int rxPort = 8; // connected to Bluetooth TX
const int txPort = 9; // connected to Bluetooth RX
SoftwareSerial myConnection = SoftwareSerial(rxPort, txPort);

void setup() {
  Wire.begin();
  Serial.begin(9600);
  Serial.println("Initializing I2C devices...");
  accelgyro.initialize();
  Serial.println("Testing device connections...");
  Serial.println(accelgyro.testConnection() ? "MPU9250 connection successful" : "MPU9250 connection failed");
  delay(1000);
  myConnection.begin(9600);

}

void loop() 
{
  myConnection.print(mapX);
  myConnection.print("  ,  ");
  myConnection.println(mapY);
  ////Keyboard.press('a');
}

【问题讨论】:

    标签: bluetooth arduino wireless


    【解决方案1】:

    对于蓝牙 v2,您需要启用 HID 的蓝牙模块。一旦我知道了这个产品

    https://www.sparkfun.com/products/retired/10938

    但现在他们退役了。

    如果你想迁移到蓝牙 v4,我不知道。在网上搜索,您似乎需要实施“HID over GATT profile”(HOGP)。

    我发现this library 用于一些 ble 芯片(nRF8001、nRF2740/nRF2741),其中有蓝牙键盘的示例;否则,如果您已经有 BT4 板,请尝试寻找实现该配置文件的库,或尝试将其移植到您的平台。

    当然这只适用于蓝牙 4 板,因为蓝牙 2 有一些固定的“类”(所以你不能将 BT-serial 适配器变成 BT-HID 设备)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-16
      • 2014-07-12
      • 2016-05-08
      • 1970-01-01
      • 2016-12-26
      相关资源
      最近更新 更多