专业版
#第九届立创电赛#高颜值触摸温湿度传感器

创建时间:3个月前

296 2

描述

<p><div class="document"> <h3 class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"><span style="font-size: 24pt;">1、项目介绍</span></h3> <hr class="horizontal-splitline normal-bold-2" /> <p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"><span style="color: #000000; font-size: 18pt;">本项目核心电路设计复刻了<em><strong><span style="color: #236fa1;">立创EDA训练营&mdash;&mdash;桌面温湿度检测仪</span></strong></em>。在训练营的基础设计之上,优化了元件和布局以缩小检测仪整体的体积。考虑到单手指难以按下原方案的物理唤醒按键,本项目升级成了单指更易操作的<strong>触摸唤醒</strong>,同时以触摸按键为核心设计了上层触摸面板PCB,兼做温湿度检测仪的面板,提升了整体颜值。</span></p> <ul> <li class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"><span style="color: #000000; font-size: 18pt;">主控使用了低成本的<em><strong>STM32G030K6T6</strong></em></span></li> <li class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"><span style="color: #000000; font-size: 18pt;">温湿度采集选用了<em><strong><span style="color: #2dc26b;">Sensirion盛思锐 </span></strong><strong>SHT40-AD1B </strong></em>高精度温湿度传感器模块</span></li> <li class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"><span style="color: #000000; font-size: 18pt;">电源采用<em><strong>2节7号电池供电</strong></em>,同时支持1.2V的充电电池和1.5V的一次性干电池,主打一个环保</span></li> <li class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"><span style="color: #000000; font-size: 18pt;">数据显示部分采用了经典的 <em><strong>74HC595 </strong></em>三态输出8位移位寄存器+ <em><strong>数码管 </strong></em>的组合</span></li> <li class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"><span style="font-size: 24px;">触摸采用了单通道电容式触摸,选用了 <em><strong>PT2041AT6 </strong></em>作为触摸摸芯片</span></li> <li class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"><span style="font-size: 24px;">主控PCB和触摸面板PCB通过 <em><strong>POGO PIN贴片型弹簧顶针 </strong></em>+ <em><strong>焊盘 </strong></em>的形式连接<img style="display: block; margin-left: auto; margin-right: auto;" src="//image.lceda.cn/oshwhub/2bc6f738b1e04c58b437d9380b892527.png" /><img style="display: block; margin-left: auto; margin-right: auto;" src="//image.lceda.cn/oshwhub/466cc84e7ac54631b8c0c680a183a9ab.png" /></span></li> </ul> <p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;">&nbsp;</p> <h3 class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"><span style="font-size: 24pt;">2、电路设计</span></h3> <hr class="horizontal-splitline normal-bold-2" /> <p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"><span style="font-size: 18pt;">电路设计的整体框架如下图:</span></p> <p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"><img style="display: block; margin-left: auto; margin-right: auto;" src="//image.lceda.cn/oshwhub/f3112a11aaac4ea4887a764d2b005393.png" /></p> <p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"><span style="font-size: 18pt;">电路整体不复杂,主要难点在于需要理解核心显示电路部分的工作原理,即移位寄存器+数码管。单片机其实可以直接通过GPIO来控制数码管的显示,但一个3位数码管需要8个GPIO控制单格位的8段LED+3个GPIO控制3格位的切换显示,共计需要占用11个宝贵的GPIO口资源。这对于引脚有限的STM32单片机是巨大的负担,所以需要通过74HC595这样的三态输出8位移位寄存器,对单片机少量的GPIO口占用实现大量的输出。</span></p> <ul> <li><span style="font-size: 18pt;">74HC595工作原理:SER引脚使用高低电平来输入数据,SCLK引脚通过高低电平变化使得SER输入的数据有效并将至分段。最后RCLK输入高电平来完成整个通讯过程。比如单片机需要将0111 0011输入到74HC595并输出,需要倒序输入,第一个输入的是末尾的1,然后是1、0、0、1、1、1、0。首先拉高SCLK,同时SER拉高输入1(如果需要输入0则保持低电平),完成后SCLK拉低,完成这一位的输入。重复8次输入完成8位后,RCLK输入一个上升沿,完成本轮输入,并将移位寄存器中的数据移至锁存器并进行八位输出。</span><span style="font-size: 18pt;"><img style="display: block; margin-left: auto; margin-right: auto;" src="//image.lceda.cn/oshwhub/51830d8eb2be42cbbcb8a5b87182e9df.png" /></span></li> <li><span style="font-size: 18pt;">共阴极三位数码管工作原理:通过A、B、C、D、E、F、G、DP八个引脚,同时控制三位数字的同一个段,总计8段。而DIG1、DIG2、DIG3则是可以控制同一位数字的八个段。这样两两交叉,就可以一次控制三位中的某一位显示指定的数字了。比如需要第二位显示数字1,那么DIG1和DIG3输入高电平使之没有电势差没有电流导通LED,而DIG2输入低电平形成电势差,使得第二位数字处于可以显示的情况,而数字1需要B、C段同时亮,那么给4和7号引脚高电平,另外6个引脚低电平,那么此时只有第二位数字的B、C两段LED灯两段有电势差,导通点亮,最终完成了在第二位上显示数字1。<img style="display: block; margin-left: auto; margin-right: auto;" src="//image.lceda.cn/oshwhub/a5f02945d72147e892aff728df814ee3.png" /></span></li> </ul> <p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;">&nbsp;</p> <h3 class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"><span style="font-size: 24pt;">3、软件设计</span></h3> <hr class="horizontal-splitline normal-bold-2" /> <div class="lake-content"><span class="ne-text" style="font-size: 18pt;">软件设计采用了STM32CubeMX和Keil5。STM32CubeMX软件可以进行基础代码生成与配置,通过图形化配置的方式,帮助新手快速入门,大大缩短了上手的时间。本项目使用的代码在keil5中需要使用arm compile5编译器,目前最新的keil5中内置的是arm compile6编译器,ac5编译器需要自行安装,在官网注册账号后可以直接下载。</span></div> <div class="lake-content"><span class="ne-text" style="font-size: 18pt;"><img style="display: block; margin-left: auto; margin-right: auto;" src="//image.lceda.cn/oshwhub/2fec26fb4c1e4eb2b331ae0cb73f211b.png" /></span></div> <div class="lake-content"><span class="ne-text" style="font-size: 18pt;">在STM32CubeMX中对GPIO进行设置时,需要理解GPIO的两种输出模式&mdash;&mdash;推挽输出和开漏输出。</span></div> <ul> <li class="lake-content"><span class="ne-text" style="font-size: 18pt;">推挽输出:当想输出高电平时,P-MOS导通,N-MOS截止,输出为电源电压VDD。当想输出低电平时,N-MOS导通,P-MOS截止,相当于引脚直接接地,输出低电平。</span></li> <li class="lake-content"><span class="ne-text" style="font-size: 18pt;">开漏输出模式下,P-MOS一直处于截止状态。当N-MOS导通时,对外输出低电平;当N-MOS截止时,此时P-MOS和N-MOS端同时处于截止状态,两个晶体管的电阻可以看作无穷大,输出呈现出高阻态。开漏输出工作时需要加一个上拉电阻,常使用在芯片直接输出电压和需求不匹配的场景(如STM32输出3.3V,而想要输出5V的电压),可外接一个上拉电阻和5V电源。</span></li> </ul> <div class="lake-content"><span class="ne-text" style="font-size: 18pt;"><img style="display: block; margin-left: auto; margin-right: auto;" src="//image.lceda.cn/oshwhub/457e41667e4f430399cad2f196860a73.png" alt="" width="873" height="406" /><img style="display: block; margin-left: auto; margin-right: auto;" src="//image.lceda.cn/oshwhub/11bbb956807542e2b751c442eb591dbe.png" alt="" width="873" height="401" /><img style="display: block; margin-left: auto; margin-right: auto;" src="//image.lceda.cn/oshwhub/de424873310544e2b6b93bd81b6c7de2.png" alt="" width="873" height="280" /></span></div> <div class="lake-content"><span class="ne-text" style="font-size: 18pt;">综上,推挽输出可以输出高电平和低电平,而开漏输出只能输出低电平。在本项目中需要高低电平切换来输出数据,因此都采用推挽输出模式。</span></div> <div class="lake-content"><span class="ne-text" style="font-size: 18pt;">在keil5中进行代码编写,主要需要三个方面需要理解透彻:</span></div> <ul> <li class="lake-content"><span style="font-size: 24px;">1)与温湿度传感器交互,获取温湿度数据。找到并打开SHT40的相关数据手册,重点查看IIC地址与数据传输协议。</span><span style="font-size: 24px;">由数据手册可知,0x44是IIC地址;当地址最低位是0,表示读数据,最低位是1,表示写数据;</span><span style="font-size: 24px;">当发送0xFD指令时,代表高精度测量温湿度;</span><span style="font-size: 24px;">通过对数据进行公式计算可以得出温湿度;<img style="display: block; margin-left: auto; margin-right: auto;" src="//image.lceda.cn/oshwhub/151e6dd0d9b14def9297712f1c61af58.png" /></span><span style="font-size: 24px;"><img style="display: block; margin-left: auto; margin-right: auto;" src="//image.lceda.cn/oshwhub/7b9da7a9259d4ad080ece5bb8f774d0e.png" /></span></li> <li class="lake-content"><span class="ne-text" style="font-size: 18pt;"><span class="ne-text" style="font-size: 18pt;">2)中断的理解。中断是指单片机在运行过程中,出现了某种需要紧急处理的事件,此时单片机会暂停当前运行的代码,转而执行更加紧急的事件代码。处理完毕后又返回原来被暂停的程序中继续运行。STM32G030K6T6是Cortex ARM0+内核,具有NVIC(嵌套中断控制器)以及EXTI(外部中断事件控制器),支持4种优先级设置,且每一个GPIO均可作为外部中断/事件触发信号输入,通过这二者进行组合,使单片机能够对外部中断/事件进行快速响应。这里对PB7也就是WAKE引脚进行下降沿读取,当发生下降沿时,单片机进入中断处理,执行相关的代码操作,这样就无需在代码中一直轮询按键引脚是否是低电平了。</span></span></li> <li class="lake-content"><span class="ne-text" style="font-size: 18pt;"><span class="ne-text" style="font-size: 18pt;">3)进入休眠模式以及定时器中断。STM32G0系列有四种休眠模式,其中睡眠模式为系统进入睡眠,任意中断/事件唤醒。在Cubemx中设置了定时器14中断,代码中默认是不开启的,启动后自动开始计时。计时时间到来后进入溢出中断。</span></span><span class="ne-text" style="font-size: 18pt;"><span class="ne-text" style="font-size: 18pt;">定时器溢出中断回调函数,在回调函数中进行温度获取和数码管的显示输出。</span></span></li> </ul> <p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;">&nbsp;</p> <h3 class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"><span style="font-size: 24pt;">4、实物展示</span></h3> <hr class="horizontal-splitline normal-bold-2" /> <p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"><span style="font-size: 18pt; color: #000000;">上层触控面板和主控板之间使用的是<strong>M2<em>5+3单通铜柱</strong>固定,主控板和底板之间使用的是<strong>M2</em>15双通铜柱</strong>固定,安装示意图如下</span></p> <p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"><span style="font-size: 18pt; color: #000000;"><img style="display: block; margin-left: auto; margin-right: auto;" src="//image.lceda.cn/oshwhub/01a1aa22323646919ff1441b6d0a3ec4.png" /></span></p> <p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"><span style="font-size: 18pt; color: #000000;">组装完成后实物展示</span></p> <p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"><img style="display: block; margin-left: auto; margin-right: auto;" src="//image.lceda.cn/oshwhub/fabef724b8854f018f595bf678274cae.jpg" alt="" width="623" height="466" /></p> <p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"><img style="display: block; margin-left: auto; margin-right: auto;" src="//image.lceda.cn/oshwhub/2deafe0b47b4468cb0de8a32e84b3a85.jpg" alt="" width="623" height="466" /></p> <p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"><img style="display: block; margin-left: auto; margin-right: auto;" src="//image.lceda.cn/oshwhub/762f5d8bd8014fabbf2bc0a6c67e392d.jpg" alt="" width="623" height="466" /></p> <p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"><span style="font-size: 24pt;">5、演示视频</span></p> <hr class="horizontal-splitline normal-bold-2" /> <p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;">&nbsp;</p> <p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;">&nbsp;</p> </div></p>
  • VID_20240804_183923.mp4

  • VID_20240805_000002.mp4

文档

BOM

暂无

附件

附件名 下载
VID_20240804_183923.mp4
VID_20240805_000002.mp4
项目代码.7z

评论(0)

  • 表情
    emoji
    小嘉工作篇
    小嘉日常篇
  • 图片
成功
工程所有者当前已关闭评论
goToTop
svg-battery svg-battery-wifi svg-books svg-more svg-paste svg-pencil svg-plant svg-ruler svg-share svg-user svg-logo-cn svg-double-arrow