『瀚思彼岸』» 智能家居技术论坛

 找回密码
 立即注册
12
返回列表 发新帖
楼主: hyifan

[技术探讨] 这里有用ESP32+ILI9341显示屏的吗?咨询个问题。

[复制链接]

11

主题

123

帖子

3470

积分

论坛元老

Rank: 8Rank: 8

积分
3470
金钱
3347
HASS币
0
 楼主| 发表于 2024-1-29 10:11:50 | 显示全部楼层
tettr 发表于 2024-1-28 22:43
楼主,能不能分享一下,你之前用  ESPHOME 来做的 代码呢?

不胜感谢。
esphome:
  name: esp-livingroom-display

esp32:
  board: nodemcu-32s
  framework:
    type: arduino
    version: recommended

psram:
  
logger:
  level: DEBUG
  logs:
    component: ERROR

debug:
  update_interval: 5s
  
ota:
  password: !secret ota_password

#api:
#  encryption:
#    key: !secret api_key

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  fast_connect: on
  reboot_timeout: 15min
  ap:
    ssid: $device_name
    password: "!secret ap_password"
  use_address: esp-livingroom-display.gz

web_server:
  port: 80
  auth:
    username: admin
    password: !secret web_password
    
time:
  - platform: sntp
    id: sntp_time
    timezone: Asia/Shanghai

spi:
  clk_pin: 18
  mosi_pin: 23
  miso_pin: 19

i2c:
  sda: 21
  scl: 22
  scan: true

mqtt:
  broker: !secret mqtt_broker
  username: !secret mqtt_username
  password: !secret mqtt_password
  topic_prefix: esp_livingroom_display

sensor:
  - platform: sht4x
    temperature:
      id: livingroom_temperature
      name: "temperature"
      unit_of_measurement: "°C"
      accuracy_decimals: 2
    humidity:
      id: livingroom_humidity
      name: "humidity"
      unit_of_measurement: "%"
      accuracy_decimals: 2
    address: 0x44
    heater_max_duty: 0.05
    heater_power: High
    heater_time: Long
    update_interval: 60s

  - platform: bmp280
    temperature:
      name: "bmp280_temperature"
      oversampling: 16x
    pressure:
      name: "pressure"
    address: 0x76
    update_interval: 60s

  - platform: bh1750
    name: "bh1750 illuminance"
    address: 0x23
    update_interval: 30s
    on_value:
      then:
        - if:
            condition:
                - lambda: return x <= 30;
            then:
                - light.turn_on:
                    id: back_light
                    brightness: 40%        
        - if: 
            condition:
              and:
                - lambda: return x >= 31 ;
                - lambda: return x <= 80;                
            then:
                - light.turn_on:
                    id: back_light
                    brightness: 65%   
        - if:
            condition:
                - lambda: return x >= 81;
            then:
                - light.turn_on:
                    id: back_light
                    brightness: 100%

  - platform: uptime
    name: uptime
    filters:
      - lambda: return x / 3600.0;
    unit_of_measurement: "Hours"
    accuracy_decimals: 2

  - platform: template
    name: cpufreq
    icon: mdi:cpu-32-bit
    lambda: |-
      return ESP.getCpuFreqMHz();
    unit_of_measurement: "MHz"
    update_interval: 10s

  - platform: template
    name: freememory
    icon: mdi:memory
    lambda: |-
      return ESP.getFreeHeap();
    filters:
      - multiply: 0.001
    unit_of_measurement: "KB"
    update_interval: 10s
    
  - platform: mqtt_subscribe
    name: "outside_temperature"
    id: outside_temperature
    topic: esp_outside/sensor/temperature/state
    unit_of_measurement: "°C"
#    internal: true

  - platform: mqtt_subscribe
    name: "outside_humidity"
    id: outside_humidity
    topic: esp_outside/sensor/humidity/state
    unit_of_measurement: "%"
#    internal: true

  - platform: mqtt_subscribe
    name: "cy_temperature"
    id: cy_temperature
    topic: esp_cy_outside/sensor/temperature/state
    unit_of_measurement: "°C"
#    internal: true

  - platform: mqtt_subscribe
    name: "cy_humidity"
    id: cy_humidity
    topic: esp_cy_outside/sensor/humidity/state
    unit_of_measurement: "%"
