ESP8266 and Buzzer

I have purchased
D1 wemos mini ESP8266
D1 mini buzzer shield (Wemos D1 mini Buzzer Shield V1.0.0 ESP8266 Arduino - Kunkune)

I have tried to follow many forum articles as well as the RTTTL help pages but nothing is happening. I am at the pont of wondering if the hardware is faulty.

Would anyone mind throwing together a piece of code that I can put into ESPHOME and test it with a switch?

Or could someone tell me if there is a way to test that the hardware actually works?

Many thanks.



output:
  - platform: ledc
    pin: PICK your PIN
    id: rtttl_out
    inverted: True
    zero_means_zero: True
    

rtttl:
  output: rtttl_out
  
binary_sensor:
  - platform: gpio
    pin:
      number: Pick your pin for this
      mode: INPUT_PULLUP
      inverted: True
    filters:
      - invert:
      - delayed_on: 100ms
      - delayed_off: 100ms      
    name: "momentary_button1"

    on_press:
      then:
      - rtttl.play: 'TubularB:d=4,o=6,b=200:8b,8e,8a,8e,8b,8e,8g,8a,8e,8c7,8e,8d7,8e,8b,8c7,8e,8b,8e,8a,8e,8b,8e,8g,8a,8e,8c7'  

Try this.

Thanks for the input @Spiro

Got this:

Failed config

output.ledc: [source /config/esphome/esphome-web-6f71c4.yaml:37]
  
  Component output.ledc requires component esp32.
  platform: ledc
  pin: GPIO14
  id: rtttl_out
  inverted: True
  zero_means_zero: True

Sorry that was for Esp32.

output:
  - platform: esp8266_pwm
    pin: your pin
    id: rtttl_out
    inverted: True     
    zero_means_zero: True

Possibly will need to use inverted to true otherwise it heats up and chirps all the time. Not sure about zero means zero bit.

Sorry I must be making a newbie error- first time using buzzer.

INFO ESPHome 2024.3.1
INFO Reading configuration /config/esphome/esphome-web-6f71c4.yaml...
Failed config

output.esp8266_pwm: [source /config/esphome/esphome-web-6f71c4.yaml:37]
  
  Pin 14 is used in multiple places.
  platform: esp8266_pwm
  pin: 
    number: 14
    mode: 
      output: True
      input: False
      open_drain: False
      pullup: False
      pulldown: False
      analog: False
    inverted: False
  id: rtttl_out
  inverted: True
  zero_means_zero: True
  frequency: 1000.0
binary_sensor.gpio: [source /config/esphome/esphome-web-6f71c4.yaml:48]
  
  Pin 14 is used in multiple places.
  platform: gpio
  pin: 
    number: 14
    mode: 
      input: True
      pullup: True
      output: False
      open_drain: False
      pulldown: False
      analog: False
    inverted: True
  filters: 
    - invert: {}
    - delayed_on: 100ms
    - delayed_off: 100ms
  name: momentary_button1
  on_press: 
    - then: 
        - rtttl.play: 
            rtttl: |-
              TubularB:d=4,o=6,b=200:8b,8e,8a,8e,8b,8e,8g,8a,8e,8c7,8e,8d7,8e,8b,8c7,8e,8b,8e,8a,8e,8b,8e,8g,8a,8e,8c7
  disabled_by_default: False

You have used the data pin for buzzer and your external button. I assume you wanted to burn buzzer on with an external switch/button

Sorry my error: I meant activate the buzzer from a button in HA.

I want to set it up so that if the car does not charge at 2330hrs then it will buzz. (Automation script)

api:
  services:
    - service: play_rtttl
      variables:
        song_str: string 
      then:
        - rtttl.play:
            rtttl: !lambda 'return song_str;'
        - output.turn_off: rtttl_out 

  platform: esp8266_pwm
  pin: 
    number: D1
  id: rtttl_out
  inverted: True
  zero_means_zero: True
  frequency: 1000.0



This above code in ESPhome yaml will expose the esp8266 as a service. Below is the action sequence to put in your automation to play the sound. I’ll leave the trigger up to yourself.

sequence:
  - service: esphome.whateveryoucalledyourespdeviceinesphome_play_rtttl
    data:
      song_str: >-
        TubularB:d=4,o=6,b=200:8b,8e,8a,8e,8b,8e,8g,8a,8e,8c7,8e,8d7,8e,8b,8c7,8e,8b,8e,8a,8e,8b,8e,8g,8a,8e,8c7

I never had much luck with pin picking and using D1. I tended to use GPIO number. pin: 5 instead for D1 if that’s the pin you picked.


You can test if buzzer working from developer tools. In this backroom is the name of my esphome device.

Read this then post your yaml file.

Thanks, but if you read the original post, I did not have a yaml as nothing was working and I got myself in a mess

substitutions:
  name: esphome-web-6f71c4
  friendly_name: buzz

esphome:
  name: ${name}
  friendly_name: ${friendly_name}
  name_add_mac_suffix: false
  project:
    name: esphome.web
    version: '1.0'

esp8266:
  board: esp01_1m

# Enable logging
logger:

# Enable Home Assistant API
#api:

# Allow Over-The-Air updates
ota:

# Allow provisioning Wi-Fi via serial
improv_serial:

wifi:
  # Set up a wifi access point
  ap: {}

# In combination with the `ap` this allows the user
# to provision wifi credentials to the device via WiFi AP.
captive_portal:
output:
  - platform: esp8266_pwm
    pin: GPIO14
    id: rtttl_out
    inverted: True     
    zero_means_zero: True
    frequency: 1000.0

api:
  services:
    - service: play_rtttl
      variables:
        song_str: string 
      then:
        - rtttl.play:
            rtttl: !lambda 'return song_str;'
        - output.turn_off: rtttl_out 

error when installing to hardware:

INFO ESPHome 2024.3.1
INFO Reading configuration /config/esphome/esphome-web-6f71c4.yaml...
Failed config

api: [source /config/esphome/esphome-web-6f71c4.yaml:44]
  services: 
    - service: play_rtttl
      variables: 
        song_str: string
      then: 
        - 
          Unable to find action with the name 'rtttl.play'.
          rtttl.play: 
            rtttl: !lambda |-
              return song_str;
        - output.turn_off: rtttl_out

rtttl:
  output: rtttl_out

Did we leave these lines out?

found this:

rtttl:
  output: rtttl_out
  on_finished_playback:
    - logger.log: 'Song ended!'

Should that be added?

When you mention GPIO number.

The syntax would be GPIO14 in my case, rather than just pin: 14 ???

`  on_finished_playback:
    - logger.log: 'Song ended!'`

This just adds a line to the log in esphome. Won’t affect the buzzer working. Bit below is needed.

rtttl:
  output: rtttl_out

just pin: 5. Don’t have to put GPIO in front. D1 is GPIO 5

Those are identical.

Pin

ESPHome always uses the chip-internal GPIO numbers. These internal numbers are always integers like 16 and can be prefixed by GPIO. For example to use the pin with the internal GPIO number 16, you could type GPIO16 or just 16.

Getting nowhere- no buzzing at all

Tried, GPIO14,12,13,15 as per Buzzer Shield — WEMOS documentation

and GPIO5 as a last gasp try.

Looking at the board on the site D1, GPIO5 is the pin needed. It is possible the Buzzer isn’t a passive buzzer but an active one so won’t work.
active
Looks active to me from the mlt-s540 document. @stevemann you have an electrical background, does this look like an active buzzer?

Have you tried contacting the shield seller to ask if they have sample code?