xinmeng_wit 发表于 2022-5-15 21:32

【平头哥RVB2601创意应用开发】网络天气时钟

本帖最后由 xinmeng_wit 于 2022-5-15 21:56 编辑

<p align="center" style="text-align:center"><span style="font-size:10.5pt"><span style="font-family:&quot;Times New Roman&quot;"><b><span class="16" style="font-size:16.0000pt"><span style="font-family:微软雅黑"><span style="font-weight:bold"><font face="微软雅黑">网络天气时钟</font></span></span></span></b></span></span></p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p align="right" style="text-align:right"><span style="font-size:10.5pt"><span style="font-family:&quot;Times New Roman&quot;"><b><span style="font-size:16.0000pt"><span style="font-family:微软雅黑"><span style="font-weight:bold"><font face="微软雅黑">作者:</font></span></span></span></b><b><span style="font-size:16.0000pt"><span style="font-family:微软雅黑"><span style="font-weight:bold">xinmeng_wit</span></span></span></b></span></span></p>

<p>&nbsp;</p>

<ul>
        <li style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:&quot;Times New Roman&quot;"><b><span style="font-size:16.0000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="font-weight:bold"><font face="微软雅黑">项目背景</font></span></span></span></span></b></span></span></li>
</ul>

<p style="text-indent:21.0000pt; text-align:justify"><span style="font-size:16px;"><strong><span style="font-family:&quot;Times New Roman&quot;"><span style="font-family:宋体">RVB2601<font face="宋体">开发板板上外设资源除了基本的</font><font face="Times New Roman">led</font><font face="宋体">,按键,</font><font face="Times New Roman">OLED</font><font face="宋体">之外,还有音频输入输出和</font><font face="Times New Roman">WiFi</font><font face="宋体">功能。有了</font><font face="Times New Roman">WiFi</font><font face="宋体">的加持,使这款开发板很容易开发联网类的应用。由此想到了之前一直想做但是没有做的桌面天气摆件&mdash;&mdash;网络天气时钟。用</font><font face="Times New Roman">RVB2601</font><font face="宋体">开发板来实现网络天气时钟其实是非常合适的,毕竟不用外接</font><font face="Times New Roman">WiFi</font><font face="宋体">模块,省掉了外部接线的麻烦,基本不用外接任何器件就能实现功能。</font></span></span></strong></span></p>

<ul>
        <li style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:&quot;Times New Roman&quot;"><b><span class="15" style="font-size:16.0000pt"><span style="font-family:微软雅黑"><span style="font-weight:bold"><font face="微软雅黑">作品简介</font></span></span></span></b></span></span></li>
</ul>

<p style="text-indent:21.0000pt; text-align:justify"><span style="font-size:16px;"><strong><span style="font-family:&quot;Times New Roman&quot;"><span style="font-family:宋体"><font face="宋体">本作品的定位是桌面电子小摆件,主要功能是显示日历、实时时间、实时天气和未来天气。上电自动联网对时,无需手动调节,上电默认显示实时时间,可以通过板载的两个按键进行时间与天气的的切换(单击</font>KEY2<font face="宋体">进行上翻页,单击</font><font face="Times New Roman">KEY1</font><font face="宋体">进行下翻页)。另外,作品还支持城市的设置,长按</font><font face="Times New Roman">KEY1</font><font face="宋体">进入设置页面,使用单击</font><font face="Times New Roman">KEY1,KEY2</font><font face="宋体">进行光标移动,选择好城市以后长按</font><font face="Times New Roman">KEY2</font><font face="宋体">确定,自动退出设置页面回到正常页面。板载</font><font face="Times New Roman">RGB</font><font face="宋体">灯红绿蓝交替闪烁指示程序的运行。</font></span></span></strong></span></p>

<p>&nbsp;</p>

<p style="text-indent:21.0000pt; text-align:justify"></p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p style="text-indent:21.0000pt; text-align:justify"></p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p style="text-indent:21.0000pt; text-align:justify"></p>

<ul><br />
        <li style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:&quot;Times New Roman&quot;"><b><span class="15" style="font-size:16.0000pt"><span style="font-family:微软雅黑"><span style="font-weight:bold"><font face="微软雅黑">系统框图</font></span></span></span></b></span></span></li>
</ul>

<p style="text-indent:21.0000pt; text-align:justify"><span style="font-size:16px;"><strong><span style="font-family:&quot;Times New Roman&quot;"><span style="font-family:宋体"><font face="宋体">本作品全部使用板载资源,主控为</font>CH2601<font face="宋体">,</font><font face="Times New Roman">WiFi</font><font face="宋体">芯片</font><font face="Times New Roman">w800</font><font face="宋体">与主控之间采用</font><font face="Times New Roman">SPI</font><font face="宋体">进行通讯;显示部分与主控之间也是通过</font><font face="Times New Roman">SPI</font><font face="宋体">的方式进行通讯;剩下的</font><font face="Times New Roman">led</font><font face="宋体">和按键直接就是</font><font face="Times New Roman">GPIO</font><font face="宋体">驱动。</font></span></span></strong></span></p>

<p>&nbsp;</p>

<p style="text-indent:21.0000pt; text-align:justify"></p>

<p>&nbsp;</p>

<ul><br />
        <li style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:&quot;Times New Roman&quot;"><b><span class="15" style="font-size:16.0000pt"><span style="font-family:微软雅黑"><span style="font-weight:bold"><font face="微软雅黑">各部分功能说明</font></span></span></span></b><b><span class="15" style="font-size:16.0000pt"><span style="font-family:微软雅黑"><span style="font-weight:bold"><font face="微软雅黑">和解析</font></span></span></span></b></span></span></li>
</ul>

<p style="text-align:justify"><span style="font-size:16px;"><strong><span style="font-family:&quot;Times New Roman&quot;"><span style="font-family:宋体"><font face="宋体">总体上功能并不复杂,总结下来主要分为如下几个部分:</font></span></span></strong></span></p>

<ol><br />
        <li style="text-align:justify"><span style="font-size:16px;"><strong><span style="font-family:&quot;Times New Roman&quot;"><span style="font-family:宋体">Wifi<font face="宋体">通讯部分</font></span></span></strong></span></li>
</ol>

<p align="justify" style="text-indent:21.0000pt; text-align:justify"><span style="font-size:16px;"><strong><span style="font-family:&quot;Times New Roman&quot;"><span style="font-family:宋体">Wifi<font face="宋体">通讯部分主要负责网络连接、</font><font face="Times New Roman">NTP</font><font face="宋体">对时和天气消息的获取,在软件里面是单独的一个</font><font face="Times New Roman">task</font><font face="宋体">,专门负责处理网络相关的任务。该</font><font face="Times New Roman">task</font><font face="宋体">有几个比较重要的模块:按键检测和天气数据的获取</font><font face="Times New Roman">/</font><font face="宋体">解析</font><font face="Times New Roman">/</font><font face="宋体">发送。</font></span></span></strong></span></p>

<p align="justify" style="text-indent:21.0000pt; text-align:justify"><span style="font-size:16px;"><strong><span style="font-family:&quot;Times New Roman&quot;"><span style="font-family:宋体"><font face="宋体">按键的检测移植了开源库</font>Multi Button<font face="宋体">,注册了板载两个按键的单击和长按事件。单击实现上下翻页,长按实现进入设置和退出设置。</font></span></span></strong></span></p>

<p>&nbsp;</p>

<p align="justify" style="text-indent:21.0000pt; text-align:justify"><span style="font-size:16px;"><strong><span style="font-family:&quot;Times New Roman&quot;"><span style="font-family:宋体"><font face="宋体">天气数据的解析,使用了到了开源库</font>cJSON<font face="宋体">,使用</font><font face="Times New Roman">cJSON</font><font face="宋体">库确实会带来很大的方便,但同时会带来</font><font face="Times New Roman">RAM</font><font face="宋体">的开销,对于</font><font face="Times New Roman">RAM</font><font face="宋体">不是很够的</font><font face="Times New Roman">MCU</font><font face="宋体">不建议使用。天气数据的处理,主要包含几个函数:</font></span></span></strong></span></p>

<p align="justify" style="text-indent:21.0000pt; text-align:justify"></p>

<p>&nbsp;</p>

<p align="justify" style="text-indent:21.0000pt; text-align:justify"></p>

<p>&nbsp;</p>

<p style="text-align:justify"><span style="font-size:16px;"><strong><span style="font-family:&quot;Times New Roman&quot;"><span style="font-family:宋体">2、OLED<font face="宋体">显示部分</font></span></span></strong></span></p>

<p align="justify" style="text-indent:21.0000pt; text-align:justify"><span style="font-size:16px;"><strong><span style="font-family:&quot;Times New Roman&quot;"><span style="font-family:宋体"><font face="宋体">显示部分也是单独的</font>task<font face="宋体">,只负责显示,不参与任何检测和控制。显示部分通过消息队列接收消息进行显示。</font></span></span></strong></span></p>

<p align="justify" style="text-indent:21.0000pt; text-align:justify"></p>

<p>&nbsp;</p>

<p align="justify" style="text-indent:21.0000pt; text-align:justify"><span style="font-size:16px;"><strong><span style="font-family:&quot;Times New Roman&quot;"><span style="font-family:宋体"><font face="宋体">另外,为了能够显示比较复杂的内容或者图形等,移植了</font>GUI<font face="宋体">开源库</font><font face="Times New Roman">u8g2</font><font face="宋体">,</font><font face="Times New Roman">u8g2</font><font face="宋体">内置很多的字符和图形接口,直接调用,非常方便,而且还支持中文的显示,但是中文的显示并不支持所有汉字,所以如果要显示汉字还需要制作汉字库。汉字库的制作方法可以参考网站上其它网友的方法,不在这篇讨论的范围内。</font></span></span></strong></span></p>

<p align="justify" style="text-indent:21.0000pt; text-align:justify"><span style="font-size:16px;"><strong><span style="font-family:&quot;Times New Roman&quot;"><span style="font-family:宋体"><font face="宋体">为了能够一目了然地显示天气状态,特意制作了十几种天气图标,这些图标都做成统一大小(</font>48*48<font face="宋体">)的位图,并用工具取模保存为数组,显示的时候根据天气状态调用对应的图标。</font></span></span></strong></span></p>

<p align="justify" style="text-indent:21.0000pt; text-align:justify"><span style="font-size:16px;"><strong><span style="font-family:&quot;Times New Roman&quot;"><span style="font-family:宋体"><font face="宋体">天气中文的显示与图标一样通过数组偏移量的方法来匹配:</font></span></span></strong></span></p>

<p align="justify" style="text-indent:21.0000pt; text-align:justify"></p>

<p>&nbsp;</p>

<p style="text-align:justify"><span style="font-size:16px;"><strong><span style="font-family:&quot;Times New Roman&quot;"><span style="font-family:宋体">3、Led<font face="宋体">和</font><font face="Times New Roman">RTC</font><font face="宋体">部分</font></span></span></strong></span></p>

<p align="justify" style="text-indent:21.0000pt; text-align:justify"><span style="font-size:16px;"><strong><span style="font-family:&quot;Times New Roman&quot;"><span style="font-family:宋体">led<font face="宋体">的显示是在天气</font><font face="Times New Roman">task</font><font face="宋体">里面附带做的,红绿蓝交替亮灭,间隔时间为</font><font face="Times New Roman">1s</font><font face="宋体">。</font></span></span></strong></span></p>

<p align="justify" style="text-indent:21.0000pt; text-align:justify"><span style="font-size:16px;"><strong><span style="font-family:&quot;Times New Roman&quot;"><span style="font-family:宋体">RTC<font face="宋体">的获取和显示的任务是在</font><font face="Times New Roman">AOS</font><font face="宋体">软件定时器回调函数里面做的,软件定时器的周期是</font><font face="Times New Roman">1s</font><font face="宋体">,也就是每一秒取一次硬件</font><font face="Times New Roman">RTC</font><font face="宋体">的数据然后显示。</font></span></span></strong></span></p>

<p align="justify" style="text-indent:21.0000pt; text-align:justify"></p>

<p style="text-align:justify"><span style="font-size:16px;"><strong><span style="font-family:&quot;Times New Roman&quot;"><span style="font-family:宋体"><font face="宋体">4、按键处理部分</font></span></span></strong></span></p>

<p align="justify" style="text-align:justify"><span style="font-size:16px;"><strong><span style="font-family:&quot;Times New Roman&quot;"><span style="font-family:宋体"><font face="宋体">按键部分是个回调事件已在上面介绍过了,这里不再赘述。</font></span></span></strong></span></p>

<ul><br />
        <li style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:&quot;Times New Roman&quot;"><b><span class="15" style="font-size:16.0000pt"><span style="font-family:微软雅黑"><span style="font-weight:bold"><font face="微软雅黑">作品源码</font></span></span></span></b></span></span></li>
</ul>

<p style="text-align:justify"><span style="font-size:16px;"><strong>源代码:<a href="https://download.eeworld.com.cn/detail/xinmeng_wit/623572" target="_blank">https://download.eeworld.com.cn/detail/xinmeng_wit/623572</a></strong></span></p>

<p style="text-align:justify">&nbsp;</p>

<p align="justify" style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:&quot;Times New Roman&quot;"><b><span style="font-size:16.0000pt"><span style="font-family:微软雅黑"><span style="font-weight:bold"><font face="微软雅黑">视频</font></span></span></span></b><b><span class="15" style="font-size:16.0000pt"><span style="font-family:微软雅黑"><span style="font-weight:bold"><font face="微软雅黑">演示</font></span></span></span></b></span></span></p>

<p align="justify" style="text-align:justify"><iframe allowfullscreen="true" frameborder="0" height="450" src="//player.bilibili.com/player.html?bvid=1U34y177Lw&amp;page=1" style="background:#eee;margin-bottom:10px;" width="700"><br />
</iframe></p>

<ul><br />
        <li style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:&quot;Times New Roman&quot;"><b><span style="font-size:16.0000pt"><span style="font-family:微软雅黑"><span style="font-weight:bold"><font face="微软雅黑">项目总结</font></span></span></span></b></span></span></li>
</ul>

<p style="text-indent:21.0000pt; text-align:justify"><span style="font-size:16px;"><strong><span style="font-family:&quot;Times New Roman&quot;"><span style="font-family:宋体"><font face="宋体">首次使用平头哥的芯片和开发板,收获颇多。在这个项目中,了解和学习了</font>AOS<font face="宋体">,知道了什么是</font><font face="Times New Roman">yoc</font><font face="宋体">,熟悉了平头哥芯片的开发环境和开发流程。</font></span></span></strong></span></p>

<p style="text-indent:21.0000pt; text-align:justify"><span style="font-size:16px;"><strong><span style="font-family:&quot;Times New Roman&quot;"><span style="font-family:宋体"><font face="宋体">对于项目本身,完成了基本功能,实现了时间日期的显示,实时天气的显示,未来天气的显示,城市的设置。但是,还有一些功能由于某些原因未能在本次项目中实现。</font></span></span></strong></span></p>

<p style="text-indent:21.0000pt; text-align:justify"><span style="font-size:16px;"><strong><span style="font-family:&quot;Times New Roman&quot;"><span style="font-family:宋体">RVB2601<font face="宋体">的硬件资源其实还是比较可以的,包括了网络和音频,可以开发出很多有创意的产品,但是也有一些小小的不足,总结下来主要有如下几点:</font></span></span></strong></span></p>

