ESP Multimeter - NÁVOD

www
Odpovědět
Uživatelský avatar
tiimsvk
Dárce - Donátor
Dárce - Donátor
Příspěvky: 800
Registrován: 06. květen 2021, 07:03
Dal poděkování: 72 poděkování
Dostal poděkování: 65 poděkování

ESP Multimeter - NÁVOD

Příspěvek od tiimsvk »

Ahojte podarilo sa mi vyhotoviť multimeter s grafickým displejom.

ZARIADENIA A SÚČIASTKY:
- ESP32 wrover
- ina219 (neskôr nahradim ina226)
- ADS1115
- XH-M401
- LM7805
- ili9341 320x240

KÓD:

Kód: Vybrat vše

#-------------------------------------------
# SUBTITUTIONS - basic definitions and description of the device
#-------------------------------------------
substitutions:
  friendly_name: ESP-Multimeter
  device_name: esp-multimeter
  created_by: "StudioTiiM 2022"
  version: "1.0"
  device_description: "Current, Voltage, Power and ADC monitor"
#-------------------------------------------
# COMPONENT AND RATING 

# input max 34V 
# XH-M401 1.25-36V 8A out fuse 7.5A (out eneregy tester LCD 150V 20A)
# LM7805CV 5V 1A
# ESP32 WROVER32; ADS1115 4-channal ADC; ina219 current and voltage measurement; ili9341 320x240;
# esp32 5v out PPTC PolySwitch Self-Recovery Fuse 1.1A
# ili9341
#-------------------------------------------
  
#-------------------------------------------
# Define pins
#-------------------------------------------
  status_led_pin: GPIO19

  i2c_scl: GPIO22
  i2c_sda: GPIO21

  spi_clk: GPIO14
  spi_mosi: GPIO13
  spi_miso: GPIO12

  lcd_cs: GPIO26
  lcd_dc: GPIO27
  lcd_led: GPIO32
  lcd_reset: GPIO33

  adc0_pin: A0_GND
  adc1_pin: A1_GND
  adc2_pin: A2_GND
  adc3_pin: A3_GND

#-------------------------------------------
# ESP - main settings
#-------------------------------------------
esphome:
  name: oscilloscope

esp32:
  board: esp32dev
  framework:
    type: arduino

logger:
api:
ota:
  password: !secret ota_pass

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  ap:
    ssid: "$device_name Hotspot"
    password: "passoscilloscope"

captive_portal:

#-------------------------------------------
# BUS SETTINGS
#-------------------------------------------
spi:
  clk_pin: "$spi_clk"
  mosi_pin: "$spi_mosi"
  miso_pin: "$spi_miso"

i2c:
 sda: "$i2c_scl"
 scl: "$i2c_sda"

ads1115:
  - address: 0x48

#-------------------------------------------
# STATUS LED
# led resistor 220R
#-------------------------------------------
status_led:
  pin: "$status_led_pin"

#-------------------------------------------
# SENSORS
#-------------------------------------------
sensor:
#-------------------------------------------
# Wifi signal component
#-------------------------------------------
  - platform: wifi_signal
    name: "${friendly_name} Signal"
    id: "signal_id"
    update_interval: 60s

#-------------------------------------------
# ina219 max 26V 3.5A
#-------------------------------------------
  - platform: ina219
    address: 0x41
    shunt_resistance: 0.1 ohm
    current:
      name: "$friendly_name Current"
      id: current
      accuracy_decimals: 2
      unit_of_measurement: "mA"
      filters:
        - multiply: 1000
    power:
      name: "$friendly_name Power"
      id: power
    bus_voltage:
      name: "$friendly_name Voltage"
      id: voltage
    shunt_voltage:
      name: "$friendly_name Shunt Voltage"
    max_voltage: 32.0V
    max_current: 3.2A
    update_interval: 300ms

#-------------------------------------------
# Internal temerature
#-------------------------------------------
  - platform: template
    id: temp
    name: temperature
    lambda: return temperatureRead();
    unit_of_measurement: "°C"
    accuracy_decimals: 1
    entity_category: diagnostic