#    internal: true

  - platform: mqtt_subscribe
    name: "cy_sensor_voltage"
    id: cy_sensor_voltage
    topic: esp_cy_outside/sensor/voltage/state
    unit_of_measurement: "V"
#    internal: true

# MQTT网络传感器
  - platform: mqtt_subscribe
    name: "wan_up"
    id: wan_up
    topic: node_red/network/wan_up  
    unit_of_measurement: "Mbit/s"
#    internal: true

  - platform: mqtt_subscribe
    name: "wan_down"
    id: wan_down
    topic: node_red/network/wan_down
    unit_of_measurement: "Mbit/s"
#    internal: true

  - platform: mqtt_subscribe
    name: "vpn_up"
    id: vpn_up
    topic: node_red/network/vpn_up  
    unit_of_measurement: "Mbit/s"
#    internal: true

  - platform: mqtt_subscribe
    name: "vpn_down"
    id: vpn_down
    topic: node_red/network/vpn_down
    unit_of_measurement: "Mbit/s"
#    internal: true

# MQTT能源传感器
  - platform: mqtt_subscribe
    name: "current"
    id: current
    topic: node_red/energy/current
    unit_of_measurement: "A"
#    internal: true

  - platform: mqtt_subscribe
    name: "apparent_power"
    id: apparent_power
    topic: node_red/energy/apparent_power
    unit_of_measurement: "VA"
    filters:
      - multiply: 1000
#    internal: true

  - platform: mqtt_subscribe
    name: "daily_energy"
    id: daily_energy
    topic: node_red/energy/daily_energy
    unit_of_measurement: "kWh"
#    internal: true

  - platform: mqtt_subscribe
    name: "monthly_energy"
    id: monthly_energy
    topic: node_red/energy/monthly_energy
    unit_of_measurement: "kWh"
#    internal: true

# DS36717 磁盘空间传感器
  - platform: mqtt_subscribe
    name: "total_size"
    id: total_size
    topic: node_red/ds3617/total_size
    accuracy_decimals: 2
    unit_of_measurement: "T"
#    internal: true

  - platform: mqtt_subscribe
    name: "free_space"
    id: free_space
    topic: node_red/ds3617/used_space
    accuracy_decimals: 2
    unit_of_measurement: "T"
    filters:
    - lambda: return id(total_size).state - x;
#    internal: true

# cy网络设备传感器
text_sensor:
  - platform: mqtt_subscribe
    name: "cy_vpn"
    id: cy_vpn
    topic: node_red/network/cy_vpn_status
#    internal: true
    filters:
      - map:
        - home -> 已连接
        - not_home -> 离线

  - platform: mqtt_subscribe
    name: "ds211"
    id: ds211
    topic: node_red/network/ds211_status
#    internal: true
    filters:
      - map:
        - home -> 在线
        - not_home -> 离线

# DS3617磁盘状态传感器
  - platform: mqtt_subscribe
    name: "raid_status"
    id: raid_status
    topic: node_red/ds3617/raid_status
#    internal: true
    filters:
      - map:
        - normal -> 正常
        - unknow -> 未知

  - platform: mqtt_subscribe
    name: "disk1"
    id: disk1
    topic: node_red/ds3617/disk1_status
#    internal: true
    filters:
      - map:
        - normal -> 正常
        - unknow -> 未知

  - platform: mqtt_subscribe
    name: "disk2"
    id: disk2
    topic: node_red/ds3617/disk2_status
#    internal: true
    filters:
      - map:
        - normal -> 正常
        - unknow -> 未知

  - platform: mqtt_subscribe
    name: "disk3"
    id: disk3
    topic: node_red/ds3617/disk3_status
#    internal: true
    filters:
      - map:
        - normal -> 正常
        - unknow -> 未知

  - platform: mqtt_subscribe
    name: "disk4"
    id: disk4
    topic: node_red/ds3617/disk4_status
#    internal: true
    filters:
      - map:
        - normal -> 正常
        - unknow -> 未知

button:
  - platform: restart
    name: "restart"

# 显示屏部分
color:
  - id: color_red
    hex: FE1010
  - id: color_green
    hex: 30FE10
  - id: color_blue
    hex: 4C70FA
  - id: color_orange
    hex: F89C08
  - id: color_white
    hex: FFFFFF
  - id: color_pink
    hex: F80983
  - id: color_yellow
    hex: FEFF00
  - id: color_lightblue
    hex: 5EEDFA

