ESP8266 and Buzzer

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?

Thats a good idea- will try that.

This is the schematic

I was thinking the same. An rttl buzzer has Vcc gnd and io.

Not sure now. The D5, D6, D7, D8 look like alternatives. D5 has a solder link in the picture on the WeMos page, change the link to to change the GPIO.

To get a translation of D numbers to GPIO see ESP8266 Pinout Reference: Which GPIO pins should you use? | Random Nerd Tutorials

1 Like

Can you recommend an appropriate buzzer?