#-------------------------------------------
# ADS1115 4-channal ADC
#-------------------------------------------
  - platform: ads1115
    multiplexer: 'A0_GND'
    gain: 6.144
    name: "ADS1115 Channel A0-GND"
    update_interval: 1s
    id: ads_a0

  - platform: ads1115
    multiplexer: 'A1_GND'
    gain: 4.096
    name: "ADS1115 Channel A0-GND"
    update_interval: 1s
    id: ads_a1

  - platform: ads1115
    multiplexer: 'A2_GND'
    gain: 2.048 
    name: "ADS1115 Channel A0-GND"
    update_interval: 1s
    id: ads_a2

  - platform: ads1115
    multiplexer: 'A3_GND'
    gain: 1.024 
    name: "ADS1115 Channel A0-GND"
    update_interval: 1s
    id: ads_a3

#-------------------------------------------
# GRAPH
#-------------------------------------------
graph:
  # Show bare-minimum auto-ranged graph
  - id: ina_graph_current
    duration: 15s
    x_grid: 1s
    y_grid: 0.1     # 0.1mA/div
    width: 140
    height: 190
    traces:
      - sensor: current
        line_type: SOLID
        line_thickness: 1
        color: color_orange

  - id: ina_graph_voltage
    duration: 15s
    x_grid: 1s
    y_grid: 1.0     # 1.0V/div
    width: 150
    height: 80
    traces:
      - sensor: voltage
        line_type: SOLID
        line_thickness: 1
        color: color_azure

  - id: adc_graph
    duration: 10s
    x_grid: 1s
    y_grid: 1.0     # 1.0V/div
    width: 150
    height: 70
    traces:
      - sensor: ads_a0
        line_type: SOLID
        line_thickness: 1
        color: color_orange

      - sensor: ads_a1
        line_type: SOLID
        line_thickness: 1
        color: color_blue

      - sensor: ads_a2
        line_type: SOLID
        line_thickness: 1
        color: color_red

      - sensor: ads_a3
        line_type: SOLID
        line_thickness: 1
        color: color_azure

#-------------------------------------------
# FONTS
#-------------------------------------------
font:
  - file: 'font_rg.ttf'
    id: font1
    size: 18

  - file: 
      type: gfonts
      family: "Ubuntu Mono"
      weight: bold
    id: font1_bold
    size: 20

  - file: 'font_rg.ttf'
    id: font2
    size: 14

  - file: 'fonts/icons.ttf'
    id: fonticon
    size: 20 
    glyphs: [
      "\U000F08BF", # no wifi
      "\U000F08BC", # wifi low
      "\U000F08BD", # mwifi middle
      "\U000F08BE", # wifi high
      ]

#-------------------------------------------
# COLORS
#-------------------------------------------
color:
  - id: color_orange
    red: 100%
    green: 50%
    blue: 0%

  - id: color_blue
    red: 27%
    green: 45%
    blue: 62%

  - id: color_red
    red: 55%
    green: 29%
    blue: 59%

  - id: color_azure
    red: 0%
    green: 79%
    blue: 80%

  - id: color_white
    red: 88%
    green: 88%
    blue: 88%

  - id: color_gray
    red: 50%
    green: 50%
    blue: 50%

