创客维克多 发表于 2024-1-8 13:52:03

基于树莓派Pico的温度提醒装置

本帖最后由 创客维克多 于 2024-1-9 10:33 编辑

一次偶然的机会,买了3块树莓派Pico,但是后来感觉没啥用,就压箱底了。直到这次DF社区发起的树莓派活动,于是想起了箱底的Pico,就拿来试试看。没想到还挺不错的,最棒的是它自带温度传感器,直接用串口读取非常方便。但是奇怪了,为什么总是上传不了程序呢?经过几周的折腾,后来发现是Mind+版本的问题,更新到V1.8-RC1.0之后就解决了上传不了程序的问题了。

       本来想用RX711称重模块做一个称重作品的,结果测试了一个午都不成功,原因是称重模块的读取数据很不稳定而且跨越的幅度很大,所以放弃了。
       入冬以来,学校很多小朋友感冒请假没来上学,很多都是因为着凉了。于是我就想到做一个出门防着凉提醒装置,放在家门鞋柜上面,可以在出门前提醒小朋友。

       接线图:



       程序:


      

      C代码:
/*!
* MindPlus
* pico
*
*/
#include <DFRobot_URM10.h>
#include <DFRobot_SSD1306_I2C.h>

// 动态变量
volatile float mind_n_Temp;
// 函数声明
String numberRetain(float t, uint8_t n);
// 静态常量
const chCode chBuf[] = {
      {0x6c14,0xe6b094,0xC6F8,{0x10,0x00,0x10,0x00,0x3f,0xfc,0x20,0x00,0x4f,0xf0,0x80,0x00,0x3f,0xf0,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x0a,0x00,0x0a,0x00,0x06,0x00,0x02}},
      {0x6e29,0xe6b8a9,0xCEC2,{0x00,0x00,0x23,0xf8,0x12,0x08,0x12,0x08,0x83,0xf8,0x42,0x08,0x42,0x08,0x13,0xf8,0x10,0x00,0x27,0xfc,0xe4,0xa4,0x24,0xa4,0x24,0xa4,0x24,0xa4,0x2f,0xfe,0x00,0x00}},
      {0xff1a,0xefbc9a,0xA3BA,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x30,0x00,0x00,0x00,0x30,0x00,0x30,0x00,0x00,0x00,0x00,0x00}},
      {0x2103,0xe28483,0xA1E6,{0x60,0x00,0x91,0xf4,0x96,0x0c,0x6c,0x04,0x08,0x04,0x18,0x00,0x18,0x00,0x18,0x00,0x18,0x00,0x18,0x00,0x18,0x00,0x08,0x00,0x0c,0x04,0x06,0x08,0x01,0xf0,0x00,0x00}},
      {0x5f53,0xe5bd93,0xB5B1,{0x01,0x00,0x21,0x08,0x11,0x08,0x09,0x10,0x09,0x20,0x01,0x00,0x7f,0xf8,0x00,0x08,0x00,0x08,0x00,0x08,0x3f,0xf8,0x00,0x08,0x00,0x08,0x00,0x08,0x7f,0xf8,0x00,0x08}},
      {0x524d,0xe5898d,0xC7B0,{0x10,0x10,0x08,0x10,0x08,0x20,0xff,0xfe,0x00,0x00,0x3e,0x08,0x22,0x48,0x22,0x48,0x3e,0x48,0x22,0x48,0x22,0x48,0x3e,0x48,0x22,0x08,0x22,0x08,0x2a,0x28,0x24,0x10}},
      {0x5ea6,0xe5baa6,0xB6C8,{0x01,0x00,0x00,0x80,0x3f,0xfe,0x22,0x20,0x22,0x20,0x3f,0xfc,0x22,0x20,0x22,0x20,0x23,0xe0,0x20,0x00,0x2f,0xf0,0x24,0x10,0x42,0x20,0x41,0xc0,0x86,0x30,0x38,0x0e}},
      {0x4f4e,0xe4bd8e,0xB5CD,{0x08,0x08,0x08,0x3c,0x0b,0xe0,0x12,0x20,0x12,0x20,0x32,0x20,0x32,0x20,0x53,0xfe,0x92,0x20,0x12,0x10,0x12,0x10,0x12,0x12,0x12,0x0a,0x12,0x8a,0x13,0x26,0x12,0x12}},
      {0xff0c,0xefbc8c,0xA3AC,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x30,0x00,0x10,0x00,0x20,0x00,0x00,0x00}},
      {0x8bf7,0xe8afb7,0xC7EB,{0x00,0x40,0x40,0x40,0x27,0xfc,0x20,0x40,0x03,0xf8,0x00,0x40,0xe7,0xfe,0x20,0x00,0x23,0xf8,0x22,0x08,0x23,0xf8,0x22,0x08,0x2b,0xf8,0x32,0x08,0x22,0x28,0x02,0x10}},
      {0x6ce8,0xe6b3a8,0xD7A2,{0x00,0x80,0x20,0x40,0x10,0x00,0x17,0xfc,0x80,0x40,0x40,0x40,0x40,0x40,0x10,0x40,0x13,0xfc,0x20,0x40,0xe0,0x40,0x20,0x40,0x20,0x40,0x20,0x40,0x2f,0xfe,0x00,0x00}},
      {0x610f,0xe6848f,0xD2E2,{0x01,0x00,0x3f,0xf8,0x08,0x20,0x04,0x40,0xff,0xfe,0x00,0x00,0x1f,0xf0,0x10,0x10,0x1f,0xf0,0x10,0x10,0x1f,0xf0,0x02,0x00,0x51,0x04,0x51,0x12,0x90,0x12,0x0f,0xf0}},
      {0x9632,0xe998b2,0xB7C0,{0x00,0x40,0x7c,0x20,0x44,0x20,0x4b,0xfe,0x48,0x80,0x50,0x80,0x48,0x80,0x48,0xfc,0x44,0x84,0x44,0x84,0x44,0x84,0x68,0x84,0x51,0x04,0x41,0x04,0x42,0x28,0x44,0x10}},
      {0x5bd2,0xe5af92,0xBAAE,{0x02,0x00,0x01,0x00,0x7f,0xfe,0x44,0x42,0x9f,0xf4,0x04,0x40,0x3f,0xf8,0x04,0x40,0xff,0xfe,0x08,0x20,0x13,0x10,0x20,0x88,0xc0,0x46,0x06,0x00,0x01,0x80,0x00,0x40}},
      {0x4fdd,0xe4bf9d,0xB1A3,{0x08,0x00,0x0b,0xf8,0x0a,0x08,0x12,0x08,0x12,0x08,0x33,0xf8,0x30,0x40,0x50,0x40,0x97,0xfc,0x10,0xe0,0x11,0x50,0x12,0x48,0x14,0x44,0x18,0x42,0x10,0x40,0x10,0x40}},
      {0x6696,0xe69a96,0xC5AF,{0x00,0x3c,0x07,0xc0,0x7a,0x44,0x49,0x28,0x48,0x00,0x4b,0xfc,0x78,0x80,0x48,0x80,0x4f,0xfe,0x49,0x00,0x49,0xf8,0x7a,0x88,0x4a,0x50,0x04,0x20,0x08,0xd8,0x03,0x06}},
      {0x3002,0xe38082,0xA1A3,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x00,0x24,0x00,0x24,0x00,0x18,0x00,0x00,0x00,0x00,0x00}},
      {0x8212,0xe88892,0xCAE6,{0x10,0x00,0x11,0xf8,0x28,0x08,0x44,0x50,0x82,0x20,0x7c,0x10,0x13,0xfe,0x10,0x22,0xfe,0x24,0x10,0x20,0x10,0x20,0x7c,0x20,0x44,0x20,0x44,0x20,0x7c,0xa0,0x44,0x40}},
      {0x9002,0xe98082,0xCACA,{0x00,0x78,0x23,0xc0,0x10,0x40,0x10,0x40,0x07,0xfe,0x00,0x40,0xf0,0x40,0x13,0xf8,0x12,0x08,0x12,0x08,0x12,0x08,0x13,0xf8,0x12,0x08,0x28,0x00,0x47,0xfe,0x00,0x00}},
      {0x65e9,0xe697a9,0xD4E7,{0x00,0x00,0x1f,0xf0,0x10,0x10,0x10,0x10,0x1f,0xf0,0x10,0x10,0x10,0x10,0x1f,0xf0,0x01,0x00,0x01,0x00,0xff,0xfe,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00}},
      {0x665a,0xe6999a,0xCDED,{0x00,0x80,0x00,0x80,0x79,0xf8,0x4a,0x08,0x4c,0x10,0x4b,0xfc,0x4a,0x44,0x7a,0x44,0x4a,0x44,0x4b,0xfc,0x48,0xa0,0x48,0xa0,0x79,0x22,0x49,0x22,0x02,0x1e,0x04,0x00}},
      {0x5dee,0xe5b7ae,0xB2EE,{0x08,0x20,0x04,0x40,0x7f,0xfc,0x01,0x00,0x01,0x00,0x3f,0xf8,0x02,0x00,0x02,0x00,0xff,0xfe,0x04,0x00,0x08,0x00,0x17,0xf8,0x20,0x80,0x40,0x80,0x80,0x80,0x1f,0xfc}},
      {0x9ad8,0xe9ab98,0xB8DF,{0x02,0x00,0x01,0x00,0xff,0xfe,0x00,0x00,0x0f,0xe0,0x08,0x20,0x08,0x20,0x0f,0xe0,0x00,0x00,0x7f,0xfc,0x40,0x04,0x4f,0xe4,0x48,0x24,0x48,0x24,0x4f,0xe4,0x40,0x0c}},
      {0x591a,0xe5a49a,0xB6E0,{0x02,0x00,0x02,0x00,0x07,0xf0,0x08,0x20,0x38,0x40,0x04,0x80,0x03,0x40,0x0c,0x80,0x71,0xf8,0x02,0x08,0x0c,0x10,0x32,0x20,0x01,0x40,0x01,0x80,0x0e,0x00,0x70,0x00}},
      {0x559d,0xe5969d,0xBAC8,{0x00,0x00,0x03,0xf8,0x7a,0x08,0x4b,0xf8,0x4a,0x08,0x4b,0xf8,0x49,0x00,0x4b,0xfc,0x4c,0x44,0x4a,0x44,0x7a,0xa4,0x4a,0x04,0x03,0xf4,0x00,0x04,0x00,0x28,0x00,0x10}},
      {0x6c34,0xe6b0b4,0xCBAE,{0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x08,0x01,0x08,0x7d,0x90,0x05,0xa0,0x09,0x40,0x09,0x40,0x11,0x20,0x11,0x10,0x21,0x08,0x41,0x06,0x81,0x00,0x05,0x00,0x02,0x00}}
};
// 创建对象
DFRobot_SSD1306_I2C oled12864;
DFRobot_URM10       urm10;