font:
# 微软雅黑  
  - file: 'msyh.ttf'
    id: msyh_size_13 
    size: 13
    glyphs: 传感压伏出入站概况已连接存储服务器容可安流量当宽带功率上下行潮阳磁盘阵列正常未知在离线室内外温湿度网络日月用电瓦实时信息/!"%()+,-_.::°0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz

  - file: 'msyh.ttf'
    id: msyh_size_14 
    size: 14
    glyphs: 传感压伏出入站概况已连接存储服务器容可安流量当宽带功率上下行潮阳磁盘阵列正常未知在离线室内外温湿度网络日月用电瓦实时信息/!"%()+,-_.::°0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz

  - file: 'msyh.ttf'
    id: msyh_size_34 
    size: 34
    glyphs: 传感压伏出入站概况已连接存储服务器容可安流量当宽带功率上下行潮阳磁盘阵列正常未知在离线室内外温湿度网络日月用电瓦实时信息/!"%()+,-_.::°0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz


output:
  - platform: ledc
    pin: 32
    id: gpio_32_backlight_pwm

light:
  - platform: monochromatic
    output: gpio_32_backlight_pwm
    name: "Display Backlight"
    id: back_light
    restore_mode: ALWAYS_ON

display:
  - platform: ili9xxx
    model: ili9341
    data_rate: 80MHz
    update_interval: 1000ms
    cs_pin: 14
    dc_pin: 27
    reset_pin: 33
    rotation: 90
    lambda: |-

      it.line(0, 44, 320, 44, id(color_yellow));
      it.line(160, 44, 160, 240, id(color_yellow));
      it.line(0, 135, 320, 135, id(color_yellow));

      static int i = 1;
      i++;
      if ((i % 2) == 0)
        it.printf(160, 10, id(msyh_size_34), id(color_white), TextAlign::CENTER, ":"); 
      it.strftime(160, 12, id(msyh_size_34), id(color_white), TextAlign::CENTER, "%H %M", id(sntp_time).now()); 
      it.strftime(160, 35, id(msyh_size_14), id(color_white), TextAlign::CENTER, "%Y-%m-%d", id(sntp_time).now()); 

      it.printf(310, 3, id(msyh_size_14), id(color_green), TextAlign::RIGHT, "室内温湿度");
      it.printf(320, 24, id(msyh_size_14), id(color_white), TextAlign::RIGHT, "%.1f°C/%.1f%%", id(livingroom_temperature).state, id(livingroom_humidity).state);

      it.printf(5, 3, id(msyh_size_14), id(color_green), TextAlign::LEFT, "室外温湿度");
      it.printf(0, 24, id(msyh_size_14), id(color_white), TextAlign::LEFT, "%.1f°C/%.1f%%", id(outside_temperature).state, id(outside_humidity).state);


      it.printf(82, 53, id(msyh_size_14), id(color_green), TextAlign::CENTER, "实时网络概况"); 
      it.printf(10, 65, id(msyh_size_14), id(color_lightblue), TextAlign::LEFT, "上行流量:");
      it.printf(155, 65, id(msyh_size_14), id(color_white), TextAlign::RIGHT, "%.1f Mb/s", id(wan_up).state);
      it.printf(10, 82, id(msyh_size_14), id(color_lightblue), TextAlign::LEFT, "下行流量:");
      it.printf(155, 82, id(msyh_size_14), id(color_white), TextAlign::RIGHT, "%.1f Mb/s", id(wan_down).state);

      it.printf(10, 99, id(msyh_size_14), id(color_lightblue), TextAlign::LEFT, "VPN上行:");
      it.printf(155, 99, id(msyh_size_14), id(color_white), TextAlign::RIGHT, "%.1f Mb/s", id(vpn_up).state);
      it.printf(10, 116, id(msyh_size_14), id(color_lightblue), TextAlign::LEFT, "VPN下行:");
      it.printf(155, 116, id(msyh_size_14), id(color_white), TextAlign::RIGHT, "%.1f Mb/s", id(vpn_down).state);      

     
      it.printf(240, 53, id(msyh_size_14), id(color_green), TextAlign::CENTER, "实时用电概况");
      it.printf(180, 65, id(msyh_size_14), id(color_lightblue), TextAlign::LEFT, "实时电流:");
      it.printf(300, 65, id(msyh_size_14), id(color_white), TextAlign::RIGHT, "%.3f 安", id(current).state);            
      it.printf(180, 82, id(msyh_size_14), id(color_lightblue), TextAlign::LEFT, "实时功率:");
      it.printf(300, 82, id(msyh_size_14), id(color_white), TextAlign::RIGHT, "%.0f 瓦", id(apparent_power).state);
      it.printf(180, 99, id(msyh_size_14), id(color_lightblue), TextAlign::LEFT, "日用电量:");
      it.printf(300, 99, id(msyh_size_14), id(color_white), TextAlign::RIGHT, "%.1f 度", id(daily_energy).state);
      it.printf(180, 116, id(msyh_size_14), id(color_lightblue), TextAlign::LEFT, "月用电量:");
      it.printf(300, 116, id(msyh_size_14), id(color_white), TextAlign::RIGHT, "%.1f 度", id(monthly_energy).state);


      it.printf(82, 145, id(msyh_size_14), id(color_green), TextAlign::CENTER, "存储服务概况");       
      it.printf(10, 157, id(msyh_size_14), id(color_lightblue), TextAlign::LEFT, "容量/可用:");
      it.printf(155, 157, id(msyh_size_14), id(color_white), TextAlign::RIGHT, "%.2fT/%.2fT", id(total_size).state, id(free_space).state); 
      it.printf(10, 174, id(msyh_size_14), id(color_lightblue), TextAlign::LEFT, "磁盘阵列:");
      it.printf(155, 174, id(msyh_size_14), id(color_white), TextAlign::RIGHT, "%s", id(raid_status).state.c_str());
      it.printf(10, 191, id(msyh_size_14), id(color_lightblue), TextAlign::LEFT, "磁盘 1/2:");           
      it.printf(155, 191, id(msyh_size_14), id(color_white), TextAlign::RIGHT, "%s/%s", id(disk1).state.c_str(), id(disk2).state.c_str());
      it.printf(10, 208, id(msyh_size_14), id(color_lightblue), TextAlign::LEFT, "磁盘 3/4:");
      it.printf(155, 208, id(msyh_size_14), id(color_white), TextAlign::RIGHT, "%s/%s", id(disk3).state.c_str(), id(disk4).state.c_str());

