2024年11月22日星期五 上午12:32:54

超声波测距传感器 - HC-SR04 via ESPHome

4 个月 前
#39370 引用
超声波测距传感器

超声波测距传感器HC-SR04
https://tasmota.github.io/docs/HC-SR04/




https://esphome.io/components/sensor/ultrasonic.html
0
4 个月 前
#39371 引用


超声波测距值最远就到0.6米左右
超聲波測距傳感器最遠5米都還OK耶,精度比不上激光測距,勝在便宜
0
4 个月 前
#39372 引用
{"Time":"2019-01-01T22:42:35","SR04":{"Distance":16.754}}
0
3 个月 前
#44542 引用
Where to 编译?
0
1 个月 前
#46572 引用
Esp32  ESP-WROOM-32
https://item.taobao.com/item.htm?_u=s1ed9uj180a&id=564776492972&spm=a1z09.2.0.0.5bbd2e8daYVsoO


HC-SR04
https://item.taobao.com/item.htm?_u=s1ed9uj5b03&id=37984321649&spm=a1z09.2.0.0.5bbd2e8daYVsoO
0
1 个月 前
#46574 引用

# Example configuration entry
sensor:
  - platform: ultrasonic
    trigger_pin: D1
    echo_pin: D2
    name: "Ultrasonic Sensor"


https://esphome.io/components/sensor/ultrasonic.html


sensor:
  - platform: ultrasonic
    trigger_pin: GPIO3
    echo_pin:  GPIO1
    name: "Ultrasonic Sensor"
    update_interval: 5s
    filters:
      - multiply: 4
      - lambda: return 3 - x;  

https://bbs.hassbian.com/forum.php?mod=redirect&goto=findpost&ptid=18888&pid=499892




sensor:
- platform: ultrasonic
   trigger_pin: D1
   echo_pin: D2
   name: 'My Ultrasonic Sensor'
   update_interval: 1s
   accuracy_decimals: 2
   unit_of_measurement: cm



run ok
sensor:
  - platform: ultrasonic
    trigger_pin: GPIO12
    echo_pin:  GPIO13
    name: "Ultrasonic Sensor"
    update_interval: 1s
    accuracy_decimals: 2
    unit_of_measurement: m


board: esp32dev; 
framework: espidf;
platform: platformio/[email protected]
0
1 个月 前
#46575 引用
Download esp32-bluetooth-proxy-58d270.yaml  logs

首先是自动下载和安装必要的编译环境


Downloading & Installing platformio/framework-espidf @ ~3.40407.0
Downloading & Installing platformio/tool-cmake @ ~3.16.0



