Playing sound using with my BBB using a piezo buzzer (beeper)

I want play ‘beeps’ connecting a piezo buzzer to my Beaglebone Black. I am very new to eletronics, so I need some help here, don’t know how to operate these sound devices.

-Eletrical circuit: as for the circuit, I am referring to this book/chapter which shows it very well how I should proceed: using a transistor…

-What I don’t know is, how do I control the buzzer (say from a C program) to emit sound?

-I guess I should configure and use PWM feature of the processor, am I right?
-And how do I pragmatically control PWM output?
-How could I make it play an given sound file, like a .midi file?

Hi Ramon,

The piezo buzzer you are using is a digital device. It is either on or off. When it is on it beeps at a fixed frequency. When it is off it is silent.

The circuit you have shown uses a transistor to control current through the buzzer. When the line “from processor” is high, or 3.3 V, the transistor turns on and draws current through the buzzer. The line “from processor” would normally be a GPIO (general purpose input/output) pin rather than a PWM output.

You can use one of the Python or Bonescript libraries to turn a GPIO pin on or off to control the buzzer.

This simple buzzer will not play a sound file or midi file. For that you would need a PWM output running at a high frequency with its duty cycle adjusted at the sample rate of your audio signal to produce an average analog voltage proportional to the audio signal. This would then need to be low pass filtered to remove the high frequency PWM carrier and amplified to drive a speaker. This will require much more learning, hardware, and software on your part.

HTH
Dennis Cote

I want play 'beeps' connecting a piezo buzzer to my Beaglebone Black. I am
very new to eletronics, so I need some help here, don't know how to operate
these sound devices.

-Eletrical circuit: as for the circuit, I am referring to this
book/chapter which shows it very well how I should proceed: using a
transistor..

-What I don't know is, how do I control the buzzer (say from a C program)
to emit sound?
-I guess I should configure and use PWM feature of the processor, am I
right?
-And how do I pragmatically control PWM output?
-How could I make it play an given sound file, like a .midi file?

Hi Ramon,

The piezo buzzer you are using is a digital device. It is either on or off.
When it is on it beeps at a fixed frequency. When it is off it is silent.

The circuit you have shown uses a transistor to control current through the
buzzer. When the line "from processor" is high, or 3.3 V, the transistor
turns on and draws current through the buzzer. The line "from processor"
would normally be a GPIO (general purpose input/output) pin rather than a
PWM output.

You can use one of the Python or Bonescript libraries to turn a GPIO pin on
or off to control the buzzer.

This simple buzzer will not play a sound file or midi file. For that you
would need a PWM output running at a high frequency with its duty cycle
adjusted at the sample rate of your audio signal to produce an average
analog voltage proportional to the audio signal. This would then need to be
low pass filtered to remove the high frequency PWM carrier and amplified to
drive a speaker. This will require much more learning, hardware, and
software on your part.

http://elinux.org/ECE497_BeagleBone_PRU#Building_and_Running_the_Sin_Approximation_Example
might be helpful.

Also http://www.embedded.com/design/real-time-and-performance/4006419/Low-cost-techniques-for-sound-generation

For what it is worth, I also wanted sounds and the like to my BBBk, I like to have some form of Audio notification, when I do something lets say with a remote control, to let me know that it was received.

More details on how (readme.md) I set it up, plus code are up on my Raspberry Pi project (https://github.com/KurtE/Raspberry_Pi)

Since there is no Sound output plug on the BBBk, I used a real cheap USB sound adapter, plus a cheap powered speaker.

I then installed PCM (on RPI and now Debian can just do sudo apt-get … earlier on BBBk had to download and build sources.

Once you have PCM installed, need to configure to output to the device instead of the default of HDMI.

I then have a function(https://github.com/KurtE/Raspberry_Pi/blob/master/library/msound.cpp) , that I can pass in how many notes to play, followed by the notes, with a call like: MSound(3, 60, 2000, 80, 2250, 100, 2500);
(play 3 notes, first one 60ms with 200hz…) The code creates a sound buffer with the sine wave for that hz and repeats it so many times…

Probably not the greatest approach, but it has worked for me.

Kurt