From 35c2ffc74b6efd75ee6049009b15da337d750a5a Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 22 Aug 2025 04:25:56 +0000 Subject: [PATCH 1/4] [m5stack-atom-echo] Replace demo with sound level meter --- boards/m5stack-atom-echo/demo.yaml | 57 +++++++++++++----------------- 1 file changed, 24 insertions(+), 33 deletions(-) diff --git a/boards/m5stack-atom-echo/demo.yaml b/boards/m5stack-atom-echo/demo.yaml index 5247fb5..a4fb5f4 100644 --- a/boards/m5stack-atom-echo/demo.yaml +++ b/boards/m5stack-atom-echo/demo.yaml @@ -1,43 +1,34 @@ # Copyright 2025 Vinicius Fortuna -# SPDX-License-Identifier: Apache-2.0 +# SPDX-License-Identifier: Apache-2.0 -# This demo exercises the button, LED, IR transmitter, speaker and microphone. -# When the button is pressed, it will: -# - Toggle the LED -# - Send an IR command -# - Play a tone on the speaker -# The microphone is used by the VAD sensor, which logs when it detects speech. +# This demo exercises the microphone as an Analog Sound Level Meter. +# It continuously measures the ambient noise level and sets the light +# brightness to match the sound level. packages: board: !include ./board.yaml esphome: - name: board-demo - friendly_name: Board Demo + name: sound-level-meter + friendly_name: Sound Level Meter logger: -binary_sensor: - - id: !extend echo_button - on_release: - - light.toggle: - id: echo_led - transition_length: 0.5s - - remote_transmitter.transmit_nec: - address: 0x1234 - command: 0x5678 - - rtttl.play: - id: rtttl_player - rtttl: scale_up:d=32,o=5,b=100:c,c#,d#,e,f#,g#,a#,b - # Work around RTTTL player getting stuck after first play. - # See https://github.com/esphome/esphome/issues/10312 - - lambda: |- - id(rtttl_player).enable_loop(); - -rtttl: - - id: rtttl_player - speaker: echo_speaker - gain: 0.3 - on_finished_playback: - then: - - logger.log: Finished playing RTTTL tune. +sensor: + - platform: sound_level + microphone: echo_microphone + id: sound_level_sensor + passive: false + measurement_duration: 50ms + rms: + name: "Sound Level" + unit_of_measurement: "%" + accuracy_decimals: 1 + filters: + - multiply: 100 + on_value: + then: + - light.turn_on: + id: echo_led + # The sensor value is from 0.0 to 1.0. + brightness: !lambda "return x / 100.0;" From 1419fbaebaf39a8f185d83a97669e6a2d2b6bee8 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 22 Aug 2025 04:39:50 +0000 Subject: [PATCH 2/4] [m5stack-atom-echo] Replace demo with sound level meter --- boards/m5stack-atom-echo/demo.yaml | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/boards/m5stack-atom-echo/demo.yaml b/boards/m5stack-atom-echo/demo.yaml index a4fb5f4..1009320 100644 --- a/boards/m5stack-atom-echo/demo.yaml +++ b/boards/m5stack-atom-echo/demo.yaml @@ -22,13 +22,18 @@ sensor: measurement_duration: 50ms rms: name: "Sound Level" - unit_of_measurement: "%" - accuracy_decimals: 1 - filters: - - multiply: 100 on_value: then: - light.turn_on: id: echo_led - # The sensor value is from 0.0 to 1.0. - brightness: !lambda "return x / 100.0;" + brightness: !lambda |- + // The sound level is in dB, from approx -80 (quiet) to 0 (loud). + // Map it to a brightness from 0.0 to 1.0. + // We'll use a range of -60 to 0 dB. + const float db_min = -60.0; + const float db_max = 0.0; + float brightness = (x - db_min) / (db_max - db_min); + // Clamp to the valid range + if (brightness < 0.0) brightness = 0.0; + if (brightness > 1.0) brightness = 1.0; + return brightness; From b062e6e3d3c0a4dcf67241d7f78f0bfa0300be55 Mon Sep 17 00:00:00 2001 From: Vinicius Fortuna Date: Fri, 22 Aug 2025 01:23:34 -0400 Subject: [PATCH 3/4] Improve --- boards/m5stack-atom-echo/demo.yaml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/boards/m5stack-atom-echo/demo.yaml b/boards/m5stack-atom-echo/demo.yaml index 1009320..f3183fd 100644 --- a/boards/m5stack-atom-echo/demo.yaml +++ b/boards/m5stack-atom-echo/demo.yaml @@ -14,6 +14,12 @@ esphome: logger: +microphone: + - id: !extend echo_microphone + # Without this, the sound level is squished in a narrow range + # aroung -30 dB. + correct_dc_offset: true + sensor: - platform: sound_level microphone: echo_microphone @@ -31,7 +37,7 @@ sensor: // Map it to a brightness from 0.0 to 1.0. // We'll use a range of -60 to 0 dB. const float db_min = -60.0; - const float db_max = 0.0; + const float db_max = -25.0; float brightness = (x - db_min) / (db_max - db_min); // Clamp to the valid range if (brightness < 0.0) brightness = 0.0; From cb644bc80ba272f12b807824e2083bb4eb8351b3 Mon Sep 17 00:00:00 2001 From: Vinicius Fortuna Date: Fri, 22 Aug 2025 01:51:32 -0400 Subject: [PATCH 4/4] Add demo --- boards/m5stack-atom-echo/demo.yaml | 34 +++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/boards/m5stack-atom-echo/demo.yaml b/boards/m5stack-atom-echo/demo.yaml index f3183fd..e857988 100644 --- a/boards/m5stack-atom-echo/demo.yaml +++ b/boards/m5stack-atom-echo/demo.yaml @@ -1,5 +1,5 @@ # Copyright 2025 Vinicius Fortuna -# SPDX-License-Identifier: Apache-2.0 +# SPDX-License-Identifier: Apache-2.0 # This demo exercises the microphone as an Analog Sound Level Meter. # It continuously measures the ambient noise level and sets the light @@ -9,8 +9,8 @@ packages: board: !include ./board.yaml esphome: - name: sound-level-meter - friendly_name: Sound Level Meter + name: board-demo + friendly_name: Board Demo logger: @@ -21,9 +21,9 @@ microphone: correct_dc_offset: true sensor: - - platform: sound_level + - id: sound_level_sensor + platform: sound_level microphone: echo_microphone - id: sound_level_sensor passive: false measurement_duration: 50ms rms: @@ -43,3 +43,27 @@ sensor: if (brightness < 0.0) brightness = 0.0; if (brightness > 1.0) brightness = 1.0; return brightness; + +rtttl: + - id: rtttl_player + speaker: echo_speaker + gain: 0.3 + on_finished_playback: + then: + - logger.log: Finished playing RTTTL tune. + +binary_sensor: + - id: !extend echo_button + on_release: + - remote_transmitter.transmit_nec: + address: 0x1234 + command: 0x5678 + # yamllint disable-line rule:comments-indentation + # TODO: Make this work with the microphone. + # - rtttl.play: + # id: rtttl_player + # rtttl: scale_up:d=32,o=5,b=100:c,c#,d#,e,f#,g#,a#,b + # # Work around RTTTL player getting stuck after first play. + # # See https://github.com/esphome/esphome/issues/10312 + # - lambda: |- + # id(rtttl_player).enable_loop();