在rp2040上用DHT22 + ssd1306显示温度信息,

 用 embedded-graphics库和ssd1306库来实现。但实现的效果不是很理想,无法在ssd1306屏幕上显示中文。

 为了解决这个问题,在github和crates.io上面找了几天。解决方法还是找到了,利用  u8g2-font这个库实现。。。

 

实现的办法如下:

Cargo.toml的[dependencies]节点下添加如下内容

embedded-hal = { version = "1.0.0" } 
embedded-graphics = "0.8.1"
dht-sensor = "0.2.1"
ssd1306 = "0.8.1"
u8g2-fonts = { version = "0.4.0", features = ["embedded_graphics_textstyle"] }

 

src/main.rs文件头中添加引用

use embedded_graphics::{
    pixelcolor::BinaryColor,
    prelude::*,
    primitives::{Line, PrimitiveStyle},
    text::{Baseline, Text},
};
use u8g2_fonts::U8g2TextStyle;

src/main.rs:: fn main()  里面添加定义

  ...此处省略了很多代码
  // Create a text style for drawing the font:
此处的u8g2_font_wqy12_t_gb2312是输出中文的重点
    let character_style =
        U8g2TextStyle::new(u8g2_fonts::fonts::u8g2_font_wqy12_t_gb2312, BinaryColor::On);

fn main()  -> {
 .... 此处省略了很多代码
loop {
             // Empty the display:
        // Draw 3 lines of text:
        //reset before loop
        let _ = display.clear(BinaryColor::Off);

        write!(&mut line2, "湿度: {}%", humi).unwrap();
        Text::with_baseline(
            line2.as_str(),
            Point::new(32, 38),
            character_style.clone(),
            Baseline::Top,
        )
        .draw(&mut display)
        .unwrap();

    ... 此处省略了很多代码
        display.flush().unwrap();
        // delay for 1 sec
        //per loop is 1 sec
        timer.delay_ms(1000);
 }
}

 

最终实现效果如图

 

本项目开源地址: https://github.com/sndnvaps/rp2040-display

u8g2-font库开源地址,主用提供中文字库:https://github.com/Finomnis/u8g2-fonts

目前支持的中文字库 https://github.com/olikraus/u8g2/wiki/fntgrpwqy ,https://github.com/olikraus/u8g2/wiki/fntgrpbb

posted @ 2024-09-28 20:32 sndnvaps 阅读(127) 评论(0) 推荐(0) 编辑
摘要: 因何而起,从网上花了40大洋买了一个比较水的128G U盘,准备格式化为ext4以供openwrt的samba来使用。但经两天的努力后,发现无法格式化为ext4,只能格式化为exfat。但是 树莓派的3B+ openwrt 21.02.3版本,在仓库里面无法安装kmod-fs-exfat。简单来说, 阅读全文
posted @ 2022-06-10 10:44 sndnvaps 阅读(1389) 评论(0) 推荐(0) 编辑
摘要: 使用ffmpeg进行视频的裁剪和合并 阅读全文
posted @ 2019-05-08 16:46 sndnvaps 阅读(19328) 评论(0) 推荐(0) 编辑
摘要: linux平台,使用rand.Seed() windows平台,直接使用 rand.Int63n() 或者 rand.Intn() Mac平台 阅读全文
posted @ 2017-01-14 20:18 sndnvaps 阅读(1318) 评论(0) 推荐(0) 编辑
摘要: #!/bin/sh #Filename: repo_sync.sh count=0 ret=1 while [ ret -ne 0 ] do #输入参数1,用作同步的线程数 #如果什么参数都不输入,默认线程为4 #usage: ./repo_sync.sh 10 if [1 -lt 20 ] && [ $1 -gt 0 ]; then echo "start repo t... 阅读全文
posted @ 2016-10-03 08:47 sndnvaps 阅读(869) 评论(1) 推荐(0) 编辑
摘要: 小米2S mkm ROM 阅读全文
posted @ 2016-08-28 15:07 sndnvaps 阅读(2231) 评论(0) 推荐(0) 编辑
摘要: MultiROM for the XIAOMI MI2S/2C/2! (Kexec HardBoot Enabled with Kexec HardBoot Patch!) 阅读全文
posted @ 2016-08-28 14:58 sndnvaps 阅读(2203) 评论(0) 推荐(0) 编辑
摘要: ubuntu touch v3.4 kernel AppArmor v3 backport patch 地址1:https://github.com/multirom-aries/ubuntu-phone_kernel_lge_msm8226/commit/447767477f59130246221 阅读全文
posted @ 2016-06-18 09:21 sndnvaps 阅读(311) 评论(0) 推荐(0) 编辑
摘要: 原文链接:http://www.myexception.cn/android/1904013.html 启动service保存android系统log 作为android开发工程师,出现了BUG是否苦于没有log而苦恼万分呢,以下敝人提供一套自动保存log的方法,供大家借鉴学习: 首先,在产品目录的 阅读全文
posted @ 2016-06-11 15:12 sndnvaps 阅读(3148) 评论(0) 推荐(0) 编辑
摘要: 注意:此版本为合并分区后的twrp 小米2S 合并分区教程:http://forum.xda-developers.com/mi-2/orig-development/flashtools-miflash4linux-recovery-qdl-t3036730 选项为:unified_single: 阅读全文
posted @ 2016-05-23 19:41 sndnvaps 阅读(15923) 评论(0) 推荐(0) 编辑
点击右上角即可分享
微信分享提示