版本协议

CC BY-NC-SA 4.0

标签
专业版
#第11届立创电赛#超低功耗电容式蓝牙土壤湿度计

创建时间:3周前

146 2

描述

<p style="line-height:1.8;"> </p> <h3 style="line-height:1.8;"><span style="font-size:14pt;">* 1、项目功能介绍</span></h3> <hr> <p><span style="font-size:12pt;">一切的起因都是从家里那颗发财树被我浇水浇过头开始……</span></p> <p><span style="font-size:12pt;">为了能精准知道什么时候该浇水,我开始研究起了<strong style="margin:0px;padding:0px;color:#1a1a2e;">土壤湿度计</strong>。</span></p> <p><span style="font-size:12pt;">土壤湿度计从原理上主要分为两种:<strong style="margin:0px;padding:0px;color:#1a1a2e;">电导率测量</strong>和<strong style="margin:0px;padding:0px;color:#1a1a2e;">电容值测量</strong>。</span></p> <p style="line-height:1.8;"> </p> <div style="font-size:15px;"> <table style="margin:0px;padding:0px;width:670.286px;font-size:14px;height:99.9374px;"> <tr style="margin:0px;padding:0px;height:19.5982px;"> <th style="height:19.5982px;"><span style="font-size:12pt;">测量方式</span></th> <th><span style="font-size:12pt;">优点</span></th> <th style="height:19.5982px;"><span style="font-size:12pt;">缺点</span></th> </tr> <tr style="margin:0px;padding:0px;height:40.1696px;"> <td style="margin:0px;padding:10px 14px;border-color:#e0e4eb;vertical-align:top;height:40.1696px;"><span style="font-size:12pt;">电导率法</span></td> <td style="margin:0px;padding:10px 14px;border-color:#e0e4eb;vertical-align:top;height:40.1696px;"><span style="font-size:12pt;">电路简单</span></td> <td style="margin:0px;padding:10px 14px;border-color:#e0e4eb;vertical-align:top;height:40.1696px;"><span style="font-size:12pt;">电极易氧化,需使用抗腐蚀金属,成本偏高</span></td> </tr> <tr style="margin:0px;padding:0px;background:#fafbfc;height:40.1696px;"> <td style="margin:0px;padding:10px 14px;border-color:#e0e4eb;vertical-align:top;height:40.1696px;"><span style="font-size:12pt;">电容法</span></td> <td style="margin:0px;padding:10px 14px;border-color:#e0e4eb;vertical-align:top;height:40.1696px;"><span style="font-size:12pt;">传感器可绝缘,寿命长,线性度好</span></td> <td style="margin:0px;padding:10px 14px;border-color:#e0e4eb;vertical-align:top;height:40.1696px;"><span style="font-size:12pt;">传统方案功耗偏高</span></td> </tr> </table> </div> <p style="line-height:1.8;"><span style="font-size:12pt;"><span style="font-family:'-apple-system', BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', Roboto, 'Helvetica Neue', Arial, sans-serif;text-align:justify;background-color:#ffffff;">电容测量本身传感器可以做到完全绝缘,因此在</span><strong style="text-align:justify;background-color:#ffffff;">寿命上优于电导率方式</strong><span style="font-family:'-apple-system', BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', Roboto, 'Helvetica Neue', Arial, sans-serif;text-align:justify;background-color:#ffffff;">,同时</span><strong style="text-align:justify;background-color:#ffffff;">线性度也更加优秀</strong><span style="font-family:'-apple-system', BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', Roboto, 'Helvetica Neue', Arial, sans-serif;text-align:justify;background-color:#ffffff;">。</span></span></p> <p style="line-height:1.8;"> </p> <h3><span style="font-size:14pt;">传统方案的痛点</span></h3> <p><span style="font-size:12pt;">市面上常见的电容式土壤湿度计,大多依赖 <strong style="margin:0px;padding:0px;color:#1a1a2e;">RC 振荡电路</strong> 产生方波,通过<strong style="margin:0px;padding:0px;color:#1a1a2e;">频率变化</strong>来推测土壤湿度。然而振荡电路的<strong style="margin:0px;padding:0px;color:#1a1a2e;">缺点在于功耗偏高</strong>,大部分方案的功耗在 <strong style="margin:0px;padding:0px;color:#1a1a2e;">10~100mA</strong> 级别,难以长时间依靠电池供电运行。</span></p> <p><span style="color:#3598db;font-size:12pt;">本项目核心目标:在保持电容测量优势的前提下,大幅降低系统功耗。</span></p> <p style="line-height:1.8;"> </p> <h3><span style="font-size:14pt;">核心创新方案</span></h3> <p><span style="font-size:12pt;">电容测量除了 RC 振荡法之外,还有另一种方式:<strong style="margin:0px;padding:0px;color:#1a1a2e;">恒流恒定时间充电法</strong>—— 以恒定电流对电容充电固定时间,然后通过电压计算电容值。</span></p> <p><span style="font-size:12pt;"><strong style="margin:0px;padding:0px;color:#1a1a2e;">CH584</strong> 芯片内置了该功能,支持 <strong style="margin:0px;padding:0px;color:#1a1a2e;">10~100pF</strong> 的电容测量范围。通过合理的 PCB 设计,可以使等效电容值刚好落在这个区间内,从而实现精准的土壤湿度测量。</span></p> <p> </p> <h3><span style="font-size:14pt;">功耗与工作策略</span></h3> <p><span style="font-size:12pt;">为了尽可能延长设备续航时间,同时保证使用体验,采用了以下工作策略:</span></p> <div style="font-size:15px;"> <table style="margin:0px;padding:0px;width:670.286px;font-size:14px;"> <tr style="margin:0px;padding:0px;"> <th><span style="font-size:12pt;">工作项</span></th> <th><span style="font-size:12pt;">频率</span></th> <th><span style="font-size:12pt;">说明</span></th> </tr> <tr style="margin:0px;padding:0px;"> <td style="margin:0px;padding:10px 14px;border-color:#e0e4eb;vertical-align:top;"><span style="font-size:12pt;">蓝牙广播</span></td> <td style="margin:0px;padding:10px 14px;border-color:#e0e4eb;vertical-align:top;"><span style="font-size:12pt;">每 <strong style="margin:0px;padding:0px;color:#1a1a2e;">2 秒</strong> 一次</span></td> <td style="margin:0px;padding:10px 14px;border-color:#e0e4eb;vertical-align:top;"><span style="font-size:12pt;">低功耗蓝牙广播,用于数据上报</span></td> </tr> <tr style="margin:0px;padding:0px;background:#fafbfc;"> <td style="margin:0px;padding:10px 14px;border-color:#e0e4eb;vertical-align:top;"><span style="font-size:12pt;">湿度测量</span></td> <td style="margin:0px;padding:10px 14px;border-color:#e0e4eb;vertical-align:top;"><span style="font-size:12pt;">每 <strong style="margin:0px;padding:0px;color:#1a1a2e;">5 秒</strong> 一次</span></td> <td style="margin:0px;padding:10px 14px;border-color:#e0e4eb;vertical-align:top;"><span style="font-size:12pt;">电容采样 + 湿度换算</span></td> </tr> <tr style="margin:0px;padding:0px;"> <td style="margin:0px;padding:10px 14px;border-color:#e0e4eb;vertical-align:top;"><span style="font-size:12pt;">电池电压测量</span></td> <td style="margin:0px;padding:10px 14px;border-color:#e0e4eb;vertical-align:top;"><span style="font-size:12pt;">每 <strong style="margin:0px;padding:0px;color:#1a1a2e;">10 秒</strong> 一次</span></td> <td style="margin:0px;padding:10px 14px;border-color:#e0e4eb;vertical-align:top;"><span style="font-size:12pt;">监测电池电量</span></td> </tr> </table> </div> <p> </p> <p><span style="font-size:12pt;">广播数据包含:</span></p> <ul> <li style="margin:0px 0px 6px;padding:0px;"><span style="font-size:12pt;">电容采样后的<strong style="margin:0px;padding:0px;color:#1a1a2e;">原始 ADC 值</strong></span></li> <li style="margin:0px 0px 6px;padding:0px;"><span style="font-size:12pt;"><strong style="margin:0px;padding:0px;color:#1a1a2e;">电池电压值</strong></span></li> <li style="margin:0px 0px 6px;padding:0px;"><span style="font-size:12pt;">转换后的<strong style="margin:0px;padding:0px;color:#1a1a2e;">湿度百分比</strong></span></li> <li style="margin:0px 0px 6px;padding:0px;"><span style="font-size:12pt;">转换后的<strong style="margin:0px;padding:0px;color:#1a1a2e;">电量百分比</strong></span></li> </ul> <p> </p> <p><span style="font-size:12pt;">得益于 <strong style="margin:0px;padding:0px;color:#1a1a2e;">CH584 优秀的功耗管理</strong>,整个电路<strong style="margin:0px;padding:0px;color:#1a1a2e;">平均功耗仅 22μA</strong>,一颗 <strong style="margin:0px;padding:0px;color:#1a1a2e;">200mAh 的 CR2032 纽扣电池</strong>可以<strong style="margin:0px;padding:0px;color:#1a1a2e;">连续使用1整年</strong>,大幅降低设备维护频率。</span></p> <p><span style="font-size:12pt;"><img src="https://image.lceda.cn/oshwhub/pullImage/94bc48ed90274b2eab7d2cdf5a3e4f32.jpg" alt="" width="774" height="510"></span></p> <p style="line-height:1.8;"> </p> <h3><span style="font-size:14pt;">土壤标定流程</span></h3> <p><span style="font-size:12pt;">首次使用时,需进行<strong style="margin:0px;padding:0px;color:#1a1a2e;">土壤标定</strong>。通过发送蓝牙指令,可以分别标定两个基准点:</span></p> <ol> <li style="margin:0px 0px 6px;padding:0px;"><span style="font-size:12pt;"><strong style="margin:0px;padding:0px;color:#1a1a2e;">"全干土壤"</strong> → 对应 <strong style="margin:0px;padding:0px;color:#1a1a2e;">0%</strong> 湿度</span></li> <li style="margin:0px 0px 6px;padding:0px;"><span style="font-size:12pt;"><strong style="margin:0px;padding:0px;color:#1a1a2e;">"全湿土壤"</strong> → 对应 <strong style="margin:0px;padding:0px;color:#1a1a2e;">100%</strong> 湿度</span></li> </ol> <p><span style="font-size:12pt;">固件记录这两个基准值后,后续土壤湿度通过<strong style="margin:0px;padding:0px;color:#1a1a2e;">线性插值计算</strong>得出。最后可以为设备<strong style="margin:0px;padding:0px;color:#1a1a2e;">重命名</strong>,就能与不同花盆中的其他设备区分开了。</span></p> <p> </p> <p><img src="//image.lceda.cn/pullimage/Ygy4GCdLvCmLVbiLNTq485uPOsLuQlWuLTXW67tn.png" alt="" width="475" height="674"></p> <p style="line-height:1.8;"> </p> <h3 style="line-height:1.8;"><span style="font-size:14pt;">*2、项目属性</span></h3> <hr> <p style="line-height:1.8;"><span style="color:#95a5a6;">首次公开;项目完全原创;项目未曾在其他比赛中获奖;项目未参加过答辩。</span></p> <p style="line-height:1.8;"> </p> <h3 style="line-height:1.8;"><span style="font-size:14pt;">* 3、开源协议</span></h3> <hr> <p style="line-height:1.8;"><span style="color:#212529;font-size:medium;background-color:#ffffff;">本项目以CC BY-NC-SA 4.0协议发放</span></p> <p style="line-height:1.8;"> </p> <h3 style="line-height:1.8;"><span style="font-size:14pt;">*4、硬件部分</span></h3> <hr> <p><span style="font-size:12pt;">这个湿度计核心部分其实就是CH584F最小系统,USB\LDO\TVS只是为了没有烧录器的人下载程序用,去掉不影响设备运行。</span></p> <p><span style="font-size:12pt;">触摸传感器本质上也是电容测量,所以只需要设计一个合适的“触摸区域”,就能直接利用芯片进行土壤湿度检测。</span></p> <p style="line-height:1.8;"> </p> <h3 style="line-height:1.8;"><span style="font-size:14pt;">*5、软件部分</span></h3> <hr> <h3>开发环境</h3> <p><span style="font-size:12pt;"><span style="font-family:'-apple-system', BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', Roboto, 'Helvetica Neue', Arial, sans-serif;text-align:justify;background-color:#ffffff;">软件使用 </span><strong style="text-align:justify;background-color:#ffffff;"> MSR2</strong><span style="font-family:'-apple-system', BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', Roboto, 'Helvetica Neue', Arial, sans-serif;text-align:justify;background-color:#ffffff;"> 开发环境进行开发,编译后的固件可以直接通过 </span><strong style="text-align:justify;background-color:#ffffff;">沁恒 ISP 软件</strong><span style="font-family:'-apple-system', BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', Roboto, 'Helvetica Neue', Arial, sans-serif;text-align:justify;background-color:#ffffff;">从 USB 口烧录进芯片。</span></span></p> <p> </p> <h3><span style="font-size:14pt;">软件流程</span></h3> <p><span style="font-size:12pt;"><span style="font-family:'-apple-system', BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', Roboto, 'Helvetica Neue', Arial, sans-serif;text-align:justify;background-color:#ffffff;">通过TMOS定时</span><span style="background-color:#ffffff;font-family:'-apple-system', BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', Roboto, 'Helvetica Neue', Arial, sans-serif;text-align:justify;">(每5秒)</span><span style="background-color:#ffffff;font-family:'-apple-system', BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', Roboto, 'Helvetica Neue', Arial, sans-serif;text-align:justify;">触发数据更新,每次广播时更新数据值。</span></span></p> <p> </p> <h3><span style="font-size:14pt;">线性插值计算</span></h3> <p><span style="font-size:12pt;">标定完成后,土壤湿度通过以下公式计算:</span></p> <pre style="font-size:13px;line-height:1.7;color:#24292e;"><span style="font-size:12pt;"><code>湿度(%) = (1 - (ADC_当前 - ADC_湿土) / (ADC_干土 - ADC_湿土)) × 100%</code></span></pre> <p style="line-height:1.8;"> </p> <h3><span style="font-size:14pt;">广播数据包</span></h3> <p>在mainApp.cpp里,</p> <p><code>static uint8_t advertDataV[31] = {</code><br><code>    /* flags */</code><br><code>        0x02, 0x01, 0x06,  //00-02</code><br><code>        0x09, 0x16,  //03-04</code><br><code>        0xF0, 0x77, 0x00, 0x00, 0x77, 0x0F, 0x00, 0x00, //05-12</code><br><code>        </code><br><code>        /* device name */</code><br><code>        //13  14   15</code><br><code>        0x10-4, 0x09, 'L', 't', 't', 'E', 'S', 'T', 'M', 'o', 'n', 'V', '1'</code></p> <p><code>};</code></p> <p> </p> <p><code>void adverCB(uint32_t timeUs)</code><br><code>{</code><br><code>    if(cfgMgr.NameModifyed != 0)</code><br><code>    {</code><br><code>        advertDataV[13] = cfgMgr.config.NameStrLen+1;</code><br><code>        tmos_memcpy(advertDataV +15, cfgMgr.config.NameStr, cfgMgr.config.NameStrLen);</code><br><code>        advertDataSize = 15+cfgMgr.config.NameStrLen;</code><br><code>        cfgMgr.NameModifyed = 0;</code><br><code>    }</code></p> <p><br><code>    advertDataV[7] = curKval&0xFF;</code><br><code>    advertDataV[8] = (curKval>>8)&0xFF;</code><br><code>    advertDataV[9] = curAdcV&0xFF;</code><br><code>    advertDataV[10] = (curAdcV>>8)&0xFF;</code><br><code>    </code><br><code>    advertDataV[11] = cfgMgr.CalcWetVal(curKval);</code><br><code>    advertDataV[12] = cfgMgr.CalcBatVal(curAdcV);</code></p> <p><code>    GAP_UpdateAdvertisingData(Peripheral_TaskID_Real, TRUE, advertDataSize, advertDataV);</code></p> <p><code>}</code></p> <p>advertDataV的03-12为自定义数据,其中 advertDataV[05] = 0xF0, advertDataV[06] = 0x77 作为识别标记,后续紧跟2字节湿度ADC值,2字节电压mV值,1字节湿度百分比,1字节电量百分比。</p> <p>后续如有需要蓝牙网关识别,主要就依赖这段数据。</p> <p> </p> <h3><span style="font-size:14pt;">参数修改</span></h3> <p>还是在mainApp.cpp里,void newDatain(uint8_t * inData,int len)负责处理蓝牙写入的指令处理。</p> <p>代码都有完整注释,可以直接看到每一个指令。</p> <p>写入指令为  0x75 0x35 负载长度 命令字 负载数据 </p> <p>0x75 0x35 为识别头,负载长度即负载数据的字节数。</p> <p>命令字目前只有3个:</p> <p><code>    switch (bcmdBuffer[3]) //命令字</code><br><code>    {</code><br><code>        case 1: //修改蓝牙名</code><br><code>        {</code><br><code>            if(bcmdBuffer[2] < 2)</code><br><code>            {</code><br><code>                //蓝牙名无效</code><br><code>            }</code><br><code>            else</code><br><code>            {</code><br><code>                if(bcmdBuffer[2] > 15)</code><br><code>                {</code><br><code>                    bcmdBuffer[2] = 15;</code><br><code>                }</code><br><code>                cfgMgr.SetBleName(bcmdBuffer+4,bcmdBuffer[2]);</code><br><code>            }</code><br><code>        }</code><br><code>        break;</code><br><code>        </code><br><code>        case 2: //设置为满湿度</code><br><code>        {</code><br><code>            cfgMgr.SetWetADC(curKval);</code><br><code>        }</code><br><code>        break;</code></p> <p><code>        case 3: //设置为干燥值</code><br><code>        {</code><br><code>            cfgMgr.SetDryADC(curKval);</code><br><code>        }</code><br><code>        break;</code><br><code>    </code><br><code>    }</code></p> <p> </p> <h3 style="line-height:1.8;"><span style="font-size:14pt;">*6、BOM清单</span></h3> <hr> <p style="line-height:1.8;"><span style="color:#95a5a6;">见后面自动生成的BOM,所有元件均已验证,可直接使用。</span></p> <p style="line-height:1.8;"> </p> <h3 style="line-height:1.8;"><span style="font-size:14pt;">*7、大赛LOGO验证</span></h3> <hr> <p style="line-height:1.8;"><img src="//image.lceda.cn/pullimage/RUhuZoP21xMXjNPK5QpEJWkOhuTtsbhfDahroSoL.jpeg" alt="" width="842" height="561"></p> <p style="line-height:1.8;"> </p> <h3 style="line-height:1.8;">* 8、演示您的项目并录制成视频上传</h3> <hr> <p style="line-height:1.8;"><a href="https://www.bilibili.com/video/BV14sGm6yEar/" target="_blank">https://www.bilibili.com/video/BV14sGm6yEar/</a></p>

文档

BOM

附件

附件名 下载
LtSoilMonBLE.zip
com.lotsbiss.LtSoilMon.v1.apk

成员

评论(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