#-------------------------------------------
# DISPLAY
#-------------------------------------------
display:
  - platform: ili9341
    id: oled
    model: TFT 2.4
    cs_pin: "$lcd_cs"
    dc_pin: "$lcd_dc"
    led_pin: "$lcd_led"
    reset_pin: "$lcd_reset"
    rotation: 270

    lambda: |-
      //--------------------------------------------------------------------------
      // TITLE
      //--------------------------------------------------------------------------
      it.print(0, 0, id(font1_bold), "MULTIMETER");

      //--------------------------------------------------------------------------
      // WIFI SIGNAL SENSOR mdi print
      //--------------------------------------------------------------------------
      int signal_wifi = int(id(signal_id).state);  //convert state to int
          
      if (signal_wifi < 0 && signal_wifi >= -60) {
        it.printf(322, 4, id(fonticon), TextAlign::TOP_RIGHT, "\U000F08BE");
      }
      if (signal_wifi < -60 && signal_wifi >= -75) {
        it.printf(322, 4, id(fonticon), TextAlign::TOP_RIGHT, "\U000F08BD");
      }
      if (signal_wifi < -75 && signal_wifi >= -100) {
        it.printf(322, 4, id(fonticon), TextAlign::TOP_RIGHT, "\U000F08BC");
      }
      else {
        it.printf(322, 4, id(fonticon), TextAlign::TOP_RIGHT, "\U000F08BF");
      }

      //--------------------------------------------------------------------------
      // LINE
      //--------------------------------------------------------------------------
      it.line(0, 22, 320, 22);

      //--------------------------------------------------------------------------
      // VOLTAGE
      //--------------------------------------------------------------------------
      it.print(10, 25, id(font1), "VOLTAGE 1V/15s");
      it.print(0, 80, id(font1), "V");
      it.printf(134, 24, id(font1), "%.2fV", id(voltage).state);
      it.graph(10, 50, id(ina_graph_voltage), color_gray);

      //--------------------------------------------------------------------------
      // CURRENT
      //--------------------------------------------------------------------------
      it.print(180, 24, id(font1), "CURRENT 0.1mA/15s");
      it.print(170, 120, id(font1), "mA");
      it.printf(285, 24, id(font1), "%.2fA", id(current).state);
      it.graph(180, 50, id(ina_graph_current), color_gray);

      //--------------------------------------------------------------------------
      // ADC
      //--------------------------------------------------------------------------
      it.print(10, 140, id(font1), "ADC 1V/15s");
      it.print(0, 180, id(font1), "V");
      it.printf(90, 130, id(font1), "%.3fV% .3fV%", id(ads_a0).state, id(ads_a1).state);
      it.printf(90, 150, id(font1), "%.3fV% .3fV%", id(ads_a2).state, id(ads_a3).state);
      it.graph(10, 170, id(adc_graph), color_gray);
      
      
PREVEDENIE:
20221216_145004.jpg
Samozrejme je ešte čo vylepšovať ale takto zatial prvá verzia.

Skúšal som merať esp8266 aj v deep sleep a minimalný prúd zmeria na 4,8mA ... ak máte niekto modul,ktorý dokáže merať presnejšie a menšie hodnoty tak sem snim :)

Uživatelský avatar
tiimsvk
Dárce - Donátor
Dárce - Donátor
Příspěvky: 800
Registrován: 06. květen 2021, 07:03
Dal poděkování: 72 poděkování
Dostal poděkování: 65 poděkování

Re: ESP Multimeter - NÁVOD

Příspěvek od tiimsvk »

Ahojte aktualizoval som kód:

Kód: Vybrat vše

#-------------------------------------------
# SUBTITUTIONS - basic definitions and description of the device
#-------------------------------------------
substitutions:
  friendly_name: ESP-Multimeter
  device_name: esp-multimeter
  created_by: "StudioTiiM 2022-2023"
  device_description: "Current, Voltage, Power and ADC monitor"
#-------------------------------------------
# COMPONENT AND RATING 

# input max 34V 
# XH-M401 1.25-36V 8A out fuse 7.5A (out eneregy tester LCD 150V 20A)
# LM7805CV 5V 1A
# ESP32 WROVER32; ADS1115 4-channal ADC; ina219 current and voltage measurement; ili9341 320x240;
# esp32 5v out PPTC PolySwitch Self-Recovery Fuse 1.1A
#-------------------------------------------
  
#-------------------------------------------
# Define pins
#-------------------------------------------
  status_led_pin: GPIO19

  i2c_scl: GPIO22
  i2c_sda: GPIO21

  spi_clk: GPIO14
  spi_mosi: GPIO13
  spi_miso: GPIO12

  lcd_cs: GPIO26
  lcd_dc: GPIO27
  lcd_led: GPIO32
  lcd_reset: GPIO33

  adc0_pin: A0_GND
  adc1_pin: A1_GND
  adc2_pin: A2_GND
  adc3_pin: A3_GND

#-------------------------------------------
# ESP - main settings
#-------------------------------------------
preferences:
  flash_write_interval: 10min  # reduce writings to the flash to preserve its health, adjust it on demand
  
esphome:
  name: oscilloscope
  project:
    name: "studiotiim.assistant"
    version: 2023.5.1.0.1

esp32:
  board: esp32dev
  framework:
    type: arduino

logger:
api:
ota:
  password: !secret ota_pass

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  ap:
    ssid: "$device_name Hotspot"
    password: "passoscilloscope"

