当前位置:网站首页>20. [stm32] realize the function of intelligent garbage can by using ultrasonic module and steering gear
20. [stm32] realize the function of intelligent garbage can by using ultrasonic module and steering gear
2022-07-05 15:48:00 【According to point_ DW】
Author's brief introduction : Hello, everyone , My name is DW, Share some of my new knowledge every day , Look forward to making progress with you
Series column :STM32
Small experimental target : Smart trash can
If there is anything that is not well written, you are welcome to correctDevelopment board :STM32F103
Creation time :2022 year 6 month 27 Japan
In the previous post , We have learned how to use the ultrasonic ranging module , At the same time, I also know how to oled The measured data is displayed on , So today I will integrate the knowledge I learned before , Realize the function of intelligent garbage cans .
The specific functions are as follows :
1. Can be in oled On Display the measured distance ;
2. When someone approaches to take out the garbage , The steering gear controls the trash can to open ; After taking out the garbage , The steering gear controls the trash can to close .
In the last article, the principle and application method of ultrasonic module have been introduced in detail , On the basis of the last article , Add a steering gear program , Control the opening and closing of garbage cans .
Hardware connection
OLED:
CS----PB5
DC----PB6
D0----PB7
D1----PB8
RST----PC13
GND--- The earth
VCC---5V
HC_SR04:
Trig-----PA6
Echo----PA7
VCC-----5V
GND---- The earth
The steering gear :
The signal line ( The yellow line ):PB0 Red thread :5V Brown line :GND
Use TIM3 Timer channel 3, Its corresponding PB0 Pin
Prior to The first 12 Article online The process of using the steering gear has been explained in detail , This article uses TIM3 Of CH1, This article USES TIM3 Of CH3, Modify several parameters based on the previous article .
12.[STM32]PWM Pulse width modulation - Steering gear control ( One is enough )
// Configure timer 3
TIM_DeInit(TIM3);
TIM_InitStructure.TIM_Period = 200-1;
TIM_InitStructure.TIM_Prescaler = 7200-1;
TIM_InitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_InitStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_InitStructure.TIM_RepetitionCounter = DISABLE;
TIM_TimeBaseInit(TIM3,&TIM_InitStructure);
TIM_ClearFlag(TIM3,TIM_FLAG_Update);
PWM_InitStructure.TIM_OCMode = TIM_OCMode_PWM1;//PWM1
PWM_InitStructure.TIM_OutputState = TIM_OutputState_Enable;
PWM_InitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OC3Init(TIM3,&PWM_InitStructure);//CH3
TIM_OC3PreloadConfig(TIM3,ENABLE);
TIM_SetCompare3(TIM3,0);
TIM_Cmd(TIM3,ENABLE);
In the 19 Of the article void HC_SR04_Debolan(u8 mode) Make a change in the function , When away from the garbage can 3~10cm when , Slowly open the trash can , Otherwise, the trash can is closed . The specific implementation process is as follows :
void HC_SR04_Debolan(u8 mode){
u16 data1 = 0,data2 = 0; u32 data = 0;
static u8 flag;
HC_SR04_Ranging(&data1,&data2);
if(mode){
for(u8 i=0;i<5;i++){
data = data + data1;
}
}
else{
for(u8 i=0;i<5;i++){
data = data + data2;
}
}
data/=5;
if((data >= 3) && (data) <= 10){
if(flag == 0){
flag=1;
for(u16 i=15;i>5;i--){
TIM_SetCompare3(TIM3,i);
delay_ms(1);
}
delay_ms(1500);//1.5s 1.86s
}
}
else{
if(flag == 1){
flag=0;
for(u16 i=5;i<15;i++){
TIM_SetCompare3(TIM3,i);
delay_ms(1);
}
}
}
OLED_Write_Number(0,30,data);
}
thus , The program is all written , Compiling and burning code , We have successfully achieved the functions we need .
In order to facilitate the next search , Remember to pay a little attention .
This chapter ends , I'll see you in the next chapter
Reference material :
1.STM32 Firmware library manual
2. The punctual atoms STM32 Incomplete manual _ Library function version
Data uploaded , You need to take it yourself
边栏推荐
- The difference between SQL Server char nchar varchar and nvarchar
- Definition of episodic and batch
- 如何将 DevSecOps 引入企业?
- Noi / 1.4 07: collect bottle caps to win awards
- verilog实现计算最大公约数和最小公倍数
- Data communication foundation smart_ Link_&_ Monitor_ Link
- F. Weights assignment for tree edges problem solving Report
- Xiao Sha's arithmetic problem solving Report
- I spring and autumn blasting-2
- Severlet learning foundation
猜你喜欢
F. Min cost string problem solving Report
Optional parameters in the for loop
Value series solution report
Number protection AXB function! (essence)
17.[STM32]仅用三根线带你驱动LCD1602液晶
Bugku's Ah Da
[brief notes] solve the problem of IDE golang code red and error reporting
Usage and usage instructions of JDBC connection pool
Huawei Hubble incarnation hard technology IPO harvester
1330: [example 8.3] minimum steps
随机推荐
记录一下树莓派搭建环境中遇到的坑。。。
Information collection of penetration test
I'm fat, huh
ionic cordova项目修改插件
Data communication foundation - dynamic routing protocol rip
Appium automation test foundation - appium basic operation API (II)
"Sequelae" of the withdrawal of community group purchase from the city
16.[STM32]从原理开始带你了解DS18B20温度传感器-四位数码管显示温度
mapper. Comments in XML files
Basic JSON operations of MySQL 5.7
go学习 ------jwt的相关知识
修改pyunit_time使得其支持‘xx~xx月’的时间文本
go语言编程规范梳理总结
Appium自动化测试基础 — APPium基础操作API(一)
The OBD deployment mode of oceanbase Community Edition is installed locally
First PR notes
Where is the operation of convertible bond renewal? Is it safer and more reliable to open an account
Data communication foundation - Ethernet port mirroring and link aggregation
I spring web upload
P6183 [USACO10MAR] The Rock Game S