INFO ESPHome 2024.9.1
INFO Reading configuration /config/esphome/esp32-bluetooth-proxy-58d270.yaml...
INFO Generating C++ source...
INFO Compiling app...
Processing esp32-bluetooth-proxy-58d270 (board: esp32dev; framework: espidf; platform: platformio/[email protected])
--------------------------------------------------------------------------------
Tool Manager: Installing espressif/toolchain-esp32ulp @ 2.35.0-20220830
INFO Installing espressif/toolchain-esp32ulp @ 2.35.0-20220830
Downloading  [############################--------]   80%  00:01:08

...
Tool Manager: Installing platformio/tool-cmake @ ~3.16.0
INFO Installing platformio/tool-cmake @ ~3.16.0
Downloading  [####################################]  100%          
Unpacking  [####################################]  100%          
Tool Manager: [email protected] has been installed!
INFO [email protected] has been installed!
0
1 个月 前
#46581 引用
生成了
esp32-bluetooth-proxy-58d270.ota.bin
0
1 个月 前
#46582 引用
[code]
INFO ESPHome 2024.9.1
INFO Reading configuration /config/esphome/esp32-bluetooth-proxy-58d270.yaml...
INFO Generating C++ source...
INFO Compiling app...
Processing esp32-bluetooth-proxy-58d270 (board: esp32dev; framework: espidf; platform: platformio/[email protected])
--------------------------------------------------------------------------------
Tool Manager: Installing platformio/tool-cmake @ ~3.16.0
INFO Installing platformio/tool-cmake @ ~3.16.0
Downloading  [####################################]  100%          
Unpacking  [####################################]  100%          
Tool Manager: [email protected] has been installed!
INFO [email protected] has been installed!
Tool Manager: Installing platformio/tool-ninja @ ^1.7.0
INFO Installing platformio/tool-ninja @ ^1.7.0
Downloading  [####################################]  100%          
Unpacking  [####################################]  100%
Tool Manager: [email protected] has been installed!
INFO [email protected] has been installed!
Library Manager: Installing esphome/noise-c @ 0.1.6
INFO Installing esphome/noise-c @ 0.1.6
Unpacking  [####################################]  100%
Library Manager: [email protected] has been installed!
INFO [email protected] has been installed!
Library Manager: Resolving dependencies...
INFO Resolving dependencies...
Library Manager: Installing esphome/libsodium @ 1.10018.4
INFO Installing esphome/libsodium @ 1.10018.4
Unpacking  [####################################]  100%
Library Manager: [email protected] has been installed!
INFO [email protected] has been installed!
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
- framework-espidf @ 3.40407.240606 (4.4.7)
- tool-cmake @ 3.16.4
- tool-ninja @ 1.7.1
- toolchain-esp32ulp @ 2.35.0-20220830
- toolchain-xtensa-esp32 @ 8.4.0+2021r2-patch5
Creating a new virtual environment for IDF Python dependencies
Installing ESP-IDF's Python dependencies
Collecting urllib3<2
  Downloading urllib3-1.26.20-py2.py3-none-any.whl (144 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 144.2/144.2 kB 15.1 kB/s eta 0:00:00
Collecting cryptography<35.0.0,>=2.1.4
  Downloading cryptography-3.4.8-cp36-abi3-manylinux_2_24_x86_64.whl (3.0 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.0/3.0 MB 270.1 kB/s eta 0:00:00
Collecting future>=0.18.3
  Downloading future-1.0.0-py3-none-any.whl (491 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 491.3/491.3 kB 1.7 MB/s eta 0:00:00
Collecting pyparsing<2.4.0,>=2.0.3
  Downloading pyparsing-2.3.1-py2.py3-none-any.whl (61 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 61.8/61.8 kB 2.4 MB/s eta 0:00:00
Collecting kconfiglib~=13.7.1
  Downloading kconfiglib-13.7.1-py2.py3-none-any.whl (145 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 145.7/145.7 kB 2.2 MB/s eta 0:00:00
Collecting idf-component-manager~=1.0
  Downloading idf_component_manager-1.5.3-py2.py3-none-any.whl (161 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 161.3/161.3 kB 2.4 MB/s eta 0:00:00
Collecting cffi>=1.12
  Downloading cffi-1.17.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (467 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 467.2/467.2 kB 1.9 MB/s eta 0:00:00
Collecting packaging
  Downloading packaging-24.1-py3-none-any.whl (53 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 54.0/54.0 kB 1.9 MB/s eta 0:00:00
Collecting requests<3
  Downloading requests-2.32.3-py3-none-any.whl (64 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 64.9/64.9 kB 2.7 MB/s eta 0:00:00
Collecting requests-file<2
  Downloading requests_file-1.5.1-py2.py3-none-any.whl (3.7 kB)
Collecting requests-toolbelt
  Downloading requests_toolbelt-1.0.0-py2.py3-none-any.whl (54 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 54.5/54.5 kB 2.9 MB/s eta 0:00:00
Collecting schema<=0.7.5
  Downloading schema-0.7.5-py2.py3-none-any.whl (17 kB)
Collecting six
  Downloading six-1.16.0-py2.py3-none-any.whl (11 kB)
Collecting tqdm<5
  Dow
0
1 个月 前
#46590 引用
debug logs

INFO ESPHome 2024.9.1
INFO Reading configuration /config/esphome/esp32-bluetooth-proxy-58d270.yaml...
WARNING GPIO12 is a strapping PIN and should only be used for I/O with care.
Attaching external pullup/down resistors to strapping pins can cause unexpected failures.
See https://esphome.io/guides/faq.html#why-am-i-getting-a-warning-about-strapping-pins
INFO Starting log output from 192.168.2.123 using esphome API
INFO Successfully connected to esp32-bluetooth-proxy-58d270 @ 192.168.2.123 in 0.158s
INFO Successful handshake with esp32-bluetooth-proxy-58d270 @ 192.168.2.123 in 0.321s
[02:51:57][I][app:100]: ESPHome version 2024.9.1 compiled on Sep 30 2024, 02:40:04
[02:51:57][C][wifi:600]: WiFi:
[02:51:57][C][wifi:428]:   Local MAC: D0:EF:76:58:D2:70
[02:51:57][C][wifi:433]:   SSID: [redacted]
[02:51:57][C][wifi:436]:   IP Address: 192.168.2.123
[02:51:57][C][wifi:440]:   BSSID: [redacted]
[02:51:57][C][wifi:441]:   Hostname: 'esp32-bluetooth-proxy-58d270'
[02:51:57][C][wifi:443]:   Signal strength: -70 dB ▂▄▆█
[02:51:57][C][wifi:447]:   Channel: 6
[02:51:57][C][wifi:448]:   Subnet: 255.255.255.0
[02:51:57][C][wifi:449]:   Gateway: 192.168.2.1
[02:51:57][C][wifi:450]:   DNS1: 192.168.1.1
[02:51:57][C][wifi:451]:   DNS2: 192.168.2.1
[02:51:57][C][logger:185]: Logger:
[02:51:57][C][logger:186]:   Level: DEBUG
[02:51:57][C][logger:188]:   Log Baud Rate: 115200
[02:51:58][C][logger:189]:   Hardware UART: UART0
[02:51:58][C][ultrasonic.sensor:045]:   Unit of Measurement: 'm'
[02:51:58][C][ultrasonic.sensor:045]:   Accuracy Decimals: 2
[02:51:58][C][ultrasonic.sensor:045]:   Icon: 'mdi:arrow-expand-vertical'
[02:51:58][C][ultrasonic.sensor:046]:   Echo Pin: GPIO13
[02:51:58][C][esp32_ble_tracker:658]:   Scan Window: 30.0 ms
[02:51:58][C][mdns:116]: mDNS:
[02:51:58][D][ultrasonic.sensor:040]: 'HC-SR04 Ultrasonic Distance Sensor' - Got distance: 0.525 m
[02:51:58][D][sensor:094]: 'HC-SR04 Ultrasonic Distance Sensor': Sending state 0.52548 m with 2 decimals of accuracy
[02:51:59][D][ultrasonic.sensor:040]: 'HC-SR04 Ultrasonic Distance Sensor' - Got distance: 0.530 m
[02:51:59][D][sensor:094]: 'HC-SR04 Ultrasonic Distance Sensor': Sending state 0.52959 m with 2 decimals of accuracy

0