繁体   English   中英

android和arduino uno之间的蓝牙串行通信

[英]Bluetooth serial communication between android and arduino uno

我对Phonegap非常陌生。 我需要通过arduino和android mobile发送和接收数据。我至少或最好说零知识如何做到这一点。 请大家帮我。按此链接无法理解。 https://github.com/don/BluetoothSerial如果您这样做的话,请给出逐步的说明。

首先,如果您没有蓝牙屏蔽,则需要为Ardunio uno购买蓝牙屏蔽。 蓝牙屏蔽罩应具有有关如何将其连接到Ardunio uno以便使用串行端口的说明。 Android具有随SDK一起分发的出色示例应用程序,称为BluetoothChat,您应该可以轻松找到它。 我修改了BluetoothChatService.java文件以与Arduino板通信,对代码进行了一些简单的修改,您可以在其中使用该应用程序连接到Arduino板或任何其他蓝牙设备。

我在课程开始时添加了它,第二个UUID用于连接到Arduino板。

// Name for the SDP record when creating server socket
private static String NAME  = null;
private static final String NAME1 = "BluetoothChat";
private static final String NAME2 = "itead";

// Unique UUID for this application
private static UUID MY_UUID = null;
private static final UUID MY_UUID1 = UUID.fromString("fa87c0d0-afac-11de-8a39-0800200c9a66");
private static final UUID MY_UUID2 = UUID.fromString("00001101-0000-1000-8000-00805f9b34fb");

另外,我修改了这种方法

/**
 * Start the ConnectThread to initiate a connection to a remote device.
 * @param device  The BluetoothDevice to connect
 */
public synchronized void connect(BluetoothDevice device) {
    if (D) Log.d(TAG, "connect to: " + device);

    if(device.getName().indexOf("itead")!=-1)
    {
      MY_UUID = MY_UUID2;
      NAME    = NAME2;
    }
    else
    {
      MY_UUID = MY_UUID1;
      NAME    = NAME1;
    }
    // Cancel any thread attempting to make a connection
    if (mState == STATE_CONNECTING) {
        if (mConnectThread != null) {mConnectThread.cancel(); mConnectThread = null;}
    }

    // Cancel any thread currently running a connection
    if (mConnectedThread != null) {mConnectedThread.cancel(); mConnectedThread = null;}


    // Start the thread to connect with the given device
    mConnectThread = new ConnectThread(device);
    mConnectThread.start();
    setState(STATE_CONNECTING);
}

您应该使用我对示例应用程序所做的一些更改来连接并与Arduino板通信。

希望对您有用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM