使用树莓派pico驱动NB-IoT模组,完成实验开发
<div class='showpostmsg'><p style="text-indent:21.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">在之前几次实验中,我们验证了从</font><font face="Calibri">NB-IoT</font><font face="宋体">模组的</font><font face="Calibri">UART1</font><font face="宋体">口读取和写入</font><font face="Calibri">AT</font><font face="宋体">指令,但事实上,我们更希望能够将这个环境小型化(越小越好),由于是准备和小朋友一起开发的,而且操作尽可能简单为好,于是在尝试了</font><font face="Calibri">Scratch</font><font face="宋体">、</font><font face="Calibri">Arduino</font><font face="宋体">之后,选择使用</font><font face="Calibri">micropython</font><font face="宋体">开发,支持的板卡也从</font><font face="Calibri">Arduino Nano</font><font face="宋体">、</font><font face="Calibri">STM32F103</font><font face="宋体">、</font><font face="Calibri">esp32</font><font face="宋体">、</font><font face="Calibri">microbit</font><font face="宋体">、树莓派</font><font face="Calibri">pico</font><font face="宋体">等等板卡中选出了树莓派</font><font face="Calibri">pico</font><font face="宋体">,树莓</font><font face="Calibri">pico</font><font face="宋体">采用了双核 </font><font face="Calibri">Arm Cortex-M0 + @ 133MHz RP2040</font><font face="宋体">,有两个</font><font face="Calibri">UART</font><font face="宋体">可供使用,这里使用</font><font face="Calibri">uart0</font><font face="宋体">。</font></span></span></span></span></p><p style="text-indent:21.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">温湿度环境监控从</font><font face="Calibri">AHT10</font><font face="宋体">和</font><font face="Calibri">DHT11</font><font face="宋体">中选择了</font><font face="Calibri">DHT11</font><font face="宋体">,</font></span></span><span style="font-size:10.5000pt"><span style="font-family:Calibri">DHT11<font face="宋体">是一款有已校准数字信号输出的温湿度传感器</font></span></span><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">,可以通过单线获得温湿度,且待校验功能。连接图如下:</font></span></span></span></span></p>
<p style="text-align:justify"> </p>
<p style="text-indent:21.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">照片比较难看出实际接线方式,就直接用示意图吧:</font></span></span></span></span></p>
<p style="text-align:justify"> </p>
<p style="text-indent:21.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">树莓派</font></span></span><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="Calibri">pico</font></span></span><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">通过</font></span></span><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="Calibri">A0</font><font face="宋体">(</font><font face="Calibri">GPIO26</font><font face="宋体">)读取</font><font face="Calibri">DHT11</font><font face="宋体">的数据,经过处理,通过</font><font face="Calibri">uart0</font><font face="宋体">发出</font><font face="Calibri">AT</font><font face="宋体">指令,让</font><font face="Calibri">NB-IoT</font><font face="宋体">模块使用</font><font face="Calibri">mqtt</font><font face="宋体">功能,同时采集回显,当等待</font><font face="Calibri">2</font><font face="宋体">秒没有收到“</font><font face="Calibri">OK</font><font face="宋体">”,则将该指令再重发一次(</font><font face="Calibri">NB-IoT</font><font face="宋体">发送</font><font face="Calibri">mqtt</font><font face="宋体">参考</font><font face="Calibri">https://bbs.eeworld.com.cn/thread-1190206-1-1.html</font><font face="宋体">,树莓派</font><font face="Calibri">pico</font><font face="宋体">读取</font><font face="Calibri">DHT11</font><font face="宋体">准备另开一文介绍)。</font></span></span></span></span></p>
<p style="text-indent:21.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">效果如下:</font></span></span></span></span></p>
<p style="text-align:justify"> </p>
<p style="text-indent:21.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">在</font></span></span><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="Calibri">/test</font><font face="宋体">主题下可以实时订阅此传感器获得的温湿度信息。</font></span></span></span></span></p>
<p style="text-indent:21.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">可以将文件</font><font face="Calibri">sendmqtt1.py</font><font face="宋体">更名为</font></span></span><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="Calibri">main.py</font><font face="宋体">,这样可以上电即运行。未来准备再增加</font><font face="Calibri">RTC</font><font face="宋体">功能,实现定时发送。</font></span></span></span></span></p>
<p style="text-indent:21.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">另外,基于</font><font face="Calibri">mqtt</font><font face="宋体">的订阅功能,做了一个界面,如下:</font></span></span></span></span></p>
<p style="text-align:justify"> </p>
<p style="text-indent:21.0000pt; text-align:justify"> </p>
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">树莓派</font><font face="Calibri">pico</font><font face="宋体">的</font><font face="Calibri">micropython</font><font face="宋体">支持:</font></span></span></span></span></p>
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="Calibri">Pico</font><font face="宋体">上运行的代码:</font></span></span></span></span></p>
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">电脑上运行的代码:</font></span></span></span></span></p>
</div><script> var loginstr = '<div class="locked">查看本帖全部内容,请<a href="javascript:;" style="color:#e60000" class="loginf">登录</a>或者<a href="https://bbs.eeworld.com.cn/member.php?mod=register_eeworld.php&action=wechat" style="color:#e60000" target="_blank">注册</a></div>';
if(parseInt(discuz_uid)==0){
(function($){
var postHeight = getTextHeight(400);
$(".showpostmsg").html($(".showpostmsg").html());
$(".showpostmsg").after(loginstr);
$(".showpostmsg").css({height:postHeight,overflow:"hidden"});
})(jQuery);
} </script><script type="text/javascript">(function(d,c){var a=d.createElement("script"),m=d.getElementsByTagName("script"),eewurl="//counter.eeworld.com.cn/pv/count/";a.src=eewurl+c;m.parentNode.insertBefore(a,m)})(document,523)</script> <p>可以发到micropython版块</p>
页:
[1]