3000浏览
查看: 3000|回复: 3

[项目] 桌面天气显示站

[复制链接]
本帖最后由 小LZY 于 2020-5-26 15:03 编辑

每当从繁忙的工作中停下来小小的休息一会的时候;总会觉得自己的桌面是不是太枯燥无味;于是自己就想添加一些美观的配件,让自己的左面美观。今天就教大家做一个桌面天气显示站。


制作思路:
   用一个ESP32获取网络的天气和时间;再用一个SHT35传感器来收集室内的温湿度;最后将所有的数据显示在屏幕。最后在做一个好看的外壳。


准备材料:

1.ESP32
桌面天气显示站图1

2.SHT-35
桌面天气显示站图2

3.1.54" 240x240 LCD

4.线材若干

5.泡沫板一张,黑色包装纸一张


硬件原理图
这个应用只有三个主要的硬件,只需要把屏幕SPI连接到ESP32上的SPI,SHT-35的IIC连接到ESP32上的IIC即可;下面就是其原理图:
桌面天气显示站图3


软件代码的书写

代码部分相对来说比较麻烦,该应用是向中国天气网请求数据,然后得到返回的数据;由于返回的是一个Json的数据包的格式,所以需要对其进行
一次数据解码,才能正常的调用其数据。我会把所有用到的软件库放在文章末尾,提供给大家使用。

外形的制作:
用泡沫板做一个小盒子,将其包裹起来。
正面(1.54" 显示屏)
桌面天气显示站图4
侧面(microUSB口)
桌面天气显示站图5
背面(有一个SHT-35)
桌面天气显示站图6



最后的演示效果:
桌面天气显示站图7


ino代码:
[mw_shl_code=c,false]#include "mPython_Weather.h"
#include "DFRobot_SHT3x.h"
#include "DFRobot_GDL.h"


/*M0*/
#if defined Arduino_SAM_ZERO
#define TFT_DC  7
#define TFT_CS  5
#define TFT_RST 6
/*ESP32 and ESP8266*/
#elif defined(ESP32) || defined(ESP8266)
#define TFT_DC  D3
#define TFT_CS  D4
#define TFT_RST D5
/*AVR Series Board*/
#else
#define TFT_DC  2
#define TFT_CS  3
#define TFT_RST 4
#endif

//填写WiFi名称和密码
const char* ssid="xxxxx";
const char* password="hxxxxxx";

mPython_Weather myweather;
DFRobot_SHT3x sht3x;
DFRobot_ST7789_240x240_HW_SPI screen(/*dc=*/TFT_DC,/*cs=*/TFT_CS,/*rst=*/TFT_RST);

void setup() {
  // put your setup code here, to run once:
Serial.begin(115200);
delay(10);
while (sht3x.begin() != 0) {
    Serial.println("Failed to initialize the chip, please confirm the chip connection");
    delay(1000);
  }
screen.begin();


Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);

WiFi.begin(ssid,password);
while(WiFi.status() != WL_CONNECTED){
  delay(500);
  Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());

Serial.println(myweather.connectServer());


}

void loop() {
  screen.setTextSize(3);
  screen.fillScreen(COLOR_RGB565_BLACK);
  screen.setFont(&STHUPOFont36pt);
  delay(500);
  
  screen.setCursor(0,20);
  screen.setTextColor(COLOR_RGB565_GREEN);
  screen.setTextWrap(true);
  screen.print(myweather.getWeather("cityname","101270101"));
  delay(500);

  screen.setCursor(90,20);
  screen.setTextColor(COLOR_RGB565_GREEN);
  screen.setTextWrap(true);
  screen.print(myweather.getWeather("weather","101270101"));
  delay(500);

  screen.setFont(&STHUPOFont24pt);
  screen.setCursor(60,60);
  screen.setTextColor(COLOR_RGB565_BLUE);
  screen.setTextWrap(true);
  screen.print(myweather.getWeather("temperaturLow","101270101"));
  delay(500);

  screen.setCursor(110,70);
  screen.setTextColor(COLOR_RGB565_BLUE);
  screen.setTextWrap(true);
  screen.print("~");
  delay(500);
  
  screen.setCursor(130,60);
  screen.setTextColor(COLOR_RGB565_BLUE);
  screen.setTextWrap(true);
  screen.print(myweather.getWeather("temperaturHigh","101270101"));
  delay(500);

  screen.setCursor(85,90);
  screen.setTextColor(COLOR_RGB565_RED);
  screen.setTextWrap(true);
  screen.print(myweather.getWeather("time","101270101"));
  delay(500);

  screen.setCursor(0,140);
  screen.setTextColor(COLOR_RGB565_RED);
  screen.setTextWrap(true);
  screen.print("室内温度:");
  delay(500);
  
  screen.setCursor(140,140);
  screen.setTextColor(COLOR_RGB565_RED);
  screen.setTextWrap(true);
  screen.print(sht3x.getTemperatureC());
  delay(500);

  screen.setCursor(0,180);
  screen.setTextColor(COLOR_RGB565_RED);
  screen.setTextWrap(true);
  screen.print("室内湿度:");
  delay(500);

  screen.setCursor(140,180);
  screen.setTextColor(COLOR_RGB565_RED);
  screen.setTextWrap(true);
  screen.print(sht3x.getHumidityRH());
  delay(3000 );

}[/mw_shl_code]



下载附件Weather.zip
下载附件DFRobot_CHfont.zip

铁熊  初级技神

发表于 2020-5-26 16:35:36

这款彩屏还没上市吧?
回复

使用道具 举报

小LZY  见习技师
 楼主|

发表于 2020-5-27 09:02:38

铁熊 发表于 2020-5-26 16:35
这款彩屏还没上市吧?

对的;快上市了
回复

使用道具 举报

DFS1w2cb8o8  中级技师

发表于 2020-8-2 10:44:01

厉害厉害
回复

使用道具 举报

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

本版积分规则

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

硬件清单

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

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

mail