当前位置:网站首页>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
边栏推荐
- Database learning - Database Security
- Common interview questions about swoole
- I spring and autumn blasting-1
- Reproduce ThinkPHP 2 X Arbitrary Code Execution Vulnerability
- OSI seven layer model
- 示例项目:简单的六足步行者
- Ten billion massage machine blue ocean, difficult to be a giant
- vulnhub-Root_ this_ box
- Aike AI frontier promotion (7.5)
- The computer is busy, and the update is a little slow
猜你喜欢
Arduino控制微小的六足3D打印机器人
wxml2canvas
Surpass palm! Peking University Master proposed diverse to comprehensively refresh the NLP reasoning ranking
Huawei Hubble incarnation hard technology IPO harvester
Data communication foundation OSPF Foundation
MySQL overview
Appium自动化测试基础 — APPium基础操作API(二)
Bugku's eyes are not real
21.[STM32]I2C协议弄不懂,深挖时序图带你编写底层驱动
Common PHP interview questions (1) (written PHP interview questions)
随机推荐
Au - delà du PARM! La maîtrise de l'Université de Pékin propose diverse pour actualiser complètement le classement du raisonnement du NLP
17.[STM32]仅用三根线带你驱动LCD1602液晶
Data communication foundation - route republication
六种常用事务解决方案,你方唱罢,我登场(没有最好只有更好)
Noi / 1.5 37: mercenaries
First PR notes
D-snow halo solution
Bugku's steganography
I spring web upload
Memo 00
把 ”中台“ 的思想迁移到代码中去
Noi / 1.4 07: collect bottle caps to win awards
16.[STM32]从原理开始带你了解DS18B20温度传感器-四位数码管显示温度
SQL injection sqllabs (basic challenges) 1-10
基于OpenHarmony的智能金属探测器
F. Min cost string problem solving Report
Value series solution report
Severlet learning foundation
21.[STM32]I2C协议弄不懂,深挖时序图带你编写底层驱动
Database learning - Database Security