当前位置:网站首页>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
边栏推荐
- Array sorting num ranking merge in ascending order
- Bugku's Eval
- Your childhood happiness was contracted by it
- CODING DevSecOps 助力金融企业跑出数字加速度
- OSI 七层模型
- 17.[STM32]仅用三根线带你驱动LCD1602液晶
- Appium自动化测试基础 — APPium基础操作API(二)
- The difference between abstract classes and interfaces in PHP (PHP interview theory question)
- Bugku telnet
- Surpass palm! Peking University Master proposed diverse to comprehensively refresh the NLP reasoning ranking
猜你喜欢
vlunhub- BoredHackerBlog Social Network
机械臂速成小指南(九):正运动学分析
Database learning - Database Security
Advanced level of static and extern
Surpass palm! Peking University Master proposed diverse to comprehensively refresh the NLP reasoning ranking
基于OpenHarmony的智能金属探测器
I spring web upload
Summary of the third class
OSI seven layer model
Fundamentals of data communication - Principles of IP routing
随机推荐
Bugku's Ping
I spring web upload
Usage and usage instructions of JDBC connection pool
Definition of episodic and batch
六种常用事务解决方案,你方唱罢,我登场(没有最好只有更好)
Your childhood happiness was contracted by it
The difference between abstract classes and interfaces in PHP (PHP interview theory question)
wyt 。。
Bugku easy_ nbt
Ten billion massage machine blue ocean, difficult to be a giant
Go learning ----- relevant knowledge of JWT
Data communication foundation - dynamic routing protocol rip
Detailed explanation of QT creator breakpoint debugger
Bugku's Ah Da
Value series solution report
episodic和batch的定义
复现Thinkphp 2.x 任意代码执行漏洞
Stop B makes short videos, learns Tiktok to die, learns YouTube to live?
Good article inventory
P6183 [USACO10MAR] The Rock Game S