Android 与蓝牙模块通信

本文是一位Android初学者关于使用HC-05蓝牙模块进行通信的实践记录。通过USB-TTL连接蓝牙模块并设置波特率,然后在Android端创建界面,实现了蓝牙的连接和数据收发。在实现过程中遇到了连接失败的问题,最终通过CSDN问答找到解决方案,成功连接蓝牙模块。
摘要由CSDN通过智能技术生成

前言

安卓小白,想了解一下蓝牙通信,就做了这个东西

蓝牙模块

采用的是HC-05型号的蓝牙模块
在这里插入图片描述
usb-ttl蓝牙模块 连接
VCC接VCC GND接GND Tx Rx交叉连接
在这里插入图片描述
使用串口助手调试 波特率为9600

发送AT,返回OK  说明已经连接成功(需要加回车换行)

android端

先上效果图
在这里插入图片描述
在这里插入图片描述
界面搭建

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:fitsSystemWindows="true"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <RelativeLayout
        android:background="#199fff"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize">
        <TextView
            android:id="@+id/show_connection_device"
            android:text="未连接"
            android:layout_marginLeft="20dp"
            android:textColor="#ffffff"
            android:textSize="25sp"
            android:layout_centerInParent="true"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
        <ImageView
            android:id="@+id/show_menu_list"
            android:layout_centerInParent="true"
            android:layout_alignParentRight="true"
            android:layout_marginRight="10dp"
            android:src="@drawable/menu_img"
            android:layout_width="30dp"
            android:layout_height="30dp" />
    </RelativeLayout>
    <include layout="@layout/content_main" />
</LinearLayout>

c

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值