Jump to content

The Beeper Thread


ChicagoKeri

Recommended Posts

 

 

Hi everyone!

Let's start a thread to discuss adding beepers to our often entirely mute Vorons...

I often do prints with a color change. Thus, it would be convenient to have the printer beep or make some kind of noise when it needs attention.

Unfortunately, I built my 2.4 with Klipper Screen, using a Pi TFT43.  Neither the TFT43 or the Octopus has an onboard beeper.  The Raspberry Pi does have a speaker output, but I couldn't find a way to utilize this in Klipper.

At first I thought to use a small 5v powered MP3 player and connect it to a fan port.  This actually worked, but only plays one tune.

Then I found beeper tunes for Klipper. This could be great, but there is no speaker. But there can be one!

A look at the schematic for the Octopus shows a dedicated Beeper pin on Display Connector EXP1, pin 1. 

OctopusEXP1pinout.png.e850a54945c11e1bcb1aae63264a9f15.png

 

So, I connected a piezo beeper between EXP1-1 and EXP1-9 , installed some Beeper tunes and Yuck! it sounds really bad! 

It seems that the most common piezo beepers are Active, with a small oscillator built in.  The allows the beeper to work with a DC voltage connected to the wires.

What I needed is a Passive piezo beeper, as the input signal from EXP1-1 is already an alternating current, or at least rapidly switched DC.

So, I salvaged a small computer beeper and it works! The tunes play as intended.  Pretty quiet though.... I would have to be nearby to hear it.  

 

 

A further look at the schematic for a compatible LCD controller with a beeper shows what I need to see... a rudimentary amplifier in the form of a single NPN transistor increases the current to the passive piezo beeper.

ControllerEXP1pinout.png.69fa8afab755857e5b2d2da3b7e0b718.png

 

So, I gutted my Active piezo beeper, ripped out the oscillator board and stuck in an NPN transistor and a 470 ohm resistor... and it didn't work very well.

IMG_4747.thumb.jpg.3f8e8fda2862b40389bc64af33239541.jpg

 

So, I tried it with various small speakers. The best result was with a 16 ohm 36mm diameter speaker with the NPN transistor soldered directly onto a speaker terminal in the "Dead Bug" style. It is plenty loud running on VCC 5v from EXP1-10. For more power, one could build a small mono amplifier and even utilize the 24v power supply. That could potentially rattle windows with a suitable speaker...

IMG_4752.thumb.jpg.4c9e22a4f98a2199c234243c41ffbb2c.jpg

 

Fortunately, the 36mm speaker fits right into the housing of the now defunct piezo beeper. I made a very short video of it playing but it won't upload here...

 

So, it's time for some Klipper Kode! I have a separate file for the tunes called "tunes.cfg" with some fun tunes to choose from.

 

 

######################################################################
# Beeper
######################################################################

# M300 : Play tone. Beeper support, as commonly found on usual LCD
# displays (i.e. RepRapDiscount 2004 Smart Controller, RepRapDiscount
# 12864 Full Graphic). This defines a custom I/O pin and a custom
# GCODE macro.  Usage:
#   M300 [P<ms>] [S<Hz>]
#   P is the tone duration, S the tone frequency.
# The frequency won't be pitch perfect.

[include tunes.cfg]

[output_pin BEEPER_pin]
pin: PE8
#   Beeper pin. This parameter must be provided.
#   ar37 is the default RAMPS/MKS pin.
pwm: True
#   A piezo beeper needs a PWM signal, a DC buzzer doesn't.
value: 0
#   Silent at power on, set to 1 if active low.
shutdown_value: 0
#   Disable at emergency shutdown (no PWM would be available anyway).
cycle_time: 0.001
#   Default PWM frequency : 0.001 = 1ms will give a tone of 1kHz
#   Although not pitch perfect.

[gcode_macro M300]
gcode:
    # Use a default 1kHz tone if S is omitted.
    {% set S = params.S|default(1000)|int %}
    # Use a 10ms duration is P is omitted.
    {% set P = params.P|default(100)|int %}
    SET_PIN PIN=BEEPER_pin VALUE=0.5 CYCLE_TIME={ 1.0/S if S > 0 else 1 }
    G4 P{P}
    SET_PIN PIN=BEEPER_pin VALUE=0

 


Yay! beeps, boops, Mario tunes and various other noises.  Now I just gotta figure out how to play them for specific events like change filament, end print and so on...

 

 

 

 

 

 

 

  • Like 5
Link to comment
Share on other sites

  • 7 months later...
Posted (edited)

Hi,

Thanks for your explanation and the circuit. I built all as explained and it works... partially...

For some reason I cannot change the frequency and volume of the tone. Duration is o.k. The tone (frequency or cycle time) only seems to respond on the value set in [output_pin BEEPER_pin] cycle_time: 0.001 value. Any value set in the gcode macro is neglected.

Do you have any idea how this is possible???

This is how my code looks now:

[output_pin buzzer]
pin: PE8
pwm: True
value: 0.0
shutdown_value: 0.0
cycle_time: 0.001

and

[gcode_macro BUZZER]
gcode:
  {% set frequency = params.F|default(1000)|float %}
  {% set duration = params.D|default(1.0)|float %}
  {% set volume = params.V|default(0.5)|float %}
  
  # Ensure volume is within 0.0 to 0.9
  {% if volume > 0.9 %}
    {% set volume = 0.9 %}
  {% elif volume < 0.0 %}
    {% set volume = 0.0 %}
  {% endif %}
  
  # Calculate the cycle time based on the frequency
  {% set cycle_time = 1.0 / frequency %}
  
  # Debugging messages to verify the parameters (Optional)
  # Debugging messages to verify the parameters
  {action_respond_info("Frequency: " ~ frequency)}
  {action_respond_info("Cycle time: " ~ cycle_time)}
  {action_respond_info("Volume: " ~ volume)}
  {action_respond_info("Duration: " ~ duration)}
  
  # Set the cycle time first to adjust the frequency
  SET_PIN PIN=buzzer  VALUE={volume} CYCLE_TIME={cycle_time}
    
  # Play the buzzer for the specified duration
  G4 P{duration * 1000}  # Delay for the duration in milliseconds
  
  # Turn off the buzzer
  SET_PIN PIN=buzzer VALUE=0
  M400  # Wait for moves to finish

When I issue this command:

BUZZER F=2000 D=0.5 V=0.8

The resullt in the console is:

19:15
Duration: 0.5
19:15
Volume: 0.8
19:15
Cycle time: 0.0005
19:15
Frequency: 2000.0
19:15
BUZZER F=2000 D=0.5 V=0.8

Whatever value II put in for the frequency, it does not affect the tone. It sticks on the value defined in [output_bin buzzer]

Kind regards,

Tom...

Edited by Tominator T-2000
Link to comment
Share on other sites

  • 4 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...