<ol><br />
        <li style="text-align:justify"><span style="font-size:16px;"><strong><span style="font-family:&quot;Times New Roman&quot;"><span style="font-family:宋体"><font face="宋体">开发板缺乏配套的文档,只能通过有限的几个例程取学习摸索,新手使用有点难度,上手时间长;</font></span></span></strong></span></li>
        <br />
        <li style="text-align:justify"><span style="font-size:16px;"><strong><span style="font-family:&quot;Times New Roman&quot;"><span style="font-family:宋体"><font face="宋体">发布的软件包有很明显的问题,</font>NTP<font face="宋体">的问题应该很多小伙伴都遇到了;</font></span></span></strong></span></li>
        <br />
        <li style="text-align:justify"><span style="font-size:16px;"><strong><span style="font-family:&quot;Times New Roman&quot;"><span style="font-family:宋体">CH2601<font face="宋体">芯片本身</font><font face="Times New Roman">ram</font><font face="宋体">不够大,开发一些比较复杂的应用就会比较困难;</font></span></span></strong></span></li>
        <br />
        <li style="text-align:justify"><span style="font-size:16px;"><strong><span style="font-family:&quot;Times New Roman&quot;"><span style="font-family:宋体"><font face="宋体">开发工具</font>CDK<font face="宋体">不能准确定位错误的位置,导致查找错误会花很长的时间;</font></span></span></strong></span></li>
        <br />
        <li style="text-align:justify"><span style="font-size:16px;"><strong><span style="font-family:&quot;Times New Roman&quot;"><span style="font-family:宋体"><font face="宋体">没有板载</font>SD<font face="宋体">卡</font><font face="Times New Roman">/USB</font><font face="宋体">接口,有点遗憾。</font></span></span></strong></span></li>
</ol>

<p align="justify" style="text-indent:21.0000pt; text-align:justify"><span style="font-size:16px;"><strong><span style="font-family:&quot;Times New Roman&quot;"><span style="font-family:宋体"><font face="宋体">最后,再次感谢平头哥和</font>EEWORLD<font face="宋体">提供这次机会,期待平头哥继续完善生态,发布更好的产品。</font></span></span></strong></span></p>

<p align="justify" style="text-indent:21.0000pt; text-align:justify">&nbsp;</p>

<p align="justify" style="text-indent:21.0000pt; text-align:justify"><span style="font-size:16px;"><strong><span style="font-family:&quot;Times New Roman&quot;"><span style="font-family:宋体"><font face="宋体">帖子链接:</font></span></span></strong></span></p>

<ol><br />
        <li style="text-align:justify"><span style="font-size:16px;"><strong><span style="font-family:&quot;Times New Roman&quot;"><span style="font-family:'Times New Roman'"><font face="宋体">开箱</font>&amp;<font face="宋体">运行</font><font face="Times New Roman">Helloworld</font><font face="宋体">例程</font></span></span></strong></span></li>
</ol>

<p align="justify" style="text-indent:21.0000pt; text-align:justify"><span style="font-size:16px;"><strong><span style="font-family:&quot;Times New Roman&quot;"><a href="https://bbs.eeworld.com.cn/thread-1194780-1-1.html"><u><span class="15" style="font-family:宋体"><span style="color:#0000ff"><span style="text-decoration:underline">https://bbs.eeworld.com.cn/thread-1194780-1-1.html</span></span></span></u></a></span></strong></span></p>

<ol start="2"><br />
        <li style="text-align:justify"><span style="font-size:16px;"><strong><span style="font-family:&quot;Times New Roman&quot;"><span style="font-family:'Times New Roman'"><font face="宋体">板载</font>RGB<font face="宋体">灯控制</font></span></span></strong></span></li>
</ol>

<p align="justify" style="text-indent:21.0000pt; text-align:justify"><span style="font-size:16px;"><strong><span style="font-family:&quot;Times New Roman&quot;"><a href="https://bbs.eeworld.com.cn/thread-1195852-1-1.html"><u><span class="15" style="font-family:宋体"><span style="color:#0000ff"><span style="text-decoration:underline">https://bbs.eeworld.com.cn/thread-1195852-1-1.html</span></span></span></u></a></span></strong></span></p>

<ol start="3"><br />
        <li align="justify" style="text-align:justify"><span style="font-size:16px;"><strong><span style="font-family:&quot;Times New Roman&quot;"><span style="font-family:宋体">wifi<font face="宋体">网络通信</font></span></span></strong></span></li>
