2015-02-04 5 views
0

나는 아주 많이 phonegap입니다. arduino와 android mobile을 통해 데이터를 보내고받을 필요가 있습니다.이 작업을 수행하는 방법에 대한 지식이 없다고 말하는 것이 최소한 또는 더 있습니다. 제발 날 도와 줘.이 링크를 따라 가면 이해할 수 없지. https://github.com/don/BluetoothSerial 여러분이이 작업을 수행했다면 단계별 설명을하십시오.안드로이드와 arduino 사이의 블루투스 시리얼 통신 uno

답변

1

먼저 Ardunio uno에 대한 Bluetooth shield를 구입해야합니다. 블루투스 실드에는 직렬 포트를 사용하기 위해 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); 
} 

를 수정했습니다.

희망은 당신을 위해 작동합니다.