// 主程序开始
void setup() {
      oled12864.setChCode(chBuf);
      oled12864.begin(0x3c);
}
void loop() {
      mind_n_Temp = analogReadTemp();
      if (((urm10.getDistanceCM(2, 3))<=5)) {
                oled12864.setCursorLine(0);
                oled12864.printLine((String((String("气温:") + String(numberRetain(mind_n_Temp,1)))) + String(" ℃")));
                if ((mind_n_Temp<=15)) {
                        oled12864.setCursorLine(3);
                        oled12864.printLine("当前温度低,");
                        oled12864.setCursorLine(4);
                        oled12864.printLine("请注意防寒保暖。");
                        delay(1000);
                        oled12864.fillScreen(0);
                }
                else if (((mind_n_Temp>15) && (mind_n_Temp<=26))) {
                        oled12864.setCursorLine(3);
                        oled12864.printLine("当前温度舒适,");
                        oled12864.setCursorLine(4);
                        oled12864.printLine("请注意早晚温差。");
                        delay(1000);
                        oled12864.fillScreen(0);
                }
                else {
                        oled12864.setCursorLine(3);
                        oled12864.printLine("当前温度高,");
                        oled12864.setCursorLine(4);
                        oled12864.printLine("请注意多喝水。");
                        delay(1000);
                        oled12864.fillScreen(0);
                }
      }
      else {
                oled12864.fillScreen(0);
      }
}


// 静态函数
String numberRetain(float t, uint8_t n)
{
String str=t<0 ? "-" : ""; int8_t _n=n; t=abs(t);
for(; _n>=0; --_n){
    uint32_t integer = floor(t);
    float decimal = t - integer;
    str += _n == n ? (String(integer) + (n ? "." : "")) : integer;
    t = decimal*10;
}
return str;
}


       视频:
https://v.youku.com/v_show/id_XNjMxNDA4MjkwOA==.html
页: [1]
查看完整版本: 基于树莓派Pico的温度提醒装置