captive_portal:

#-------------------------------------------
# BUS SETTINGS
#-------------------------------------------
spi:
  clk_pin: "$spi_clk"
  mosi_pin: "$spi_mosi"
  miso_pin: "$spi_miso"

i2c:
 sda: "$i2c_scl"
 scl: "$i2c_sda"

ads1115:
  - address: 0x48

#-------------------------------------------
# STATUS LED
# led resistor 220R
#-------------------------------------------
status_led:
  pin: "$status_led_pin"

#-------------------------------------------
# SENSORS
#-------------------------------------------
sensor:
#-------------------------------------------
# Wifi signal component
#-------------------------------------------
  - platform: wifi_signal
    name: "${friendly_name} Signal"
    id: "signal_id"
    update_interval: 60s

#-------------------------------------------
# ina219 max 26V 3.5A
#-------------------------------------------
  - platform: ina219
    address: 0x41
    shunt_resistance: 0.1 ohm
    current:
      name: "$friendly_name Current"
      id: current
      accuracy_decimals: 2
      unit_of_measurement: "mA"
      filters:
        - multiply: 1000
    power:
      name: "$friendly_name Power"
      id: power
      internal: True
    bus_voltage:
      name: "$friendly_name Voltage"
      id: voltage
    shunt_voltage:
      name: "$friendly_name Shunt Voltage"
      internal: True
    max_voltage: 32.0V
    max_current: 3.2A
    update_interval: 150ms

#-------------------------------------------
# Internal temerature
#-------------------------------------------
  - platform: template
    id: temp
    name: temperature
    lambda: return temperatureRead();
    unit_of_measurement: "°C"
    accuracy_decimals: 1
    entity_category: diagnostic

#-------------------------------------------
# ADS1115 4-channal ADC
#-------------------------------------------
  - platform: ads1115
    multiplexer: 'A0_GND'
    gain: 6.144
    name: "ADS1115 Channel A0-GND"
    update_interval: 1s
    id: ads_a0

  - platform: ads1115
    multiplexer: 'A1_GND'
    gain: 4.096
    name: "ADS1115 Channel A1-GND"
    update_interval: 1s
    id: ads_a1

  - platform: ads1115
    multiplexer: 'A2_GND'
    gain: 2.048 
    name: "ADS1115 Channel A2-GND"
    update_interval: 1s
    id: ads_a2

  - platform: ads1115
    multiplexer: 'A3_GND'
    gain: 1.024 
    name: "ADS1115 Channel A3-GND"
    update_interval: 1s
    id: ads_a3

# Define a PWM output on the ESP32
output:
  - platform: ledc
    pin: "$lcd_led"
    id: backlight_pwm

# Define a monochromatic, dimmable light for the backlight
light:
  - platform: monochromatic
    output: backlight_pwm
    name: "Display Backlight"
    id: back_light
    restore_mode: ALWAYS_ON

#-------------------------------------------
# GRAPH
#-------------------------------------------
graph:
  # Show bare-minimum auto-ranged graph
  - id: ina_graph_current
    duration: 15s
    x_grid: 2s
    y_grid: 0.1     # 0.1mA/div
    width: 140
    height: 190
    traces:
      - sensor: current
        line_type: SOLID
        line_thickness: 1
        color: color_orange

  - id: ina_graph_voltage
    duration: 15s
    x_grid: 2s
    y_grid: 1.0     # 1.0V/div
    width: 150
    height: 80
    traces:
      - sensor: voltage
        line_type: SOLID
        line_thickness: 1
        color: color_azure

  - id: adc_graph
    duration: 10s
    x_grid: 1s
    y_grid: 1.0     # 1.0V/div
    width: 150
    height: 70
    traces:
      - sensor: ads_a0
        line_type: SOLID
        line_thickness: 1
        color: color_orange

      - sensor: ads_a1
        line_type: SOLID
        line_thickness: 1
        color: color_blue

      - sensor: ads_a2
        line_type: SOLID
        line_thickness: 1
        color: color_red

      - sensor: ads_a3
        line_type: SOLID
        line_thickness: 1
        color: color_azure

#-------------------------------------------
# FONTS
#-------------------------------------------
font:
  - file: 'fonts/font_rg.ttf'
    id: font1
    size: 17

  - file: 
      type: gfonts
      family: "Ubuntu Mono"
      weight: bold
    id: font1_bold
    size: 20

  - file: 'fonts/font_rg.ttf'
    id: font2
    size: 14

  - file: 'fonts/icons.ttf'
    id: fonticon
    size: 20 
    glyphs: [
      "\U000F08BF", # no wifi
      "\U000F08BC", # wifi low
      "\U000F08BD", # mwifi middle
      "\U000F08BE", # wifi high
      ]

#-------------------------------------------
# COLORS
#-------------------------------------------
color:
  - id: color_orange
    red: 100%
    green: 50%
    blue: 0%

  - id: color_blue
    red: 27%
    green: 45%
    blue: 62%

  - id: color_red
    red: 55%
    green: 29%
    blue: 59%

  - id: color_azure
    red: 0%
    green: 79%
    blue: 80%

  - id: color_white
    red: 88%
    green: 88%
    blue: 88%

  - id: color_gray
    red: 50%
    green: 50%
    blue: 50%

#-------------------------------------------
# DISPLAY
#-------------------------------------------
display:
  - platform: ili9xxx
    id: oled
    model: TFT 2.4
    cs_pin: "$lcd_cs"
    dc_pin: "$lcd_dc"

    reset_pin: "$lcd_reset"
    rotation: 270

    lambda: |-
      //--------------------------------------------------------------------------
      // TITLE
      //--------------------------------------------------------------------------
      it.print(0, 0, id(font1_bold), "MULTIMETER");

      //--------------------------------------------------------------------------
      // WIFI SIGNAL SENSOR mdi print
      //--------------------------------------------------------------------------
      int signal_wifi = int(id(signal_id).state);  //convert state to int
          
      if (signal_wifi < 0 && signal_wifi >= -60) {
        it.printf(322, 4, id(fonticon), TextAlign::TOP_RIGHT, "\U000F08BE");
      }
      if (signal_wifi < -60 && signal_wifi >= -75) {
        it.printf(322, 4, id(fonticon), TextAlign::TOP_RIGHT, "\U000F08BD");
      }
      if (signal_wifi < -75 && signal_wifi >= -100) {
        it.printf(322, 4, id(fonticon), TextAlign::TOP_RIGHT, "\U000F08BC");
      }
      else {
        it.printf(322, 4, id(fonticon), TextAlign::TOP_RIGHT, "\U000F08BF");
      }

      //--------------------------------------------------------------------------
      // LINE
      //--------------------------------------------------------------------------
      it.line(0, 22, 320, 22);

      //--------------------------------------------------------------------------
      // VOLTAGE
      //--------------------------------------------------------------------------
      it.print(10, 25, id(font1), "VOLTAGE 1V/15s");
      it.print(0, 80, id(font1), "V");
      it.printf(134, 24, id(font1), "%.2fV", id(voltage).state);
      it.graph(10, 50, id(ina_graph_voltage), color_gray);

      //--------------------------------------------------------------------------
      // CURRENT
      //--------------------------------------------------------------------------
      it.print(180, 24, id(font1), "CURRENT 0.1mA/15s");
      it.print(165, 120, id(font1), "mA");
      it.printf(285, 24, id(font1), "%.2fmA", id(current).state);
      it.graph(180, 50, id(ina_graph_current), color_gray);

      //----------------------------------------------A----------------------------
      // ADC
      //--------------------------------------------------------------------------
      it.print(10, 140, id(font1), "ADC 1V/15s");
      it.print(0, 180, id(font1), "V");
      it.printf(90, 130, id(font1), "%.3fV% .3fV%", id(ads_a0).state, id(ads_a1).state);
      it.printf(90, 145, id(font1), "%.3fV% .3fV%", id(ads_a2).state, id(ads_a3).state);
      it.graph(10, 170, id(adc_graph), color_gray);
Kde som upravil nejaké veci po zmene v esphome + dal som aktualizáciu údajov na 150ms a esp to stále zvláda odosielať tak ma napadlo.

Aká je najväčšia rýchlosť odosielania dát cez esphome -> wifi -> haos. resp. Ako rychlo by dokázal aktualizovať dáta na grafe a odosielanie by bolo v menšich intervaloch?

Odpovědět

Zpět na „ESPHome“