当前位置:网站首页>Openharmony South learning notes - hi3861+hc-sr04 ultrasonic testing
Openharmony South learning notes - hi3861+hc-sr04 ultrasonic testing
2022-07-23 14:49:00 【Xiao Xiang is a der】
Hi3861+HC-SR04 Ultrasonic testing
Preface
Recently participated in the Lichuang training camp , use Hi3861 Be a robot dog , Then continue to study for a period of time OpenHarmony Device development learning , The ultrasonic module has not been used in the previous notes , In this training camp , I intend to try in Hi3861 try .
Module introduction
The manufacturer's manual is shown below , The author bought 2022 paragraph , Links are as follows :「 Ultrasonic ranging module HC-SR04 ultrasonic sensor Support compatibility UNO R3/51/STM32」.
The module supports four modes to obtain distance , It can be selected through the resistance setting on the back .
1. GPIO Pattern
Sequence diagram

This mode requires Hi3861 Of the two IO Mouth comes with the ultrasonic module TRIG and ECHO Two feet communicate .
Communication process
According to the manufacturer's information , The communication flow of this module is as follows :
1. The main control chip and TRIG Connected IO Configured for output mode , And ECHO Connected IO Configured as input mode ;
2.MCU to TRIG Pin output is greater than 10us High level pulse of ;
3. Module through ECHO The pin returns a high-level pulse signal ;
4. Master record ECHO Pin high level pulse time T And substitute it into the formula .
Code
This code refers to Runhe intelligent tracking obstacle avoidance car sample code . The author here uses the vitality School of intellectual education , Some interface definitions are different .
// An highlighted block
#define Echo 8 //Echo //GPIO8
#define Trig 7 //Trig //GPIO7
#define GPIO_FUNC 0
float GetDistance (void) {
static unsigned long start_time = 0, time = 0;
float distance = 0.0;
IotGpioValue value = IOT_GPIO_VALUE0;
unsigned int flag = 0;
/* =============== GPIO Communication mode process 1 initialization GPIO======================================== */
IoTIoSetFunc(Echo, GPIO_FUNC);// Set up Echo Connect IO For the ordinary GPIO Pattern , No reuse
IoTGpioSetDir(Echo, IOT_GPIO_DIR_IN);// Set up Echo Connect IO Is the input mode
IoTGpioSetDir(Trig, IOT_GPIO_DIR_OUT);// Set up Trig Connect IO For output mode
/* =============== GPIO Communication mode process 2 Output start signal ======================================== */
IoTGpioSetOutputVal(Trig, IOT_GPIO_VALUE1);// pull up Trig
IoTUdelay(20);//20us
IoTGpioSetOutputVal(Trig, IOT_GPIO_VALUE0);// Pull it down Trig
/* =============== GPIO Communication mode process 3 testing Echo High level time of pin output ======================================== */
while (1) {
IoTGpioGetInputVal(Echo, &value);// Read Echo The level state of the pin
if ( value == IOT_GPIO_VALUE1 && flag == 0) {
// If it's high
start_time = IoTGetUs();// Get this time
flag = 1;
}
if (value == IOT_GPIO_VALUE0 && flag == 1) {
// High level ends and becomes low level
time = IoTGetUs() - start_time;// Calculate the high level maintenance time
start_time = 0;
break;
}
}
/* =============== GPIO Communication mode process 4 Substitute the formula to calculate ======================================== */
distance = time * 0.034 / 2;
// printf("distance is %f\r\n",distance);
return distance;
}
Print the results 
About the other three modes of communication , Waiting for the author 10K o 0603 When the resistance arrives, I'm making an introduction .
边栏推荐
- How can manual testing turn to automated testing? Byte 5 years of automation experience talk about
- AI acceleration gesture recognition experience based on efr32mg24
- (heavy chain dissection) Magic Tree
- C language introduction practice (11): enter a group of positive integers and sum the numbers in reverse order
- Aruba learning notes 05 configuration architecture WLAN configuration architecture
- koa框架的使用
- win11安装系统提示virtualBox不兼容需要卸载virtual的解决办法,但是卸载列表找不到virtual的解决办法
- Regular verification of ID number
- LeetCode-227-基本计算器||
- Dynamic programming -- knapsack problem
猜你喜欢

JS texture style pie chart plug-in

Spotlight light box JS plug-in full screen enlarged picture

win11安装系统提示virtualBox不兼容需要卸载virtual的解决办法,但是卸载列表找不到virtual的解决办法

【小程序自动化Minium】三、元素定位- WXSS 选择器的使用

104 maximum depth of binary tree and 543 diameter of binary tree and 124 maximum path sum of binary tree

C language implementation of classroom random roll call system

【C语言】猜数字小游戏+关机小程序

Official wechat product! Applet automation framework minium sharing Preview

直播课堂系统03补充-model类及实体
![[paper notes] mobile robot navigation method based on hierarchical depth reinforcement learning](/img/3d/6486f836535e5a1fa1a362d5214d77.png)
[paper notes] mobile robot navigation method based on hierarchical depth reinforcement learning
随机推荐
Palindrome related topics
Authing 支持 Zadig 啦!云原生用户统一认证快速对接
win11安装系统提示virtualBox不兼容需要卸载virtual的解决办法,但是卸载列表找不到virtual的解决办法
Can bus quick understanding
Chapter 4 set operation
Yunna - how to strengthen fixed asset management? How to strengthen the management of fixed assets?
Yunna | how to manage the fixed assets of the company? How to manage the company's fixed assets better?
10 years of software testing engineer experience, very confused
Detailed tutorial of typora drawing bed configuration
Towhee weekly model
Aruba learning notes 05 configuration architecture WLAN configuration architecture
2022河南萌新联赛第(二)场:河南理工大学 补题题解
OpenHarmony南向学习笔记——Hi3861+HC-SR04超声波检测
自研的数据产品迭代了一年多,为什么不买第三方商业数据平台产品呢?
第2章 基础查询与排序
直播课堂系统02-搭建项目环境
Is it risky and safe to open an account for stock speculation?
什么是Per-Title编码?
LeetCode-227-基本计算器||
[software test] redis abnormal test encountered in disk-to-disk work