当前位置:网站首页>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
边栏推荐
- 修改pyunit_time使得其支持‘xx~xx月’的时间文本
- Appium automation test foundation - appium basic operation API (II)
- Data communication foundation - routing communication between VLANs
- 复现Thinkphp 2.x 任意代码执行漏洞
- 把 ”中台“ 的思想迁移到代码中去
- Severlet learning foundation
- The elimination strategy of redis
- Usage and usage instructions of JDBC connection pool
- Magic methods and usage in PHP (PHP interview theory questions)
- String modification problem solving Report
猜你喜欢

sql server学习笔记

MySQL giant pit: update updates should be judged with caution by affecting the number of rows!!!
![19.[STM32]HC_SR04超声波测距_定时器方式(OLED显示)](/img/fe/8f59db28823290da8e9280df06673d.jpg)
19.[STM32]HC_SR04超声波测距_定时器方式(OLED显示)

"Sequelae" of the withdrawal of community group purchase from the city

First PR notes

基于OpenHarmony的智能金属探测器

Anti shake and throttling

vlunhub- BoredHackerBlog Social Network

Ionic Cordova project modification plug-in

lv_font_conv离线转换
随机推荐
修改pyunit_time使得其支持‘xx~xx月’的时间文本
1330: [example 8.3] minimum steps
Garbage collection mechanism of PHP (theoretical questions of PHP interview)
Stop B makes short videos, learns Tiktok to die, learns YouTube to live?
Bugku alert
wxml2canvas
Redis' transaction mechanism
Data communication foundation ACL access control list
Noi / 1.5 37: mercenaries
vulnhub-Root_ this_ box
Vulnhub-Moneybox
lv_ font_ Conv offline conversion
Ctfshow web entry command execution
SQL injection sqllabs (basic challenges) 11-20
vlunhub- BoredHackerBlog Social Network
Data communication foundation OSPF Foundation
Redis distributed lock principle and its implementation with PHP (1)
CODING DevSecOps 助力金融企业跑出数字加速度
Basic JSON operations of MySQL 5.7
OceanBase社区版之OBD方式部署方式本地安装