SparkFun Qwiic Buzzer  v1.0.1-17-gba6cd53
Library for the SparkFun Qwiic Buzzer
Loading...
Searching...
No Matches
SparkFun Qwiic Buzzer

SparkFun Qwiic Buzzer

Arduino Library for the SparkFun Qwiic Buzzer breakout board

License Release Release Date Documentation - build Compile - Test GitHub issues

The SparkFun_Qwiic_Buzzer_Arduino_Library (BOB-24474) adds simple beeps and buzzes to your projects via I2C. Make some noises to alert you when something interesting (or urgent) happens. Simply connect a Qwiic cable and load up some pre-written code to an Arduino to start making noises!

The board includes an ATtiny84 with custom firmware to control the magnetic buzzer over I2C. Utilizing our handy Qwiic system, no soldering is required to connect it to the rest of your system. However, we still broke out 0.1"-spaced PTH pads if you prefer to use a breadboard to access the board's I2C, power, trigger, and reset pins on the board's edge. A 2.2k&ohm; pull-up resistor is included on the data and clock lines. Looking for the board that matches this library - pick up a <a href="https://www.sparkfun.com/sparkfun-qwiic-buzzer.html" >SparkFun Qwiic Buzzer (BOB-24474)</a> at www.sparkfun.com. @subsection autotoc_md1 Functionality This library provides an interface that enables the following functionality when a SparkFun Qwiic Buzzer breakout board: * Turn the buzzer on and off * Adjust the buzzers frequency and duration * Control the the volume of the buzzer * Play sound effects on the buzzer * Change the I2C address to enable the use of multiple buzzers on one device @subsection autotoc_md2 General Use The following outlines the general use of the library in an Arduino Sketch. @subsubsection autotoc_md3 Declaration At the start of your sketch, the library header file is included using the following statement: @icode{cpp} #include <SparkFun_Qwiic_Buzzer_Arduino_Library.h> @endicode Before the arduino <tt>setup()</tt> function, create a Buzzer object in your file with the following declaration: @icode{c} QwiicBuzzer buzzer; // its a buzzer @endicode @subsubsection autotoc_md4 Initialization In the Arduino <tt>setup()</tt> function, initialize the buzzer by calling the begin method. This method is called after the Arduino <tt>Wire</tt> (I2C) library is initialized. @icode{cpp} //check if buzzer will connect over I2C if (buzzer.begin() == false) { Serial.println("Device did not connect! Freezing."); while (1); } @endicode The begin method returns true if the buzzer is connected and available, and false if it is not. If a value of <em>false</em> is returned in the above example, the sketch execution is halted. @subsubsection autotoc_md5 Usage @paragraph autotoc_md6 On/Off Turn the buzzer on and off as shown in the following loop example: @icode{cpp} void loop() { buzzer.on(); delay(1000); buzzer.off(); delay(1000); } @endicode @paragraph autotoc_md7 Frequency Control The buzzer frequency is controlled using the <tt>configureBuzzer()</tt> method. @icode{cpp} void loop() { // Configure with desired settings // Resonant frequency is 2.73KHz buzzer.configureBuzzer(SFE_QWIIC_BUZZER_RESONANT_FREQUENCY); buzzer.on(); delay(100); buzzer.off(); delay(1000); buzzer.configureBuzzer(1000); // set frequency to 1KHz buzzer.on(); delay(100); buzzer.off(); delay(1000); } @endicode @paragraph autotoc_md8 Buzz Duration The buzz duration is set by adding a timing value after the frequency to the <tt>configureBuzzer()</tt> method. @icode{cpp} buzzer.configureBuzzer(2730, 100); // frequency: 2.73KHz, duration: 100ms @endicode @paragraph autotoc_md9 Volume The buzz volume is an additional optional parameter to the <tt>configureBuzzer()</tt> method. @icode{cpp} buzzer.configureBuzzer(2730, 100, SFE_QWIIC_BUZZER_VOLUME_MIN); // frequency: 2.73KHz, duration: 100ms, volume: MIN ... buzzer.configureBuzzer(2730, 100, SFE_QWIIC_BUZZER_VOLUME_MAX); // frequency: 2.73KHz, duration: 100ms, volume: MAX @endicode @paragraph autotoc_md10 Sound Effects The buzzer has a collection of sound effects included in this library. These are started by using the <tt>playSoundEffect()</tt> method, providing the number of the sound effect to play. Playing sound effect 1: @icode{cpp} err = buzzer.playSoundEffect(1, BUZZER_VOLUME); @endicode @subsection autotoc_md11 Examples The following examples are provided with the library - <a href="examples/Example_01_Buzz/Example_01_Buzz.ino" >Buzz</a> - This example shows how to turn the buzzer on and off. - <a href="examples/Example_02_Buzz_Frequency/Example_02_Buzz_Frequency.ino" >Buzz Frequency</a> - This example shows how to adjust the frequency of the buzzer. - <a href="examples/Example_03_Buzz_Duration/Example_03_Buzz_Duration.ino" >Buzz Duration</a> - This example shows how to control the buzzer using frequency and duration. - <a href="examples/Example_04_Buzz_Volume/Example_04_Buzz_Volume.ino" >Buzz Volume</a> - This example shows how to control the buzzer to sound at different volumes. - <a href="examples/Example_05_ChangeI2CAddress/Example_05_ChangeI2CAddress.ino" >Change I2C Address</a> - A configurator for changing the I2C address on the Qwiic Buzzer that walks the user through finding the address of their buzzer, and then changing it! - <a href="examples/Example_06_SaveSettings/Example_06_SaveSettings.ino" >Save Settings</a> - This example shows how to save settings to the buzzer. - <a href="examples/Example_07_Melody/Example_07_Melody.ino" >Melody</a> - TThis example shows how to buzz a melody on the Qwiic Buzzer. - <a href="examples/Example_08_Sound_Effects/Example_08_Sound_Effects.ino" >Sound Effects</a> - This example demos the sound effects included in this library. - <a href="examples/Example_09_FirmwareVersion/Example_09_FirmwareVersion.ino" >Firmware Version</a> - This example shows how to read the firmware version from the Qwiic Buzzer - <a href="examples/Example_10_Buzz_Multiple/Example_10_Buzz_Multiple.ino" >Buzz Multiple</a> - This example shows how to control multiple buzzers. @subsection autotoc_md12 Documentation The full API and use documentation for this library is provided <a href="https://docs.sparkfun.com/SparkFun_Qwiic_Buzzer_Arduino_Library/" >here</a>. For a quick reference, the main methods available in the library are listed <a href="https://docs.sparkfun.com/SparkFun_Qwiic_Buzzer_Arduino_Library/class_qwiic_buzzer.html" >here</a>. Curious about the hardware this board works with - visit the SparkFun Qwiic Buzzer <a href="https://github.com/sparkfun/SparkFun_Qwiic_Buzzer" >hardware repository</a>. The <em><strong>Hookup Guide</strong></em> for the SparkFun Qwiic Buzzer is available <a href="https://docs.sparkfun.com/SparkFun_Qwiic_Buzzer" >here</a>. @subsection autotoc_md13 License Information This product is <em><strong>open source</strong></em>! This product is licensed using the <a href="https://opensource.org/license/mit" >MIT Open Source License.