7239浏览
查看: 7239|回复: 0

[项目] 基于树莓派Pico的温度提醒装置

[复制链接]
本帖最后由 创客维克多 于 2024-1-9 10:33 编辑

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



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

       接线图:

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

       程序:

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

      C代码:
  1. /*!
  2. * MindPlus
  3. * pico
  4. *
  5. */
  6. #include <DFRobot_URM10.h>
  7. #include <DFRobot_SSD1306_I2C.h>
  8. // 动态变量
  9. volatile float mind_n_Temp;
  10. // 函数声明
  11. String numberRetain(float t, uint8_t n);
  12. // 静态常量
  13. const chCode chBuf[] = {
  14.         {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}},
  15.         {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}},
  16.         {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}},
  17.         {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}},
  18.         {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}},
  19.         {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}},
  20.         {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}},
  21.         {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}},
  22.         {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}},
  23.         {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}},
  24.         {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}},
  25.         {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}},
  26.         {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}},
  27.         {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}},
  28.         {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}},
  29.         {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}},
  30.         {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}},
  31.         {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}},
  32.         {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}},
  33.         {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}},
  34.         {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}},
  35.         {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}},
  36.         {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}},
  37.         {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}},
  38.         {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}},
  39.         {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}}
  40. };
  41. // 创建对象
  42. DFRobot_SSD1306_I2C oled12864;
  43. DFRobot_URM10       urm10;
  44. // 主程序开始
  45. void setup() {
  46.         oled12864.setChCode(chBuf);
  47.         oled12864.begin(0x3c);
  48. }
  49. void loop() {
  50.         mind_n_Temp = analogReadTemp();
  51.         if (((urm10.getDistanceCM(2, 3))<=5)) {
  52.                 oled12864.setCursorLine(0);
  53.                 oled12864.printLine((String((String("气温:") + String(numberRetain(mind_n_Temp,1)))) + String(" ℃")));
  54.                 if ((mind_n_Temp<=15)) {
  55.                         oled12864.setCursorLine(3);
  56.                         oled12864.printLine("当前温度低,");
  57.                         oled12864.setCursorLine(4);
  58.                         oled12864.printLine("请注意防寒保暖。");
  59.                         delay(1000);
  60.                         oled12864.fillScreen(0);
  61.                 }
  62.                 else if (((mind_n_Temp>15) && (mind_n_Temp<=26))) {
  63.                         oled12864.setCursorLine(3);
  64.                         oled12864.printLine("当前温度舒适,");
  65.                         oled12864.setCursorLine(4);
  66.                         oled12864.printLine("请注意早晚温差。");
  67.                         delay(1000);
  68.                         oled12864.fillScreen(0);
  69.                 }
  70.                 else {
  71.                         oled12864.setCursorLine(3);
  72.                         oled12864.printLine("当前温度高,");
  73.                         oled12864.setCursorLine(4);
  74.                         oled12864.printLine("请注意多喝水。");
  75.                         delay(1000);
  76.                         oled12864.fillScreen(0);
  77.                 }
  78.         }
  79.         else {
  80.                 oled12864.fillScreen(0);
  81.         }
  82. }
  83. // 静态函数
  84. String numberRetain(float t, uint8_t n)
  85. {
  86.   String str=t<0 ? "-" : ""; int8_t _n=n; t=abs(t);
  87.   for(; _n>=0; --_n){
  88.     uint32_t integer = floor(t);
  89.     float decimal = t - integer;
  90.     str += _n == n ? (String(integer) + (n ? "." : "")) : integer;
  91.     t = decimal*10;
  92.   }
  93.   return str;
  94. }
复制代码


       视频:

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4

© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail