描述
<div>
<p style="line-height:1.8">注:* 为必填项</p>
<p style="line-height:1.8"><strong><span style="color:#0093e6">请在报名阶段填写 ↓</span></strong></p>
<p style="line-height:1.8"> </p>
<h3 style="line-height:1.8">* 1、项目功能介绍</h3>
<hr>
<p>最近在网上看到一款《废旧安卓手机暴改遥控坦克,支持画面传输,成品470元》的创意,这款遥控坦克是基于ESP32设计的,通过废旧安卓手机显示坦克拍摄的画面。如下图:</p>
<p><span><img src="//image.lceda.cn/pullimage/GtzQG9PYcLKLQmci68LQYSl37ywjMAOxBZW2v93N.png" alt="" width="500" height="366"></span></p>
<p><span>于是我们想着基于去年的ESP32-C3蓝牙小车,做一个蓝牙遥控的摄像小车,遥控和拍摄画面都通过微信小程序来实现,降低制作的难度和成本。</span></p>
<p><span>本项目基于立创·ESP32S3R8N8开发板、DRV8833直流电机驱动板、OV2640摄像头、OLED显示屏、锂电池、电机、橡胶轮等元件,成本不到100元(详见BOM表)。小车采用两路电源供电,具有低成本、静音、稳定、长续航等特点,适合中小学生学习、二次开发。</span></p>
<p><span>ESP32S3摄像遥控小车具有地面移动摄像的功能,能用于开展农业作物观察、动植物观察、危险区域或无人区域探险、狭窄区域搜索、科学研究等活动。比如我们就尝试开展了农田作物生长情况观察(详见视频)、寻找躲在床底下的猫猫(详见下图)、乐高城探险等应用测试(详见视频)。</span></p>
<p><span><img src="//image.lceda.cn/pullimage/NZ4uFQH9ZDLcoynLQk7IopVRFyA8zGJpvFB84UsR.jpeg" alt="" width="400" height="889"></span></p>
<h3 style="line-height:1.8">*2、项目属性</h3>
<hr>
<p style="line-height:1.8">本项目首次公开,为原创项目。</p>
<p style="line-height:1.8"> </p>
<p style="line-height:1.8"> </p>
<h3 style="line-height:1.8">* 3、开源协议</h3>
<hr>
<p style="line-height:1.8">使用GPL3.0开源协议。100%开源,便于中小学生学习和二次开发。</p>
<p> </p>
<p style="line-height:1.8"> </p>
<p style="line-height:1.8"><strong><span style="color:#0093e6">请在竞赛阶段填写 ↓</span></strong></p>
<p style="line-height:1.8"> </p>
<h3 style="line-height:1.8">*4、硬件部分</h3>
<hr>
<p><span><strong>1)主控芯片</strong></span></p>
<p><span>采用立创·ESP32S3R8N8开发板,高性能随身WiFi与蓝牙开发板,所有资料全开源,丰富教程案例,轻松上手,项目式学习。支持以下功能:</span></p>
<p><span><img src="//image.lceda.cn/pullimage/RJs2mjoYjRB4befLFRTnt4yGw4XfzsRASwScdbBq.jpeg" alt="" width="500" height="306"></span></p>
<p><span>详见官方文档:</span><span><a href="https://lckfb.com/project/detail/lckfb-esp32s3r8n8" target="_blank">https://lckfb.com/project/detail/lckfb-esp32s3r8n8</a></span></p>
<p> </p>
<p><span><strong>2)电机驱动</strong></span></p>
<p><span>采用一块国产小体积DRV8833电机驱动模块。</span></p>
<p><span><img src="//image.lceda.cn/pullimage/l1r56uD9TW8050FSMeouunDWYXXzSun81pFDv5RA.png" alt="" width="500" height="96"></span></p>
<p><span>本项目采用橡胶轮,橡胶轮不能像麦克纳姆轮一样左右水平移动,左边的两个轮子和右边的两个轮子都是同向转动的,所以可以将左边两个电机并联组成一组,右边两个电机并联组成一组,只采用一块国产小体积DRV8833电机驱动模块驱动4个直流减速电机。</span></p>
<p> </p>
<p><span><strong>3)电源方案</strong></span></p>
<p><span>采用两路电源方案,一路为ESP32S3开发板供电,一路为电机供电,避免互相干扰。特别是摄像头,需要更稳定的电压,当电压低时,图像会有水波纹。</span></p>
<p><span><img src="//image.lceda.cn/pullimage/Ucv25UG1X3NkdVLWkqfIXi7SdIzHevGljAgS2Qji.png" alt="" width="600" height="305"></span></p>
<p><span>ESP32S3开发板的供电参考《</span><span><a href="http://mp.weixin.qq.com/s?__biz=MzkzNDQzMTc0OA==&mid=2247484473&idx=1&sn=b1c698b879a1fad8ae31dc54915ed84b&chksm=c2bc1952f5cb9044fa46c54fc8351a25181194b6aeda976ab05db06e466e19abd0dd14840c59&scene=21#wechat_redirect" target="_blank"><span>常用开发板的供电设计方案(3.3V、5V供电方案)</span></a></span><span>》,直接将3.7V锂电池接入ESP32S3开发板的5V引脚,开发板会将3.7V降压到3.3V供MCU使用。</span></p>
<p><span>电机供电采用一个3.7V锂电池通过DRV8833直接供电,不需要降压。如果要让小车的速度更快,可以考虑采用2个3.7V锂电池供电,7.4V的电压能让小车速度更快。</span></p>
<p><span><img src="//image.lceda.cn/pullimage/ePkIw2LG8EjL4j433gSPqfAE7PyRuRMrgKFqo9xj.png" alt="" width="600" height="360"></span></p>
<p><span>因摄像头还需要用到2.8V和1.2V,所以增加了两路降压电路,分别采用XC6206P282MR、XC6206P122MR的LDO将3.3V降到2.8V和1.2V,供摄像头使用。</span></p>
<p> </p>
<p><strong><span>4)小车主板</span></strong></p>
<p><span>因需要使用到OV2640摄像头,PCB板增加了不省贴片电容、电阻,以及LDO、SD卡等,增加了焊接难度。ESP32S3、DRV8833、OV2640摄像头等模块采用2.54排针固定,电池、电机采用XH2.54插件连接,方便焊接、组装,以及元件重复利用。</span></p>
<p><span>PCB板原理图如下:</span></p>
<p><img src="//image.lceda.cn/pullimage/eSKITAQpFHOUzD3nJfTHOFhL3ETYASc5zLj9yrMK.png" alt="" width="800" height="567"></p>
<p><span>PCB图:</span></p>
<p><img src="//image.lceda.cn/pullimage/1dEqcvxMQY8gYNidtFOhktkSiwb5fMKLYb2xcCch.png" alt="" width="600" height="601"></p>
<p><span>焊接图:</span></p>
<p><img src="//image.lceda.cn/pullimage/05Y5XnxbBKQAmzegToSdGyA4YIl4cemxJX1DQMpm.jpeg" alt="" width="600" height="559"></p>
<p><span>PCB板焊接的难度在于那一排的贴片LDO、电容、电阻,其他都简单。</span></p>
<p style="line-height:1.8"> </p>
<p><span> 5)OV2640摄像头模块</span></p>
<p><span>包含三个模块:OV2640模块、转接板、M12镜头和镜头座。</span></p>
<p><span><img src="//image.lceda.cn/pullimage/nd5v8JcC21MuokIQHoS2eG25NFxBFmEVuTDZX16h.jpeg" alt="" width="500" height="770"></span></p>
<p><span>这是我们做的一个开源工程,详见:</span><span><a href="https://oshwhub.com/cnas2023/camera-zhuan" target="_blank">https://oshwhub.com/cnas2023/camera-zhuan</a></span></p>
<p><span>摄像头转接板比较简单,只有一个24脚转接口和一个FPC接口。我们又在网上买了个镜头和镜头座,让摄像头拍摄的照片更清晰些。这块转接板是24脚的,没有去掉不用的引脚,适用于OV2640和OV5640,需要更高分辨率也可以用OV5640。</span></p>
<p><span> 6)电机、橡胶轮、固定支架</span></p>
<p><span>某宝上买的,电机、车轮、固定支架各4个,不超过15元。</span></p>
<p><span><img src="//image.lceda.cn/pullimage/fspjsEvCozVlaUXWxblGuvkRVYkCqjeJF1Q825kc.png" alt="" width="600" height="241"></span></p>
<p><span>麦克纳姆轮具有随意改变行驶方向的特性,但稳定性较差,容易打滑,而且噪声较大。使用橡胶轮代替后,行驶稳定,且轮胎几乎没有噪声(噪声来自减速电机)。</span></p>
<p><span>7)电池</span></p>
<p><span><img src="//image.lceda.cn/pullimage/GcTsHJMeAahqpURJUykcG4SDpdOjBpyhouverjI8.jpeg" alt="" width="500" height="365"></span></p>
<p><span>3.7V锂电池两颗,带XH2.54接线端子。我们用的是从坏的小米电动牙刷上拆下来的。</span></p>
<p><span>8)成果图</span></p>
<p><span>组装好的成品:</span></p>
<p><img src="//image.lceda.cn/pullimage/CvcszIFiTk7KJuZ6CfRSaiegvpu0il5DKOF59Wan.jpeg" alt="" width="800" height="489"><img src="//image.lceda.cn/pullimage/LUKrSAyUXtepz5UIJJ0hHPe8AHsWKrnzqu2MPqGg.jpeg" alt="" width="800" height="613"><img src="//image.lceda.cn/pullimage/YpyOwhtZU4eTtYnhKJ5Rh8CZl654tauZ9KIGULrB.jpeg" alt="" width="800" height="541"><img src="//image.lceda.cn/pullimage/ON1IuADajobXBHoEYfCz3jgOH9vmbtVEdl9rFBc6.jpeg" alt="" width="800" height="549"><img src="//image.lceda.cn/pullimage/sDYE0qYiy6QXzARKmr8GcGyZTq6h3DXpW3cnner3.jpeg" alt="" width="800" height="798"></p>
<p> </p>
<p style="line-height:1.8"><span style="color:#95a5a6;font-size:14px"> 注:请前往<span style="text-decoration:underline"><a href="https://lceda.cn/editor" target="_blank">嘉立创EDA</a> </span>生成/上传设计文件,文件完成后,相关文稿将自动生成至项目详情;这里可以详细说明您的项目实现原理和机制、注意事项、调试方法、测试方法等。推荐图文并茂的形式向别人介绍您的想法。 </span></p>
<p style="line-height:1.8"> </p>
<h3 style="line-height:1.8">*5、软件部分</h3>
<hr>
<p style="line-height:1.8"> </p>
<p><strong><span>1)遥控器(微信小程序)</span></strong></p>
<p><span>我们开发的一个微信小程序,用来控制蓝牙小车行动并实时显示摄像头拍摄的画面。小程序二维码:</span></p>
<p><span><img src="//image.lceda.cn/pullimage/TBOslgDb0af1NInPYGiQ84u4rwi4SZ1A0svc5aMb.jpeg" alt="" width="344" height="344"></span></p>
<p><span>——小程序主界面</span></p>
<p><span><img src="//image.lceda.cn/pullimage/BVLyV7UWkUMOHYNNB32gXQOV6vO2ygMXN156mXXL.jpeg" alt="" width="350" height="778"></span></p>
<p><span><img src="//image.lceda.cn/pullimage/YpA7V1dOS0DbrMlBSTEsZG4fUKqcORFACFIFOZ6b.jpeg" alt="" width="350" height="778"></span></p>
<p><span>——小程序使用的UUID与Bluefruit Connect一致,默认是:</span></p>
<pre><span>service_uuid</span> <span>=</span> <span>'6E400001-B5A3-F393-E0A9-E50E24DCCA9E'</span><br><span>reader_uuid</span> <span>=</span> <span>'6E400002-B5A3-F393-E0A9-E50E24DCCA9E'</span><br><span>sender_uuid</span> <span>=</span> <span>'6E400003-B5A3-F393-E0A9-E50E24DCCA9E'</span></pre>
<p><span><img src="//image.lceda.cn/pullimage/z0J74MN3Veg6O6hTCmNqqvGesHPEuTTgWS182u4p.jpeg" alt="" width="350" height="778"></span></p>
<p><span>——小程序的6个按键,分别为上、下、左、右、A、B,按下按键分别向连接的蓝牙小车发送"upup"、"down"、"left"、"right"、"act1"、"bac2"。</span></p>
<p><span>——小程序的浏览窗口用于实时显示摄像头拍摄的画面,浏览窗口地址为"http://"+文本框输入的地址+":5000/video_feed"</span></p>
<p><span>小程序的操作详见视频。</span></p>
<p> </p>
<p><strong><span>2)小车程序(基于Micropython)</span></strong></p>
<p><span>小车程序一共包含电机控制、摄像头、SD卡、OLED等模块,当接收到微信小程序发送的"upup"、"down"、"left"、"right"指令时,做出前进、后退、左转、右转的动作,当接收到"act1"指令时,拍摄一张照片并存储在SD卡上。</span></p>
<p><span>因小车需要使用蓝牙遥控,并使用WIFI进行图像传输,所以我们使用了双线程,分别控制,避免干扰。参考代码如下:</span></p>
<pre><span>from</span> <span>machine</span> <span>import</span> <span>Pin</span>,<span>freq</span>,<span>SDCard</span>,<span>Timer</span>,<span>SoftI2C</span><br><span>from</span> <span>time</span> <span>import</span> <span>sleep_ms</span>,<span>sleep</span><br><span>import</span> <span>bluetooth</span>,<span>network</span>,<span>camera</span>,<span>_thread</span>,<span>ssd1306</span>,<span>ufont</span><br><span>from</span> <span>microdot</span> <span>import</span> <span>Microdot</span><br><br><span># 设置CPU的工作频率为 240 MHz</span><br><span>freq</span>(<span>240000000</span>)<br><br><span># 初始化OLED</span><br><span>i2c</span> <span>=</span> <span>SoftI2C</span>(<span>scl</span><span>=</span><span>Pin</span>(<span>4</span>), <span>sda</span><span>=</span><span>Pin</span>(<span>5</span>)) <br><span>display</span> <span>=</span> <span>ssd1306</span>.<span>SSD1306_I2C</span>(<span>128</span>, <span>64</span>, <span>i2c</span>) <span># 定义oled</span><br><span>font</span> <span>=</span> <span>ufont</span>.<span>BMFont</span>(<span>"unifont-14-12917-16.v3.bmf"</span>) <span># 定义字体库</span><br><br><span># 初始化SD卡</span><br><span>sd</span> <span>=</span> <span>SDCard</span>(<br> <span>slot</span><span>=</span><span>1</span> , <span>width</span><span>=</span><span>1</span>, <span>cd</span><span>=</span><span>None</span>, <span>wp</span><span>=</span><span>None</span>,<br> <span>sck</span><span>=</span><span>1</span>,<span>miso</span><span>=</span><span>3</span>,<span>mosi</span><span>=</span><span>2</span>,<br> <span>cs</span><span>=</span><span>None</span> ,<span>freq</span><span>=</span><span>20000000</span><br> ) <span>#定义SD卡</span><br><span>os</span>.<span>mount</span>(<span>sd</span>, <span>'/sd'</span>) <span>#挂载SD卡</span><br><br><span># 初始化</span><br><span>BLE_MSG</span> <span>=</span> <span>""</span><br><span>i</span><span>=</span><span>0</span><br><br><span>''' 定义小车电机引脚和动作函数 '''</span><br><span>Left0</span> <span>=</span> <span>Pin</span>(<span>6</span>,<span>Pin</span>.<span>OUT</span>) <span># O6引脚,左前轮电机向前</span><br><span>Left1</span> <span>=</span> <span>Pin</span>(<span>7</span>,<span>Pin</span>.<span>OUT</span>) <span># O7引脚,左前轮电机向后</span><br><span>Right0</span> <span>=</span> <span>Pin</span>(<span>41</span>,<span>Pin</span>.<span>OUT</span>) <span># 41引脚,右前轮电机向前</span><br><span>Right1</span> <span>=</span> <span>Pin</span>(<span>42</span>,<span>Pin</span>.<span>OUT</span>) <span># 42引脚,右前轮电机向后</span><br><br><span># 车向前进</span><br><span>def</span> <span>cargo</span>():<br> <span>Left1</span>.<span>value</span>(<span>1</span>)<br> <span>Left0</span>.<span>value</span>(<span>0</span>)<br> <span>Right1</span>.<span>value</span>(<span>1</span>)<br> <span>Right0</span>.<span>value</span>(<span>0</span>)<br> <br><span># 车向后退</span><br><span>def</span> <span>carback</span>(): <br> <span>Left1</span>.<span>value</span>(<span>0</span>)<br> <span>Left0</span>.<span>value</span>(<span>1</span>)<br> <span>Right1</span>.<span>value</span>(<span>0</span>)<br> <span>Right0</span>.<span>value</span>(<span>1</span>) <br> <br><span># 车停止</span><br><span>def</span> <span>carstop</span>():<br> <span>Left1</span>.<span>value</span>(<span>0</span>)<br> <span>Left0</span>.<span>value</span>(<span>0</span>)<br> <span>Right1</span>.<span>value</span>(<span>0</span>)<br> <span>Right0</span>.<span>value</span>(<span>0</span>)<br><br><span># 车向左转</span><br><span>def</span> <span>carleft</span>(): <br> <span>Left1</span>.<span>value</span>(<span>0</span>)<br> <span>Left0</span>.<span>value</span>(<span>1</span>)<br> <span>Right1</span>.<span>value</span>(<span>1</span>)<br> <span>Right0</span>.<span>value</span>(<span>0</span>) <br><br><span># 车向右转</span><br><span>def</span> <span>carright</span>(): <br> <span>Left1</span>.<span>value</span>(<span>1</span>)<br> <span>Left0</span>.<span>value</span>(<span>0</span>)<br> <span>Right1</span>.<span>value</span>(<span>0</span>)<br> <span>Right0</span>.<span>value</span>(<span>1</span>)<br> <br> <br><span>'''定义网页图传相关函数,以及一些定义'''</span><br><span>#拍照</span><br><span>def</span> <span>take_picture</span>():<br> <span>global</span> <span>i</span><br> <span>i</span> <span>=</span> <span>i</span><span>+</span><span>1</span><br> <span>buf</span> <span>=</span> <span>camera</span>.<span>capture</span>()<br> <span>with</span> <span>open</span>(<span>'/sd/{}.jpg'</span>.<span>format</span>(<span>i</span>),<span>'wb'</span>) <span>as</span> <span>f</span>:<br> <span>f</span>.<span>write</span>(<span>buf</span>)<br> <span>print</span>(<span>"拍照成功!"</span>)<br> <span>sleep</span>(<span>0.01</span>)<br><br><span>def</span> <span>connect</span>():<br> <span>wlan</span> <span>=</span> <span>network</span>.<span>WLAN</span>(<span>network</span>.<span>STA_IF</span>)<span># 定义模式为连接热点</span><br> <span>wlan</span>.<span>active</span>(<span>True</span>)<br> <span>if</span> <span>not</span> <span>wlan</span>.<span>isconnected</span>(): <span>#是否连接热点</span><br> <span>wlan</span>.<span>connect</span>(<span>'<span>SSID</span>'</span>, <span>'<span>password</span>'</span>)<span>#连接网络,SSID和password改成目前的2.4G网络的名称(SSID)和密码(password)</span><br> <span>while</span> <span>not</span> <span>wlan</span>.<span>isconnected</span>():<br> <span>pass</span><br> <br><br><span>connect</span>() <span># 联网</span><br><span>wlan</span> <span>=</span> <span>network</span>.<span>WLAN</span>(<span>network</span>.<span>STA_IF</span>)<span># 定义模式为连接热点</span><br><span>ifconfig</span> <span>=</span> <span>wlan</span>.<span>ifconfig</span>() <span># 获取网络信息</span><br><span>font</span>.<span>text</span>(<span>display</span>, <span>'请在浏览器打开:'</span>, <span>0</span>, <span>0</span>, <span>show</span><span>=</span><span>True</span>,<span>clear</span><span>=</span><span>True</span>, <span>auto_wrap</span><span>=</span><span>True</span>)<br><span>font</span>.<span>text</span>(<span>display</span>, <span>str</span>(<span>'{}:5000'</span>.<span>format</span>(<span>ifconfig</span>[<span>0</span>])), <span>0</span>, <span>16</span>,<span>show</span><span>=</span><span>True</span>, <span>auto_wrap</span><span>=</span><span>True</span>) <span># 提示网页图传的对应网址</span><br><span>app</span> <span>=</span> <span>Microdot</span>() <span># 定义构建网站变量。</span><br><br><br><span># 初始化摄像头</span><br><span>cam</span> <span>=</span> <span>camera</span>.<span>init</span>(<span>0</span>, <span>d0</span><span>=</span><span>38</span>, <span>d1</span><span>=</span><span>47</span>, <span>d2</span><span>=</span><span>14</span>, <span>d3</span><span>=</span><span>13</span>, <span>d4</span><span>=</span><span>12</span>, <span>d5</span><span>=</span><span>11</span>, <span>d6</span><span>=</span><span>10</span>, <span>d7</span><span>=</span><span>9</span>,<br> <span>format</span><span>=</span><span>camera</span>.<span>JPEG</span>, <span>framesize</span><span>=</span><span>camera</span>.<span>FRAME_HVGA</span>,<span>fb_location</span><span>=</span><span>camera</span>.<span>PSRAM</span>,<br> <span>xclk_freq</span><span>=</span><span>camera</span>.<span>XCLK_20MHz</span>,<br> <span>href</span><span>=</span><span>18</span>, <span>vsync</span><span>=</span><span>17</span>, <span>reset</span><span>=</span><span>8</span>, <span>pwdn</span><span>=-</span><span>1</span>,<br> <span>sioc</span><span>=</span><span>16</span>, <span>siod</span><span>=</span><span>15</span>, <span>xclk</span><span>=</span><span>40</span>, <span>pclk</span><span>=</span><span>39</span>)<span>#y2-d0</span><br><span>#调整camera参数 </span><br><span>camera</span>.<span>brightness</span>(<span>2</span>)<br><span>camera</span>.<span>contrast</span>(<span>2</span>)<br><span>camera</span>.<span>quality</span>(<span>10</span>)<br><span>camera</span>.<span>speffect</span>(<span>camera</span>.<span>EFFECT_NONE</span>)<br><span>#camera.whitebalance(camera.WB_CLOUDY)</span><br><br><br><span># 定义网站html代码。</span><br><span>@app</span>.<span>route</span>(<span>'/'</span>)<br><span>def</span> <span>index</span>(<span>request</span>):<br> <span>return</span> <span>'''</span><br><span></span><br><span> </span><br><span> ESP32S3蓝牙小车网页图传</span><br><span> </span><br><span> </span><br><span> </span><br><span> <h1>ESP32S3蓝牙小车网页图传:</h1></span><br><span> <img src="//" width="100%"></span><br><span> </span><br><span>'''</span>, <span>200</span>, {<span>'Content-Type'</span>: <span>'text/html; charset=utf-8'</span>}<br><br><span># 网页图传</span><br><span>@app</span>.<span>route</span>(<span>'/video_feed'</span>)<br><span>def</span> <span>video_feed</span>(<span>request</span>):<br> <span>def</span> <span>stream</span>():<br> <span>yield</span> <span>b'--frame\r\n'</span><br> <span>while</span> <span>True</span>:<br> <span>frame</span> <span>=</span> <span>camera</span>.<span>capture</span>()<br> <span>yield</span> <span>b'Content-Type: image/jpeg\r\n\r\n'</span> <span>+</span> <span>frame</span> <span>+</span> \<br> <span>b'\r\n--frame\r\n'</span><br> <br><br> <span>return</span> <span>stream</span>(), <span>200</span>, {<span>'Content-Type'</span>:<br> <span>'multipart/x-mixed-replace; boundary=frame'</span>}<br><br><br><span>class</span> <span>ESP32_BLE</span>():<br> <span>#蓝牙初始化</span><br> <span>def</span> <span>__init__</span>(<span>self</span>, <span>name</span>):<br> <span>self</span>.<span>led</span> <span>=</span> <span>Pin</span>(<span>48</span>, <span>Pin</span>.<span>OUT</span>) <span>#配置LED灯引脚为输出模式</span><br> <span>self</span>.<span>timer1</span> <span>=</span> <span>Timer</span>(<span>0</span>) <span>#配置定时器</span><br> <span>self</span>.<span>name</span> <span>=</span> <span>name</span><br> <span>self</span>.<span>ble</span> <span>=</span> <span>bluetooth</span>.<span>BLE</span>() <span>#创建蓝牙对象</span><br> <span>self</span>.<span>ble</span>.<span>active</span>(<span>True</span>) <span>#开启蓝牙</span><br> <span>self</span>.<span>ble</span>.<span>config</span>(<span>gap_name</span><span>=</span><span>name</span>) <span>#配置蓝牙信息</span><br> <span>self</span>.<span>disconnected</span>() <span>#设置定时器中断</span><br> <span>self</span>.<span>ble</span>.<span>irq</span>(<span>self</span>.<span>ble_irq</span>) <span>#蓝牙时间处理</span><br> <span>self</span>.<span>register</span>() <span>#配置蓝牙的uuid</span><br> <span>self</span>.<span>ble</span>.<span>gatts_write</span>(<span>self</span>.<span>rx</span>, <span>bytes</span>(<span>100</span>))<span>#默认蓝牙只接收20字节,这里更改为接收100字节</span><br> <span>self</span>.<span>advertiser</span>() <span>#蓝牙广播</span><br> <span>self</span>.<span>ok</span> <span>=</span> <span>0</span><br><br> <span>#蓝牙连接,关闭LED灯</span><br> <span>def</span> <span>connected</span>(<span>self</span>):<br> <span>self</span>.<span>timer1</span>.<span>deinit</span>()<br> <span>self</span>.<span>led</span>.<span>value</span>(<span>0</span>)<br> <span>print</span>(<span>"connected ok"</span>)<br><br> <span>#蓝牙未连接,LED闪烁</span><br> <span>def</span> <span>disconnected</span>(<span>self</span>): <br> <span>self</span>.<span>timer1</span>.<span>init</span>(<span>period</span><span>=</span><span>100</span>, <span>mode</span><span>=</span><span>Timer</span>.<span>PERIODIC</span>, <span>callback</span><span>=</span><span>lambda</span> <span>t</span>: <span>self</span>.<span>led</span>.<span>value</span>(<span>not</span> <span>self</span>.<span>led</span>.<span>value</span>()))<br><br> <span>#蓝牙事件处理</span><br> <span>def</span> <span>ble_irq</span>(<span>self</span>, <span>event</span>, <span>data</span>):<br> <span>global</span> <span>BLE_MSG</span><br> <span>if</span> <span>event</span> <span>==</span> <span>1</span>: <span>#_IRQ_CENTRAL_CONNECT 手机连接了此设备</span><br> <span>self</span>.<span>connected</span>()<br> <span>elif</span> <span>event</span> <span>==</span> <span>2</span>: <span>#_IRQ_CENTRAL_DISCONNECT 手机断开此设备</span><br> <span>if</span> <span>self</span>.<span>ok</span><span>==</span><span>0</span>:<br> <span>self</span>.<span>advertiser</span>()<br> <span>self</span>.<span>disconnected</span>()<br> <span>elif</span> <span>event</span> <span>==</span> <span>3</span>: <span>#_IRQ_GATTS_WRITE 手机发送了数据 </span><br> <span>buffer</span> <span>=</span> <span>self</span>.<span>ble</span>.<span>gatts_read</span>(<span>self</span>.<span>rx</span>)<br> <span>BLE_MSG</span> <span>=</span> <span>buffer</span>.<span>decode</span>(<span>'UTF-8'</span>).<span>strip</span>()<br> <br> <span>#蓝牙UUID配置</span><br> <span>def</span> <span>register</span>(<span>self</span>): <br> <span>service_uuid</span> <span>=</span> <span>'6E400001-B5A3-F393-E0A9-E50E24DCCA9E'</span><br> <span>reader_uuid</span> <span>=</span> <span>'6E400002-B5A3-F393-E0A9-E50E24DCCA9E'</span><br> <span>sender_uuid</span> <span>=</span> <span>'6E400003-B5A3-F393-E0A9-E50E24DCCA9E'</span><br><br> <span>services</span> <span>=</span> (<br> (<br> <span>bluetooth</span>.<span>UUID</span>(<span>service_uuid</span>), <br> (<br> (<span>bluetooth</span>.<span>UUID</span>(<span>sender_uuid</span>), <span>bluetooth</span>.<span>FLAG_NOTIFY</span>), <br> (<span>bluetooth</span>.<span>UUID</span>(<span>reader_uuid</span>), <span>bluetooth</span>.<span>FLAG_WRITE</span>),<br> )<br> ), <br> )<br><br> ((<span>self</span>.<span>tx</span>, <span>self</span>.<span>rx</span>,), ) <span>=</span> <span>self</span>.<span>ble</span>.<span>gatts_register_services</span>(<span>services</span>)<br><br><br> <span>#蓝牙广播配置</span><br> <span>def</span> <span>advertiser</span>(<span>self</span>):<br> <span>name</span> <span>=</span> <span>bytes</span>(<span>self</span>.<span>name</span>, <span>'UTF-8'</span>)<br> <span>adv_data</span> <span>=</span> <span>bytearray</span>(<span>b'\x02\x01\x02'</span>) <span>+</span> <span>bytearray</span>((<span>len</span>(<span>name</span>) <span>+</span> <span>1</span>, <span>0x09</span>)) <span>+</span> <span>name</span><br> <span>self</span>.<span>ble</span>.<span>gap_advertise</span>(<span>100</span>, <span>adv_data</span>)<br> <span>print</span>(<span>"等待连接:%s"</span> <span>%</span> <span>adv_data</span>)<br> <span>print</span>(<span>"\r\n"</span>)<br> <br> <br><span>'''定义线程1网页图传函数'''</span><br><span>def</span> <span>main_cam</span>(<span>*</span><span>args</span>, <span>**</span><span>kwargs</span>):<br> <span>app</span>.<span>run</span>(<span>debug</span><span>=</span><span>True</span>)<span>#启动网页,并执行前面的网页图传相关函数</span><br> <br><br><span>'''定义线程2蓝牙小车函数'''</span><br><span>def</span> <span>main_car</span>(<span>*</span><span>args</span>, <span>**</span><span>kwargs</span>):<br> <span>global</span> <span>BLE_MSG</span>,<span>e</span><br> <br> <span>try</span>:<br> <span># 车先待命</span><br> <span>carstop</span>() <br> <br> <span># 配置蓝牙</span><br> <span>ble</span> <span>=</span> <span>ESP32_BLE</span>(<span>"ESP32S3BLE"</span>)<br><br> <span># 配置LED</span><br> <span>led</span> <span>=</span> <span>Pin</span>(<span>48</span>, <span>Pin</span>.<span>OUT</span>)<br> <br><br><span> </span><span>while</span> <span>True</span>:<br> <span>if</span> <span>len</span>(<span>BLE_MSG</span>)<span>></span><span>0</span>:<br> <span>if</span> <span>BLE_MSG</span> <span>in</span> [<span>"!B507"</span>,<span>"!B606"</span>,<span>"!B705"</span>,<span>"!B804"</span>,<span>"!B10;"</span>,<span>"!B20:"</span>,<span>"!B309"</span>,<span>"!B408"</span>,<span>"stop"</span>]: <span>#松开按键停止</span><br> <span>print</span>(<span>">>%s<<————停止"</span> <span>%</span> <span>BLE_MSG</span>)<br> <span>carstop</span>()<br> <span>elif</span> <span>BLE_MSG</span> <span>in</span> [<span>"!B516"</span>,<span>"upup"</span>]: <span># 按下小程序的上键向前</span><br> <span>print</span>(<span>">>%s<<————向前"</span> <span>%</span> <span>BLE_MSG</span>)<br> <span>cargo</span>()<br> <span>elif</span> <span>BLE_MSG</span> <span>in</span> [<span>"!B615"</span>,<span>"down"</span>]: <span># 按下小程序的下键向后</span><br> <span>print</span>(<span>">>%s<<————向后"</span> <span>%</span> <span>BLE_MSG</span>)<br> <span>carback</span>()<br> <span>elif</span> <span>BLE_MSG</span> <span>in</span> [<span>"!B714"</span>,<span>"left"</span>]: <span># 按下小程序的左键向左运动</span><br> <span>print</span>(<span>">>%s<<————向左"</span> <span>%</span> <span>BLE_MSG</span>)<br> <span>carleft</span>()<br> <span>elif</span> <span>BLE_MSG</span> <span>in</span> [<span>"!B813"</span>,<span>"right"</span>]: <span># 按下小程序的右键向右运动</span><br> <span>print</span>(<span>">>%s<<————向右"</span> <span>%</span> <span>BLE_MSG</span>)<br> <span>carright</span>()<br> <span>elif</span> <span>BLE_MSG</span> <span>in</span> [<span>"!B11:"</span>,<span>"act1"</span>]: <span># 按下小程序的A键拍照</span><br> <span>print</span>(<span>">>%s<<————拍照"</span> <span>%</span> <span>BLE_MSG</span>)<br> <span>take_picture</span>()<br> <span>BLE_MSG</span> <span>=</span> <span>""</span><br> <span>sleep_ms</span>(<span>100</span>)<br> <br> <span>except</span> <span>KeyboardInterrupt</span>:<br> <span>pass</span><br><br><span>'''定义主函数'''</span><br><span>def</span> <span>main</span>():<br> <span>thread_1</span> <span>=</span> <span>_thread</span>.<span>start_new_thread</span>(<span>main_cam</span>, (<span>None</span>,)) <span>#定义线程1</span><br> <span>thread_2</span> <span>=</span> <span>_thread</span>.<span>start_new_thread</span>(<span>main_car</span>, (<span>None</span>,)) <span>#定义线程2</span><br> <br><br><span>'''运行'''</span><br><span>if</span> <span>__name__</span> <span>==</span> <span>"__main__"</span>: <br> <span>try</span>: <br> <span>main</span>()<br> <span>except</span> <span>KeyboardInterrupt</span>: <span>#当出现KeyboardInterrupt异常</span><br> <span>camera</span>.<span>deinit</span>() <span>#释放摄像头避免运行第二次出先错误提示</span><br> <span>print</span>(<span>"ok"</span>)<br> <br></pre>
<p><span>相关驱动(microdot、ssd1306、ufont)详见附件。</span></p>
<p><span>小车遥控和摄像效果详见视频。</span></p>
<p style="line-height:1.8"> </p>
<p style="line-height:1.8"><span style="color:#95a5a6;font-size:14px">注:若您的项目涉及软件开发,请在附件上传对应的工程源码。这里可以详细说明您的软件流程图、功能模块框图、相关算法的解释或科普、源码结构、编译环境的搭建和配置、源码编译方法、程序烧录方法等。推荐图文并茂的形式向别人介绍您的想法。</span></p>
<p style="line-height:1.8"> </p>
<h3 style="line-height:1.8">*6、BOM清单</h3>
<hr>
<p style="line-height:1.8"><span style="color:#95a5a6;font-size:14px"><img src="//image.lceda.cn/pullimage/8P7cdOYScmVu0Zoin8fCkFlH23D42s9w4I16LqJC.png" alt="" width="800" height="354"></span></p>
<p style="line-height:1.8">自己统计的费用表:</p>
<p style="line-height:1.8"><img src="//image.lceda.cn/pullimage/0ND8IJR6B644clBPCtYzldEM5XcunSqet0CyDaET.png" alt="" width="600" height="288"></p>
<p style="line-height:1.8"><span style="color:#95a5a6;font-size:14px">注:项目涉及的BOM清单。在<span style="text-decoration:underline"><a href="https://lceda.cn/editor" target="_blank">嘉立创EDA</a> </span>生成/上传设计文件后,BOM将自动生成至项目详情;建议包括型号、品牌、名称、封装、采购渠道、用途等内容。具体内容和形式应以表达清楚项目构成为准。 </span></p>
<p style="line-height:1.8"> </p>
<h3 style="line-height:1.8">*7、大赛LOGO验证</h3>
<hr>
<p style="line-height:1.8"><img src="//image.lceda.cn/pullimage/6k4NXb10qYe2e4tOQhKVo7lulQxSkKyl4UgOHHRI.jpeg" alt="" width="600" height="559"><img src="//image.lceda.cn/pullimage/18pL3TGldCgxFgNGhe9HL5catLKZYQb8KsmflHMV.jpeg" alt="" width="600" height="451"></p>
<p style="line-height:1.8"> </p>
<h3 style="line-height:1.8">* 8、演示您的项目并录制成视频上传</h3>
<hr>
<p style="line-height:1.8"><span>ESP32S3摄像遥控小车具有地面移动摄像的功能,能用于开展农业作物观察、动植物观察、危险区域或无人区域探险、狭窄区域搜索、科学研究等活动。比如我们就尝试开展了农田作物生长情况观察(详见视频)、寻找躲在床底下的猫猫(详见下图)、乐高城探险等应用测试(详见视频)。</span></p>
<p style="line-height:1.8"><span><span><img src="//image.lceda.cn/pullimage/NZ4uFQH9ZDLcoynLQk7IopVRFyA8zGJpvFB84UsR.jpeg" alt="" width="400" height="889"></span></span></p>
<p style="line-height:1.8"> </p>
<p style="line-height:1.8"><span style="font-size:14px"><a href="/posts/de460543d4cf4dacb5f0326612455578" target="_blank">前往查看更多详情 ></a></span></p>
<p style="line-height:1.8"> </p>
</div>
评论(1)