当前位置:网站首页>Fast realization of Bluetooth communication between MCU and mobile phone
Fast realization of Bluetooth communication between MCU and mobile phone
2022-06-27 06:24:00 【shine_ blink】
Core Via mobile phone Ble Bluetooth for communication
Big update !
shineblink.com Development free App, Developers don't have to do anything Android or IOS Development , That is, you can have a mobile phone that can and Core Development board communication specialty App
One 、 Realization function
Core Our main chip comes with BLE Bluetooth function , So just Core You can easily realize the mutual communication with mobile phones . The function of this chapter is to establish Bluetooth connection with mobile phone :(1)Core every other 0.2 Send a packet of data to the mobile phone in seconds ,(2) We're debugging on the phone App Customize any packet sent to Core,Core When received, pass through Print() Function print out .
Be careful : because Core Inside comes 2.4G Wireless capabilities , Therefore, the Bluetooth communication function of this chapter can be realized without external devices or modules . But if it's used Ble Bluetooth function ,Core Of 2.4G The single point or multi-point communication function cannot be used , Developers need to pay attention to this .
Mobile debugging App Here we choose to use apples IOS Well known LightBlue, Android mobile phone download and install BleTool Or Android version LightBlue It's fine too .
Two 、 Implementation mechanism
Core Of ble Low power Bluetooth offers two features , One is Write characteristic , One is Notify characteristic . among :
Write characteristic : It can be seen as a mobile phone sending data to Core The passage of , The mobile phone is sent to Core The data is stored in Write In the feature .
Notify characteristic : It can be seen as Core Channel to send data to the phone ,Core The data sent to the mobile phone through Bluetooth is stored in Notify On . But we need to pay attention , The phone wants to receive from Core The data of , You need to enable this on your mobile phone Notify( It will be mentioned in the following demonstration ).
The following is true. Core Of Ble Provided by the service describe , It doesn't matter if you don't understand this paragraph , Just follow the above understanding .
service(UUID: 0x0001) describe : service There are two features (Characteristic):
One for sending data , One to receive dataRx Characteristic (UUID: 0x0002) Used to receive data from mobile phones Mobile phone Bluetooth can be used through ATT Write Way to Rx
Characteristic send data Tx Characteristic (UUID: 0x0003) To send data to a mobile phone If Bluetooth is Tx
Characteristic Enabled notification, Then the device can send notification To send data to mobile phone Bluetooth
3、 ... and 、 Complete code
-- Configure Low Power Bluetooth to work with default parameters , The name of the device is "MyBle002"
-- The device name is the name shown in the list when the mobile phone scans the Bluetooth device .
LIB_NrfBleDefaultConfig("MyBle002")
-- Start the big cycle
while(GC(1) == true)
do
LIB_DelayMs(200)
send_tab = {
0,1,2,3,4,5,6,7,8,9}
-- take send_tab In the array 10 Elements sent to the phone
LIB_NrfBleSend(send_tab)
-- Check whether you receive Bluetooth data from your mobile phone , If you receive it print Print out
recv_flag, recv_tab = LIB_NrfBleRecv()
if recv_flag == 1 then
-- Print received data
for k,v in ipairs(recv_tab) do
print(k,v)
end
end
end
Four 、 demonstration
1. Turn on the iPhone LightBlue Software , And start searching for Bluetooth devices nearby , find "MyBle002" Then click to enter
2. find properties notify characteristic , Click to enter
3. Click on Listen for notification, So that you can receive Core The data is coming in
4. You can see every 0.2 A packet of data will be received in seconds
5. Back to the step 2 The interface of , Click on properties write, And then click write new value
6. Set to send to Core The data is AA BB CC DD EE FF
7. Last in Core Of TF Cary LOG.TXT The file can be seen that we just sent it manually by mobile phone Core Of AA BB CC DD EE FF data
For more details, please refer to shineblink.com The website links
边栏推荐
猜你喜欢
线程间等待与唤醒机制、单例模式、阻塞队列、定时器
KubeSphere 集群配置 NFS 存储解决方案-收藏版
Multithreading basic Part3
C语言练手小项目(巩固加深知识点理解)
我对于测试团队建设的意见
汇编语言-王爽 第9章 转移指令的原理-笔记
JVM对象组成和存储
汇编语言-王爽 第13章 int指令-笔记
The restart status of the openstack instance will change to the error handling method. The openstack built by the container restarts the compute service method of the computing node and prompts the gi
飞行器翼尖加速度和控制面的MPC控制
随机推荐
软件测试年终总结报告模板
Us camera cloud service scheme: designed for lightweight video production scenes
日期 数据库日期 字符串 之间互相转换
线程间等待与唤醒机制、单例模式、阻塞队列、定时器
Create a basic WDM driver and use MFC to call the driver
openresty使用文档
JS to implement bidirectional data binding
JVM整体结构解析
cpu-z中如何查看内存的频率和内存插槽的个数?
[QT notes] simple understanding of QT meta object system
【QT小记】QT元对象系统简单认识
程序猿学习抖音短视频制作
My opinion on test team construction
快速实现单片机和手机蓝牙通信
Assembly language - Wang Shuang Chapter 13 int instruction - Notes
汇编语言-王爽 第11章 标志寄存器-笔记
427-二叉树(617.合并二叉树、700.二叉搜索树中的搜索、98. 验证二叉搜索树、530.二叉搜索树的最小绝对差)
JVM的垃圾回收机制
TiDB的使用限制
表单校验 v-model 绑定的变量,校验失效的解决方案