</ol>

<p align="justify" style="text-indent:21.0000pt; text-align:justify"><span style="font-size:16px;"><strong><span style="font-family:&quot;Times New Roman&quot;"><a href="https://bbs.eeworld.com.cn/thread-1198791-1-1.html"><u><span class="15" style="font-family:'Times New Roman'"><span style="color:#0000ff"><span style="text-decoration:underline">https://bbs.eeworld.com.cn/thread-1198791-1-1.html</span></span></span></u></a></span></strong></span></p>

<ol start="4"><br />
        <li align="justify" style="text-align:justify"><span style="font-size:16px;"><strong><span style="font-family:&quot;Times New Roman&quot;"><span style="font-family:宋体">cJSON<font face="宋体">获取天气信息</font></span></span></strong></span></li>
</ol>

<p align="justify" style="text-indent:21.0000pt; text-align:justify"><span style="font-size:16px;"><strong><a href="https://bbs.eeworld.com.cn/thread-1199757-1-1.html" target="_blank"><span style="font-family:&quot;Times New Roman&quot;"><span style="font-family:宋体">https://bbs.eeworld.com.cn/thread-1199757-1-1.html</span></span></a></strong></span></p>

<ol start="5"><br />
        <li style="text-align:justify"><span style="font-size:16px;"><strong><span style="font-family:&quot;Times New Roman&quot;"><span style="font-family:宋体">OLED<font face="宋体">显示天气信息</font></span></span></strong></span></li>
</ol>

<p align="justify" style="text-indent:21.0000pt; text-align:justify"><span style="font-size:16px;"><strong><a href="https://bbs.eeworld.com.cn/thread-1200949-1-1.html" target="_blank"><span style="font-family:&quot;Times New Roman&quot;"><span style="font-family:宋体">https://bbs.eeworld.com.cn/thread-1200949-1-1.html</span></span></a></strong></span></p>

<ol start="6"><br />
        <li style="text-align:justify"><span style="font-size:16px;"><strong><span style="font-family:&quot;Times New Roman&quot;"><span style="font-family:宋体"><font face="宋体">网络天气时钟草版</font></span></span></strong></span></li>
</ol>

<p style="text-indent:21.0000pt; text-align:justify"><span style="font-size:16px;"><strong><a href="https://bbs.eeworld.com.cn/thread-1201832-1-1.html" target="_blank"><span style="font-family:&quot;Times New Roman&quot;"><span style="font-family:宋体">https://bbs.eeworld.com.cn/thread-1201832-1-1.html</span></span></a></strong></span></p>

<p style="text-indent:21.0000pt; text-align:justify">&nbsp;</p>

<p style="text-indent:21.0000pt; text-align:justify"></p>

<p>&nbsp;</p>

<p>&nbsp;</p>

云淡风轻12 发表于 2022-5-15 22:11

<p>论坛大神就是多。创意很好。不知道能不能使用普通led显示屏来做,那样的话,范围会更加的广泛。</p>

xinmeng_wit 发表于 2022-5-16 12:13

云淡风轻12 发表于 2022-5-15 22:11
论坛大神就是多。创意很好。不知道能不能使用普通led显示屏来做,那样的话,范围会更加的广泛。

<p>只要能显示就可以:lol</p>

freebsder 发表于 2022-5-18 20:28

<p>谢谢分享!</p>

梦溪开物 发表于 2022-5-29 10:41

<p><strong>AOS软件定时器是如何实现年、月、日、时、分和秒的获取的呢?</strong></p>

xinmeng_wit 发表于 2022-5-29 13:04

梦溪开物 发表于 2022-5-29 10:41
AOS软件定时器是如何实现年、月、日、时、分和秒的获取的呢?

<p>在AOS软件定时器中断里面取读取硬件RTC的数据,硬件RTC的数据是包含年月日时分秒的。</p>
页: [1]
查看完整版本: 【平头哥RVB2601创意应用开发】网络天气时钟