评分

参与人数 1金钱 +16 收起 理由
sorrypqa + 16 高手,这是高手!

查看全部评分

回复

使用道具 举报

11

主题

123

帖子

3470

积分

论坛元老

Rank: 8Rank: 8

积分
3470
金钱
3347
HASS币
0
 楼主| 发表于 2024-1-29 10:16:21 | 显示全部楼层
QQ617250210 发表于 2024-1-29 09:59
提供个思路,我之前也遇到过,不过是花屏,最后原因是杜邦线接触不良导致的,你可以看看你的 ...

这问题早解决了.原因是i2c的线太长了,后来自己做了个PCB,把esp32一起做到显示屏接口板上就再也没出现问题了.
回复

使用道具 举报

20

主题

133

帖子

850

积分

高级会员

Rank: 4

积分
850
金钱
717
HASS币
0
发表于 2024-1-29 11:18:58 | 显示全部楼层

非常感情,楼主的分享。
在学习研究,看看能不能成功。
回复

使用道具 举报

20

主题

133

帖子

850

积分

高级会员

Rank: 4

积分
850
金钱
717
HASS币
0
发表于 2024-5-6 20:41:25 | 显示全部楼层
你好,楼主,请问一下,TFT屏幕,控制底色 显示 白色或黑色 ,怎样编写语句呢
it.fill(COLOR_BLACK);
it.fill (COLOR_WHITE);
是不是这样的呢
回复

使用道具 举报

20

主题

133

帖子

850

积分

高级会员

Rank: 4

积分
850
金钱
717
HASS币
0
发表于 2024-5-9 09:43:55 | 显示全部楼层

你好,楼主,请问一下,TFT屏幕,控制底色 显示 白色或黑色 ,怎样编写语句呢
it.fill(COLOR_BLACK);
it.fill (COLOR_WHITE);
是不是这样的呢
回复

使用道具 举报

6

主题

153

帖子

578

积分

高级会员

Rank: 4

积分
578
金钱
425
HASS币
0
发表于 2024-5-9 12:18:01 | 显示全部楼层
好贴,收藏学习了
总为浮云能避日,长安不见使人愁
回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-11-25 03:45 , Processed in 0.323340 second(s), 28 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表