玩转RP2040之结项报告
<div class='showpostmsg'><p cid="n82" mdtype="paragraph"> </p><p cid="n84" mdtype="paragraph"> </p>
<p cid="n85" mdtype="paragraph">RP2040前面的几篇测试报告:</p>
<p cid="n86" mdtype="paragraph"><a href="https://bbs.eeworld.com.cn/thread-1225624-1-1.html" spellcheck="false">1 玩转RP2040之开箱测评与上电运行</a></p>
<p cid="n87" mdtype="paragraph"><a href="https://bbs.eeworld.com.cn/thread-1226513-1-1.html" spellcheck="false">2 玩转RP2040之Python开发环境搭建</a></p>
<p cid="n88" mdtype="paragraph"><a href="https://bbs.eeworld.com.cn/thread-1226547-1-1.html" spellcheck="false">3 玩转RP2040之LCD绘制基本形状测试</a></p>
<p cid="n89" mdtype="paragraph"><a href="https://bbs.eeworld.com.cn/thread-1227388-1-1.html" spellcheck="false">4 玩转RP2040之使用Python在LCD上显示图片</a></p>
<p cid="n90" mdtype="paragraph"><a href="https://bbs.eeworld.com.cn/thread-1227390-1-1.html" spellcheck="false">5 玩转RP2040之使用Python在LCD上显示多类型字体</a></p>
<p cid="n91" mdtype="paragraph"><a href="https://bbs.eeworld.com.cn/thread-1228124-1-1.html" spellcheck="false">6 玩转RP2040之设计一个表盘</a></p>
<p cid="n92" mdtype="paragraph"> </p>
<p cid="n93" mdtype="paragraph">本篇实现一个综合的功能:</p>
<ul cid="n94" data-mark="-" mdtype="list">
<li cid="n95" mdtype="list_item">
<p cid="n96" mdtype="paragraph">利用LCD显示一个运动表盘</p>
</li>
<li cid="n97" mdtype="list_item">
<p cid="n98" mdtype="paragraph">利用LCD显示运动手表中的其它功能显示,如天气信息、打开支付宝等</p>
</li>
<li cid="n99" mdtype="list_item">
<p cid="n100" mdtype="paragraph">利用IMU判断板子的翻转,实现表盘中功能的切换</p>
</li>
</ul>
<h1 cid="n101" mdtype="heading">程序编写</h1>
<p cid="n102" mdtype="paragraph">一些定义</p>
<pre cid="n103" lang="python" mdtype="fences" spellcheck="false">
<code>import time
from machine import Pin, SPI
import gc9a01
import myimu
from prop_font import chango_16
from prop_font import chango_32
from prop_font import chango_64
from mono_font import inconsolata_16
from mono_font import inconsolata_32
from mono_font import inconsolata_64
import NotoSans_32
import NotoSerif_32
import NotoSansMono_32
import vga1_bold_16x16
DC = 8
CS = 9
SCK = 10
MOSI = 11
RST = 12
BL = 25</code></pre>
<p cid="n104" mdtype="paragraph">表盘显示功能封装为一个类</p>
<pre cid="n105" lang="python" mdtype="fences" spellcheck="false">
<code>class WatchPanel:
def init(self):
self.spi = SPI(1, baudrate=60000000, sck=Pin(SCK), mosi=Pin(MOSI))
self.tft = gc9a01.GC9A01(
self.spi,
240,
240,
reset=Pin(RST, Pin.OUT),
cs=Pin(CS, Pin.OUT),
dc=Pin(DC, Pin.OUT),
backlight=Pin(BL, Pin.OUT),
rotation=0)
#时分秒
self.hour = 22
self.minute = 08
self.second = 55
self.last_hour = -1
self.last_minute = -1
self.last_second = -1
# enable display and clear screen
self.tft.init()
def display_inconsolata_font(self, font, data, column, row):
for char in data:
self.tft.bitmap(font, column, row, font.MAP.index(char))
column += font.WIDTH
def show_static_info(self):
#蓝牙
bl_x = 70
bl_y = 17
self.tft.vline(bl_x, bl_y, 20, gc9a01.BLUE)
self.tft.line(bl_x - 5, bl_y + 3, bl_x + 5, bl_y + 20 - 6, gc9a01.BLUE)
self.tft.line(bl_x - 5, bl_y + 20 - 3, bl_x + 5, bl_y + 6, gc9a01.BLUE)
self.tft.line(bl_x, bl_y, bl_x + 5, bl_y + 6, gc9a01.BLUE)
self.tft.line(bl_x, bl_y + 20, bl_x + 5, bl_y + 20 - 6, gc9a01.BLUE)
#电量
self.tft.text(vga1_bold_16x16, "80%", 95, 20, gc9a01.CYAN)
bat_x = 145
bat_y = 20
bat_w = 30
bat_h = 15
self.tft.hline(bat_x, bat_y, bat_w, gc9a01.WHITE)
self.tft.hline(bat_x, bat_y + bat_h, bat_w, gc9a01.WHITE)
self.tft.vline(bat_x, bat_y, bat_h, gc9a01.WHITE)
self.tft.vline(bat_x + bat_w, bat_y, bat_h, gc9a01.WHITE)
self.tft.vline(bat_x + bat_w + 1, bat_y + 2, bat_h - 4, gc9a01.WHITE)
self.tft.vline(bat_x + bat_w + 2, bat_y + 2, bat_h - 4, gc9a01.WHITE)
self.tft.fill_rect(bat_x + 3, bat_y + 3, bat_w - 10, bat_h -5 , gc9a01.GREEN)
#日期与星期
self.display_inconsolata_font(inconsolata_16, "12/08", 150, 60)
self.tft.text(vga1_bold_16x16, "Thur", 150, 90, gc9a01.YELLOW)
#运动步数
self.tft.text(vga1_bold_16x16, "walk:4567", 50, 190, gc9a01.YELLOW)
def show_time_info(self):
self.second = self.second + 1
if self.second >= 60:
self.minute = self.minute + 1
self.second = 0
hour_str = "%02d" % self.hour
minute_str = "%02d" % self.minute
second_str = "%02d" % self.second
self.tft.fill_rect(25, 50, 115, 60, gc9a01.BLACK)
self.tft.write(chango_64, hour_str, 25, 50, gc9a01.WHITE)
self.tft.fill_rect(60, 105, 115, 60, gc9a01.BLACK)
self.tft.write(chango_64, minute_str, 60, 105, gc9a01.YELLOW)
self.tft.write(NotoSans_32, second_str, 180, 130, gc9a01.GREEN)
self.last_hour = self.hour
self.last_minute = self.minute
self.last_second = self.second
def show_img(self, img):
self.tft.jpg(img, 0, 0, gc9a01.SLOW)
def show_watch(self):
self.tft.fill(gc9a01.BLACK)
self.show_static_info()
self.show_time_info()</code></pre>
<p cid="n106" mdtype="paragraph">主函数</p>
<pre cid="n107" lang="python" mdtype="fences" spellcheck="false">
<code>def main():
#IMU
qmi8658=myimu.IMU_QMI8658C()
watchPanel=WatchPanel()
watchPanel.init()
idx = 1
while True:
#read QMI8658
xyz=qmi8658.Read_XYZ()
print("accz:%f" % xyz)
if xyz > -1:
idx = idx+1
if (idx == 4):
idx = 1
if (idx == 1):
watchPanel.show_watch()
elif (idx == 2):
watchPanel.show_img("weather.jpg")
elif (idx == 3):
watchPanel.show_img("pay.jpg")
time.sleep(1)
main()</code></pre>
<h1 cid="n108" mdtype="heading">测试</h1>
<p cid="n109" mdtype="paragraph">显示时间界面</p>
<p cid="n109" mdtype="paragraph"></p>
<p cid="n110" mdtype="paragraph">显示天气界面</p>
<p cid="n110" mdtype="paragraph"></p>
<p cid="n111" mdtype="paragraph">显示支付宝界面</p>
<p cid="n111" mdtype="paragraph"></p>
<h1 cid="n112" mdtype="heading">演示视频</h1>
<p>ccf146de214c5520e8ed4606c017be53<br />
</p>
<h1 cid="n113" mdtype="heading">总结</h1>
<p cid="n114" mdtype="paragraph">本篇利用RP2040实现了一个综合功能:运动表盘的显示与功能的切换,切换功能只利用IMU检测Z轴加速度的变化,后续可考虑结合6轴的数据解算出姿态角,从而可以使姿态检测更加准确。</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>6轴的数据解算出姿态角解析速度如何?能达到多快的频率</p>
<p>这个界面切换采用加速度传感器的角度变化的想法不错!!!好像有手表就可以这样,无接触式控制。</p>
秦天qintian0303 发表于 2023-1-3 08:55
6轴的数据解算出姿态角解析速度如何?能达到多快的频率
<p>目前还没有做姿态解算,只是用来单一Z轴的加速度简单的实现姿态变化检测</p>
<p>很想也买一个模块,自己亲自设计体验一下。</p>
<p>这个温度条做的漂亮<img height="48" src="https://bbs.eeworld.com.cn/static/editor/plugins/hkemoji/sticker/facebook/wanwan88.gif" width="59" /></p>
sipower 发表于 2023-1-10 09:19
这个温度条做的漂亮
<p>这个只是个图片,哈哈</p>
页:
[1]