Skip to content

Moves release v1.1.0 work to main #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Mar 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
173 changes: 139 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,58 +1,163 @@
SparkFun Qwiic Buzzer Arduino Library [![Build Status](https://travis-ci.org/sparkfun/SparkFun_Qwiic_Buzzer_Arduino_Library.svg?branch=master)](https://travis-ci.org/sparkfun/SparkFun_Qwiic_Buzzer_Arduino_Library)
========================================

[![SparkFun Qwiic Buzzer](https://cdn.sparkfun.com/r/600-600/assets/parts/2/4/8/3/2/BOB-24474-Qwiic-Buzzer-Feature.jpg)](https://www.sparkfun.com/products/24474)
![SparkFun Qwiic Buzzer](docs/images/gh-banner-2025-arduino-buzzer.png "SparkFun Qwiic Buzzer")

[*SparkFun Qwiic Buzzer (BOB-24474)*](https://www.sparkfun.com/products/24474)
# SparkFun Qwiic Buzzer

<!---
Arduino Library for the SparkFun Qwiic Buzzer breakout board

![License](https://img.shields.io/github/license/sparkfun/SparkFun_Qwiic_Buzzer_Arduino_Library)
![Release](https://img.shields.io/github/v/release/sparkfun/SparkFun_Qwiic_Buzzer_Arduino_Library)
![Release Date](https://img.shields.io/github/release-date/sparkfun/SparkFun_Qwiic_Buzzer_Arduino_Library)
![Documentation - build](https://img.shields.io/github/actions/workflow/status/sparkfun/SparkFun_Qwiic_Buzzer_Arduino_Library/build-deploy-ghpages.yml?label=doc%20build)
![Compile - Test](https://img.shields.io/github/actions/workflow/status/sparkfun/SparkFun_Qwiic_Buzzer_Arduino_Library/compile-sketch.yml?label=compile%20test)
![GitHub issues](https://img.shields.io/github/issues/sparkfun/SparkFun_Qwiic_Buzzer_Arduino_Library)

UPDATE WHAT DOES THIS LIBRARY DO!?! =)

The [SparkFun_Qwiic_Buzzer_Arduino_Library (BOB-24474)](https://www.sparkfun.com/sparkfun-qwiic-buzzer.html) 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.

This library allows the user to:
Looking for the board that matches this library - pick up a [SparkFun Qwiic Buzzer (BOB-24474)](https://www.sparkfun.com/sparkfun-qwiic-buzzer.html) at www.sparkfun.com.

* Turn the buzzer on and off directly
* Optionally, set the frequency, duration, and volume of the sound
* Adjust the device's I<sup>2</sup>C address
## Functionality

-->
This library provides an interface that enables the following functionality when a SparkFun Qwiic Buzzer breakout board:

Repository Contents
-------------------
* 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

* **/examples** - Example sketches for the library (.ino). Run these from the Arduino IDE.
* **/src** - Source files for the library (.cpp, .h).
* **keywords.txt** - Keywords from this library that will be highlighted in the Arduino IDE.
* **library.properties** - General library properties for the Arduino package manager.

Documentation
--------------
## General Use
The following outlines the general use of the library in an Arduino Sketch.

* **[Installing an Arduino Library Guide](https://learn.sparkfun.com/tutorials/installing-an-arduino-library)** - Basic information on how to install an Arduino library.
* **[Product Repository](https://github.com/sparkfun/SparkFun_Qwiic_Buzzer)** - Main repository (including hardware files) for the SparkFun Qwiic Buzzer Breakout Board.
* **[Hookup Guide](https://docs.sparkfun.com/SparkFun_Qwiic_Buzzer)** - Basic hookup guide for the Qwiic Buzzer.
### Declaration

Products that use this Library
---------------------------------
At the start of your sketch, the library header file is included using the following statement:

* [*BOB-24474*](https://www.sparkfun.com/products/24474) - Initial release
~~~cpp
#include <SparkFun_Qwiic_Buzzer_Arduino_Library.h>
~~~

Version History
---------------
Before the arduino ```setup()``` function, create a Buzzer object in your file with the following declaration:

* v1.0.0 - Initial Public release.
~~~c
QwiicBuzzer buzzer; // its a buzzer
~~~

License Information
-------------------

This product is _**open source**_!
### Initialization

Please review the LICENSE.md file for license information.
In the Arduino ```setup()``` function, initialize the buzzer by calling the begin method. This method is called after the Arduino `Wire` (I2C) library is initialized.

If you have any questions or concerns on licensing, please contact technical support on our [SparkFun forums](https://forum.sparkfun.com/viewforum.php?f=152).
~~~cpp
//check if buzzer will connect over I2C
if (buzzer.begin() == false) {
Serial.println("Device did not connect! Freezing.");
while (1);
}
~~~

The begin method returns true if the buzzer is connected and available, and false if it is not. If a value of *false* is returned in the above example, the sketch execution is halted.

### Usage

#### On/Off

Turn the buzzer on and off as shown in the following loop example:

~~~cpp
void loop() {
buzzer.on();

delay(1000);

buzzer.off();

delay(1000);
}
~~~

#### Frequency Control

The buzzer frequency is controlled using the ```configureBuzzer()``` method.

~~~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);
}
~~~

#### Buzz Duration

The buzz duration is set by adding a timing value after the frequency to the ```configureBuzzer()``` method.

~~~cpp
buzzer.configureBuzzer(2730, 100); // frequency: 2.73KHz, duration: 100ms
~~~

#### Volume

The buzz volume is an additional optional parameter to the ```configureBuzzer()``` method.

~~~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
~~~

#### Sound Effects

The buzzer has a collection of sound effects included in this library. These are started by using the ```playSoundEffect()``` method, providing the number of the sound effect to play.

Playing sound effect 1:

~~~cpp
err = buzzer.playSoundEffect(1, BUZZER_VOLUME);
~~~
## Examples

The following examples are provided with the library

- [Buzz](examples/Example_01_Buzz/Example_01_Buzz.ino) - This example shows how to turn the buzzer on and off.
- [Buzz Frequency](examples/Example_02_Buzz_Frequency/Example_02_Buzz_Frequency.ino) - This example shows how to adjust the frequency of the buzzer.
- [Buzz Duration](examples/Example_03_Buzz_Duration/Example_03_Buzz_Duration.ino) - This example shows how to control the buzzer using frequency and duration.
- [Buzz Volume](examples/Example_04_Buzz_Volume/Example_04_Buzz_Volume.ino) - This example shows how to control the buzzer to sound at different volumes.
- [Change I2C Address](examples/Example_05_ChangeI2CAddress/Example_05_ChangeI2CAddress.ino) - 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!
- [Save Settings](examples/Example_06_SaveSettings/Example_06_SaveSettings.ino) - This example shows how to save settings to the buzzer.
- [Melody](examples/Example_07_Melody/Example_07_Melody.ino) - TThis example shows how to buzz a melody on the Qwiic Buzzer.
- [Sound Effects](examples/Example_08_Sound_Effects/Example_08_Sound_Effects.ino) - This example demos the sound effects included in this library.
- [Firmware Version](examples/Example_09_FirmwareVersion/Example_09_FirmwareVersion.ino) - This example shows how to read the firmware version from the Qwiic Buzzer
- [Buzz Multiple](examples/Example_10_Buzz_Multiple/Example_10_Buzz_Multiple.ino) - This example shows how to control multiple buzzers.

## Documentation

The full API and use documentation for this library is provided [here](https://docs.sparkfun.com/SparkFun_Qwiic_Buzzer_Arduino_Library/). For a quick reference, the main methods available in the library are listed [here](https://docs.sparkfun.com/SparkFun_Qwiic_Buzzer_Arduino_Library/class_qwiic_buzzer.html).

Curious about the hardware this board works with - visit the SparkFun Qwiic Buzzer [hardware repository](https://github.com/sparkfun/SparkFun_Qwiic_Buzzer).

The ***Hookup Guide*** for the SparkFun Qwiic Buzzer is available [here](https://docs.sparkfun.com/SparkFun_Qwiic_Buzzer).

## License Information

This product is ***open source***!

This product is licensed using the [MIT Open Source License](https://opensource.org/license/mit).

Distributed as-is; no warranty is given.

2 changes: 1 addition & 1 deletion docs/doxygen/doxygen-config
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ ALWAYS_DETAILED_SEC = YES
# operators of the base classes will not be shown.
# The default value is: NO.

INLINE_INHERITED_MEMB = NO
INLINE_INHERITED_MEMB = YES

# If the FULL_PATH_NAMES tag is set to YES, doxygen will prepend the full path
# before files name in the file list and in the header files. If set to NO the
Expand Down
Binary file added docs/images/gh-banner-2025-arduino-buzzer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name=SparkFun Qwiic Buzzer Library
version=1.0.1
version=1.1.0
author=SparkFun Electronics <techsupport@sparkfun.com>
maintainer=SparkFun Electronics <support@sparkfun.com>
sentence=Communicates with and configures the SparkFun Qwiic Buzzer
paragraph=This library allows the user to control the buzzer frequency/duration, and change its I2C addresses.
category=Outputs
url=https://github.com/sparkfun/SparkFun_Qwiic_Buzzer_Arduino_Library
architectures=*
depends=SparkFun Toolkit (<1.0.0)
depends=SparkFun Toolkit (>=1.0.0)
52 changes: 22 additions & 30 deletions src/SparkFun_Qwiic_Buzzer_Arduino_Library.h
Original file line number Diff line number Diff line change
@@ -1,34 +1,26 @@
/******************************************************************************
SparkFun_Qwiic_Buzzer_Arduino_Library.h
SparkFun Qwiic Buzzer Library header file

by Pete Lewis @SparkFun Electronics
January 2024

Based on original source code written by
Fischer Moseley @ SparkFun Electronics
Original Creation Date: July 24, 2019

This file implements the QwiicBuzzer class, prototyped in SparkFun_Qwiic_Buzzer_Arduino_Library.h

Development environment specifics:
IDE: Arduino 2.2.1
Hardware Platform: Arduino Uno/SparkFun Redboard
Qwiic Buzzer Version: v10

SPDX-License-Identifier: MIT

Copyright (c) 2024 SparkFun Electronics

Distributed as-is; no warranty is given.
******************************************************************************/
/**
* @file SparkFun_Qwiic_Buzzer_Arduino_Library.h
* @brief SparkFun Qwiic Buzzer Library header file
* @author Pete Lewis \@SparkFun Electronics
* @date January 2024
*
* @note Based on original source code written by Fischer Moseley \@ SparkFun Electronics
* Original Creation Date: July 24, 2019
*
* @details This file implements the QwiicBuzzer class, prototyped in SparkFun_Qwiic_Buzzer_Arduino_Library.h
*
* @copyright Copyright (c) 2024 SparkFun Electronics. This project is released under the MIT License.
* @license SPDX-License-Identifier: MIT
*
*/

#pragma once

#include "sfeQwiicBuzzer.h"
// clang-format off
#include <SparkFun_Toolkit.h>

class QwiicBuzzer : public sfeQwiicBuzzer
#include "sfTk/sfDevBuzzer.h"
// clang-format on
class QwiicBuzzer : public sfDevBuzzer
{
public:
/// @brief Begins the Qwiic Buzzer
Expand All @@ -41,16 +33,16 @@ class QwiicBuzzer : public sfeQwiicBuzzer
_theI2CBus.init(wirePort, address);

// Begin the sensor
return sfeQwiicBuzzer::begin(&_theI2CBus) == kSTkErrOk;
return sfDevBuzzer::begin(&_theI2CBus) == ksfTkErrOk;
}

/// @brief Checks if the Qwiic Buzzer is connected
/// @return True if the sensor is connected, false otherwise
bool isConnected()
{
return sfeQwiicBuzzer::isConnected() == kSTkErrOk;
return sfDevBuzzer::isConnected() == ksfTkErrOk;
}

private:
sfeTkArdI2C _theI2CBus;
sfTkArdI2C _theI2CBus;
};
Loading