gpt4 book ai didi

android - 蓝牙 HC-05 无法与 Android 配对

转载 作者:行者123 更新时间:2023-11-29 00:25:38 24 4
gpt4 key购买 nike

所以,最近我在学习这些系列教程http://www.youtube.com/playlist?list=PL2cK5QO_pN1gfEcWZ8tCWUb-WyxAiMyIK使用蓝牙模块HC-05连接Arduino与Android

我完全按照他的方案做了,蓝牙模块在我的安卓设备上被检测为 HC-05,但无法配对。红色 LED 持续闪烁。作为http://mcuoneclipse.com/2013/06/19/using-the-hc-06-bluetooth-module/表示模块上的红色LED指示状态:闪烁:准备配对常亮:已配对

这是我应该在我的设备名称旁边得到输出“(Paired)”的代码

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();
}
}
}

};

相反,我 toast 说设备未配对

@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 的视频上)

最佳答案

我找到了自己的答案,在使用我们自己的 android 应用程序连接之前,我们必须先从系统设置>蓝牙>输入蓝牙模块的密码(在我的例子中是 1234)进行配对

关于android - 蓝牙 HC-05 无法与 Android 配对,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19782103/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com