所以,最近我按照这一系列教程http://www.youtube.com/playlist?list=PL2cK5QO_pN1gfEcWZ8tCWUb-WyxAiMyIK 使用蓝牙模块 HC-05 连接 Arduino 和 Android
我完全按照他的计划做了,蓝牙模块在我的 android 上检测为 HC-05,但不会配对。红色 LED 一直闪烁。如 http://mcuoneclipse.com/2013/06/19/using-the-hc-06-bluetooth-module/表示模块上的红色LED指示状态:闪烁:准备配对常亮:已配对
这是我应该在设备名称旁边输出“(配对)”的代码
receiver = new BroadcastReceiver(){
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (BluetoothDevice.ACTION_FOUND.equals(action)){
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
devices.add(device);
String s = "";
for(int a=0;a<pairedDevices.size();a++){
if (device.getName().equals(pairedDevices.get(a))){
//append
s = "(Paired)";
break;
}
}
listAdapter.add(device.getName()+" "+s+" "+"\n"+device.getAddress());
}else if (BluetoothAdapter.ACTION_DISCOVERY_STARTED.equals(action)){
}else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)){
}else if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)){
if (btAdapter.getState() == btAdapter.STATE_OFF){
turnOnBT();
}
}
}
};
相反,我得到了祝酒词,说设备未配对
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
// TODO Auto-generated method stub
if (btAdapter.isDiscovering()){
btAdapter.cancelDiscovery();
}
if (listAdapter.getItem(arg2).contains("(Paired)")){
BluetoothDevice selectedDevice = devices.get(arg2);
ConnectThread connect = new ConnectThread(selectedDevice);
connect.start();
}else {
Toast.makeText(getApplicationContext(), "device is not paired", 0).show();
}
}
我错过了什么?注意:我正在使用,外部电源模块 HC-05 有两个芯片(视频上只有一个芯片)Arduino UNO(视频上使用 Android Pro Mini)