Getting started with mikroe BUZZ Click using ChibiOS/HAL

BUZZ Click

BUZZ Click is a click board with a mikroBus form factor. It is substantially composed of a piezoelectric speaker having a resonant frequency at 3.8 kHz: this means we should expect best performances at this frequency. Let’s take a look to the principle of operation of DC and AC buzzer.

BUZZ Click
A BUZZ Click photo.

More about Buzzers

A piezoelectric loudspeaker also known as buzzer uses the inverse piezoelectric effect for generating sound. The piezoelectricity is a phenomena where mechanical stress produces the accumulation of electrical charges and then a voltage across the material. The inverse principle is true as well, so applying a voltage across the material we can expect a mechanical bending of the piezoelectric material (from here on out “piezo“).

So, applying a DC voltage across a piezo, it will bend without producing any sound. Applying an AC voltage instead, it will vibrate producing a pressure wave (i.e. sound), if the input is a single tone signal (i.e. a signal centred on a single frequency like a sinusoid) the piezo will vibrate generating a sound at the same frequency of the input signal.

This means a piezo cannot emit sound if interested by a DC voltage. Anyway, we can found on the market certain DC buzzer which emit sound at a fixed frequency. This because they include in their package an oscillator which uses the piezo as resonant component within its loop: the oscillator will resonate at piezo resonant frequency producing a sound at the same frequency.

Official documentation

We can find documentation about this Clicker board on the related page of mikroe official website but we will post here a direct link to the BUZZ Click User Manual.

BUZZ Click User Manual

Schematic and PIN out

BUZZ schematic
The BUZZ schematic from its datasheet.

We are reporting the BUZZ click schematic from its manual in order to make some considerations.

  • VCC is selectable through a soldered 0Ω resistor; available value are 3.3V and 5V which is the default one (see J1). From here on out VCC means 5V.
  • PWR_LED is powered by VCC so it could be considered as a “Power ON” indicator.
  • piezo is driven by a transistor and its base could be interconnected to a generic IO PIN (i.e. CS) or to PWM (see J2 and J3). The default input PIN is PWM.
  • Using the PWM is possible to generate sounds at different frequencies.

Generating tones using PWM

As said applying an AC voltage to our piezo, it will vibrate producing a pressure wave (i.e. sound). Furthermore the vibration frequency and so the sound frequency will be the same of the input signal frequency. According to Fourier theory and inverse piezoelectricity principle, using a square wave with half duty cycle tuned on a frequency f0 our buzzer will produce a sound which first harmonic will be placed at f0.

The theory is a little bit more complicated but, making an example, if we will use a PWM with duty cycle 50% and a frequency of 440Hz (i.e. the frequency of the musical note LA aka A4) the produced sound will be a “metallic” LA (very similar to dial tones of telephony). If the AC signal had been a sinusoid instead of a square wave, the sound would have been more “smooth”. The interesting fact is that changing the frequency of our PWM we would be able to generate sound at any frequency.

Real case

Piezoelectric frequency response
Piezoelectric frequency response.

Of course there are some limits. First of all, the common hearing range is 20 Hz~20 kHz and tones outside this range would not be heared. In second place, the frequency response of our piezo is not uniform: it has a resonant peak that in our case is placed at 3.8 kHz, a quasi-uniform range before this frequency and it cuts both low frequencies (near the DC) and frequencies slightly greater than the resonant frequency.

This means, using this buzzer, we will not be able to play sound at high frequency (like ultrasound) but we will have a good and uniform gain in the musical notes range A1~A7 (corresponding to 55~3520 Hz).

Further readings

For those interested in the theory insight the piezo, you need to know that another main use of this components are crystal oscillator and that its impedance could be described by an equivalent model you can found out on this article of Wikipedia. Using this model, would be simple to deduce how the frequency response of Fig.3 has been obtained: according to the voltage divider principle, the higher is the equivalent impedance the higher would be the voltage transferred to the piezo.

Demo explained

The project has two threads: Thread1()) and main(). The former just blinks a LED, the latter is the core of our project. Note that the purpose of Thread1() is to make evident if ChibiOS is still alive or not.

The main() initializes the system, creates Thread1() and starts both SerialUSB Driver and PWM Driver, than it enters in its loop. Note that we have defined different frequencies related to the musical notes from C5 to B6.

In its loop main() read a character with a timeout. If the character is among the allowed (a, s, d, f, g, h and j) then PWM frequency will be changed and buzzer enabled: this makes the buzzer to produce a new tone. Note that if chnReadTimeout() goes timeout or if the character is different from the allowed ones PWM is disabled and buzzer falls silent.

Project used in this tutorial

This project has been tested under ChibiOS/RT 3.1.1 (release 16.1) using ChibiStudio Preview 16. For those that are using oldest version of ChibiStudio note that both ChibiOS relative path and USB configuration files could be different. In case of errors like “No rules to make target” look carefully at makefile or contact us.


Be the first to reply at Getting started with mikroe BUZZ Click using ChibiOS/HAL

Leave a Reply