Skip to content

Commit 387b5d0

Browse files
authored
Merge pull request #2 from sparkfun/dev_toolkit
Review
2 parents fe86348 + a5ee6d8 commit 387b5d0

File tree

19 files changed

+1489
-818
lines changed

19 files changed

+1489
-818
lines changed

examples/Example_01_Buzz/Example_01_Buzz.ino

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
By Pete Lewis @ SparkFun Electronics
99
December 2023
1010
11-
Based on code orginally written by Fischer Moseley @ SparkFun Electronics
11+
Based on code originally written by Fischer Moseley @ SparkFun Electronics
1212
Original Creation Date: June 28, 2019
1313
14-
This code is Lemonadeware; if you see me (or any other SparkFun employee) at the
15-
local, and you've found our code helpful, please buy us a round!
14+
SparkFun code, firmware, and software is released under the MIT License.
15+
Please see LICENSE.md for further details.
1616
1717
Hardware Connections:
1818
Connect QWIIC cable from Arduino to Qwiic Buzzer
@@ -28,12 +28,12 @@ void setup() {
2828
Serial.println("Qwiic Buzzer Example_01_Buzz");
2929
Wire.begin(); //Join I2C bus
3030

31-
//check if buzzer will acknowledge over I2C
31+
//check if buzzer will connect over I2C
3232
if (buzzer.begin() == false) {
33-
Serial.println("Device did not acknowledge! Freezing.");
33+
Serial.println("Device did not connect! Freezing.");
3434
while (1);
3535
}
36-
Serial.println("Buzzer acknowledged.");
36+
Serial.println("Buzzer connected.");
3737
}
3838

3939
void loop() {

examples/Example_02_Buzz_Frequency/Example_02_Buzz_Frequency.ino

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
Based on code originally written by Fischer Moseley @ SparkFun Electronics
1414
Original Creation Date: June 28, 2019
1515
16-
This code is Lemonadeware; if you see me (or any other SparkFun employee) at the
17-
local, and you've found our code helpful, please buy us a round!
16+
SparkFun code, firmware, and software is released under the MIT License.
17+
Please see LICENSE.md for further details.
1818
1919
Hardware Connections:
2020
Connect QWIIC cable from Arduino to Qwiic Buzzer
@@ -30,22 +30,26 @@ void setup() {
3030
Serial.println("Qwiic Buzzer Example_02_Buzz_Frequency");
3131
Wire.begin(); //Join I2C bus
3232

33-
//check if buzzer will acknowledge over I2C
33+
//check if buzzer will connect over I2C
3434
if (buzzer.begin() == false) {
35-
Serial.println("Device did not acknowledge! Freezing.");
35+
Serial.println("Device did not connect! Freezing.");
3636
while (1);
3737
}
38-
Serial.println("Buzzer acknowledged.");
38+
Serial.println("Buzzer connected.");
3939
}
4040

4141
void loop() {
42-
buzzer.on(2730); // resonant frequency is 2.73KHz
42+
// Configure with desired settings
43+
// Resonant frequency is 2.73KHz
44+
buzzer.configureBuzzer(SFE_QWIIC_BUZZER_RESONANT_FREQUENCY);
45+
buzzer.on();
4346
delay(100);
4447

4548
buzzer.off();
4649
delay(1000);
4750

48-
buzzer.on(1000); // try out 1KHz for fun
51+
buzzer.configureBuzzer(1000); // set frequency to 1KHz
52+
buzzer.on();
4953
delay(100);
5054

5155
buzzer.off();

examples/Example_03_Buzz_Duration/Example_03_Buzz_Duration.ino

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
Based on code originally written by Fischer Moseley @ SparkFun Electronics
1414
Original Creation Date: June 28, 2019
1515
16-
This code is Lemonadeware; if you see me (or any other SparkFun employee) at the
17-
local, and you've found our code helpful, please buy us a round!
16+
SparkFun code, firmware, and software is released under the MIT License.
17+
Please see LICENSE.md for further details.
1818
1919
Hardware Connections:
2020
Connect QWIIC cable from Arduino to Qwiic Buzzer
@@ -30,19 +30,21 @@ void setup() {
3030
Serial.println("Qwiic Buzzer Example_03_Buzz_Duration");
3131
Wire.begin(); //Join I2C bus
3232

33-
//check if buzzer will acknowledge over I2C
33+
//check if buzzer will connect over I2C
3434
if (buzzer.begin() == false) {
35-
Serial.println("Device did not acknowledge! Freezing.");
35+
Serial.println("Device did not connect! Freezing.");
3636
while (1);
3737
}
38-
Serial.println("Buzzer acknowledged.");
38+
Serial.println("Buzzer connected.");
3939
}
4040

4141
void loop() {
42-
buzzer.on(2730, 100); // frequency: 2.73KHz, duration: 100ms
42+
buzzer.configureBuzzer(2730, 100); // frequency: 2.73KHz, duration: 100ms
43+
buzzer.on();
4344
delay(1000);
4445

45-
buzzer.on(1000, 500); // frequency: 1K, duration: 500ms
46+
buzzer.configureBuzzer(1000, 500); // frequency: 1K, duration: 500ms
47+
buzzer.on();
4648
delay(1000);
4749

4850
// Note, we dont' have to call buzzer.off(), because it will automatically turn

examples/Example_04_Buzz_Volume/Example_04_Buzz_Volume.ino

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
44
This example shows how to control the buzzer to sound at different volumes.
55
6-
Note, the "on()" function accepts three arguments, and you must send all three
6+
Note, the "configureBuzzer()" function accepts three arguments, and you must send all three
77
in order to access the volume control.
88
9-
on(frequency, duration, volume);
9+
configureBuzzer(frequency, duration, volume);
1010
1111
It turns the buzzer on and off.
1212
Much like the classic "blink LED sketch" this will buzz
@@ -18,8 +18,8 @@
1818
Based on code originally written by Fischer Moseley @ SparkFun Electronics
1919
Original Creation Date: June 28, 2019
2020
21-
This code is Lemonadeware; if you see me (or any other SparkFun employee) at the
22-
local, and you've found our code helpful, please buy us a round!
21+
SparkFun code, firmware, and software is released under the MIT License.
22+
Please see LICENSE.md for further details.
2323
2424
Hardware Connections:
2525
Connect QWIIC cable from Arduino to Qwiic Buzzer
@@ -35,29 +35,33 @@ void setup() {
3535
Serial.println("Qwiic Buzzer Example_04_Buzz_Volume");
3636
Wire.begin(); //Join I2C bus
3737

38-
//check if buzzer will acknowledge over I2C
38+
//check if buzzer will connect over I2C
3939
if (buzzer.begin() == false) {
40-
Serial.println("Device did not acknowledge! Freezing.");
40+
Serial.println("Device did not connect! Freezing.");
4141
while (1);
4242
}
43-
Serial.println("Buzzer acknowledged.");
43+
Serial.println("Buzzer connected.");
4444
}
4545

4646
void loop() {
47-
Serial.println("Volume: Quietest (1)");
48-
buzzer.on(2730, 100, 1); // frequency: 2.73KHz, duration: 100ms, volume: 1
47+
Serial.println("Volume: MIN (1)");
48+
buzzer.configureBuzzer(2730, 100, SFE_QWIIC_BUZZER_VOLUME_MIN); // frequency: 2.73KHz, duration: 100ms, volume: MIN
49+
buzzer.on();
4950
delay(1000);
5051

51-
Serial.println("Volume: Mid-low (2)");
52-
buzzer.on(2730, 100, 2); // frequency: 2.73KHz, duration: 100ms, volume: 2
52+
Serial.println("Volume: LOW (2)");
53+
buzzer.configureBuzzer(2730, 100, SFE_QWIIC_BUZZER_VOLUME_LOW); // frequency: 2.73KHz, duration: 100ms, volume: LOW
54+
buzzer.on();
5355
delay(1000);
5456

55-
Serial.println("Volume: Mid-high (3)");
56-
buzzer.on(2730, 100, 3); // frequency: 2.73KHz, duration: 100ms, volume: 3
57+
Serial.println("Volume: MID (3)");
58+
buzzer.configureBuzzer(2730, 100, SFE_QWIIC_BUZZER_VOLUME_MID); // frequency: 2.73KHz, duration: 100ms, volume: MID
59+
buzzer.on();
5760
delay(1000);
5861

59-
Serial.println("Volume: Loudest (4)");
60-
buzzer.on(2730, 100, 4); // frequency: 2.73KHz, duration: 100ms, volume: 4
62+
Serial.println("Volume: MAX (4)");
63+
buzzer.configureBuzzer(2730, 100, SFE_QWIIC_BUZZER_VOLUME_MAX); // frequency: 2.73KHz, duration: 100ms, volume: MAX
64+
buzzer.on();
6165
delay(1000);
6266

6367
// Note, we dont' have to use buzzer.off(), because it will automatically turn

examples/Example_05_ChangeI2CAddress/Example_05_ChangeI2CAddress.ino

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
Fischer Moseley @ SparkFun Electronics
66
Original Creation Date: July 30, 2019
77
8-
This code is Lemonadeware; if you see me (or any other SparkFun employee) at the
9-
local, and you've found our code helpful, please buy us a round!
8+
SparkFun code, firmware, and software is released under the MIT License.
9+
Please see LICENSE.md for further details.
1010
1111
Hardware Connections:
1212
Attach the Qwiic Buzzer to your Redboard via Qwiic Cable
@@ -18,17 +18,20 @@
1818
#include <SparkFun_Qwiic_Buzzer_Arduino_Library.h>
1919
QwiicBuzzer buzzer;
2020

21+
// The default address is 0x34, change this if your buzzer currently has a different address!
22+
uint8_t initialAddress = SFE_QWIIC_BUZZER_DEFAULT_ADDRESS;
23+
2124
void setup() {
2225
Serial.begin(115200);
2326
Serial.println("Qwiic Buzzer example - I2C Address Change");
2427
Wire.begin(); //Join I2C bus
2528

26-
//check if device will acknowledge over I2C
27-
if (buzzer.begin(0x5B) == false) {
28-
Serial.println("Device did not acknowledge! Running scanner.");
29+
//check if device will connect over I2C
30+
if (buzzer.begin(initialAddress) == false) {
31+
Serial.println("Device did not connect! Running scanner.");
2932
}
3033
else{
31-
Serial.println("Device acknowledged!");
34+
Serial.println("Device connected!");
3235

3336
Serial.println();
3437
Serial.println("Enter a new I2C address for the Qwiic Buzzer to use!");
@@ -51,11 +54,11 @@ void setup() {
5154

5255
if (success) {
5356
if (newAddress > 0x08 && newAddress < 0x77) {
54-
Serial.println("Character recieved, and device address is valid!");
57+
Serial.println("Character received, and device address is valid!");
5558
Serial.print("Attempting to set device address to 0x");
5659
Serial.println(newAddress, HEX);
5760

58-
if (buzzer.setI2Caddress(newAddress) == true) {
61+
if (buzzer.setAddress(newAddress) == true) {
5962
Serial.println("Device address set succeeded!");
6063
}
6164

@@ -66,16 +69,16 @@ void setup() {
6669
delay(100); //give the hardware time to do whatever configuration it needs to do
6770

6871
if (buzzer.isConnected()) {
69-
Serial.println("Device will acknowledge on new I2C address!");
72+
Serial.println("Device will connect on new I2C address!");
7073
}
7174

7275
else {
73-
Serial.println("Device will not acknowledge on new I2C address.");
76+
Serial.println("Device will not connect on new I2C address.");
7477
}
7578
}
7679

7780
else {
78-
Serial.println("Address out of range! Try an adress between 0x08 and 0x77");
81+
Serial.println("Address out of range! Try an address between 0x08 and 0x77");
7982
}
8083
}
8184

@@ -99,7 +102,7 @@ void loop() {
99102
for (address = 1; address < 127; address++ )
100103
{
101104
// The i2c_scanner uses the return value of
102-
// the Write.endTransmisstion to see if
105+
// the Write.endTransmission to see if
103106
// a device did acknowledge to the address.
104107
Wire.beginTransmission(address);
105108
error = Wire.endTransmission();

examples/Example_06_SaveSettings/Example_06_SaveSettings.ino

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,17 @@
2323
Qwiic buzzer up. Then you can use the TRIGGER header to cause the buzzer to
2424
buzz at your saved settings.
2525
26-
Note, the "on()" function accepts three arguments:
27-
on(frequency, duration, volume);
26+
Note, the "configureBuzzer()" function accepts three arguments:
27+
configureBuzzer(frequency, duration, volume);
2828
2929
By Pete Lewis @ SparkFun Electronics
3030
December 2023
3131
3232
Based on code originally written by Fischer Moseley @ SparkFun Electronics
3333
Original Creation Date: June 28, 2019
3434
35-
This code is Lemonadeware; if you see me (or any other SparkFun employee) at the
36-
local, and you've found our code helpful, please buy us a round!
35+
SparkFun code, firmware, and software is released under the MIT License.
36+
Please see LICENSE.md for further details.
3737
3838
Hardware Connections:
3939
Connect QWIIC cable from Arduino to Qwiic Buzzer
@@ -49,23 +49,24 @@ void setup() {
4949
Serial.println("Qwiic Buzzer Example_06_SaveSettings");
5050
Wire.begin(); //Join I2C bus
5151

52-
//check if buzzer will acknowledge over I2C
52+
//check if buzzer will connect over I2C
5353
if (buzzer.begin() == false) {
54-
Serial.println("Device did not acknowledge! Freezing.");
54+
Serial.println("Device did not connect! Freezing.");
5555
while (1);
5656
}
57-
Serial.println("Buzzer acknowledged.");
57+
Serial.println("Buzzer connected.");
5858

5959
Serial.println("Buzzing at 1K, volume 3");
6060

6161
// Comment/Un-Comment the following "buzzer.on()" example lines to try different settings:
6262

6363
// "MOMENTARY" SETUP
64-
buzzer.on(1000, 0, 3); // frequency: 1KHz, duration: 0 (aka forever), volume: 3
64+
buzzer.configureBuzzer(1000, 0, SFE_QWIIC_BUZZER_VOLUME_MID); // frequency: 1KHz, duration: 0 (aka forever), volume: MID
6565

6666
// "ONE-SHOT" Setup (aka adding in a duration amount).
67-
// buzzer.on(1000, 100, 3); // frequency: 1KHz, duration: 100ms, volume: 3
67+
// buzzer.configureBuzzer(1000, 100, SFE_QWIIC_BUZZER_VOLUME_MID); // frequency: 1KHz, duration: 100ms, volume: MID
6868

69+
buzzer.on();
6970
delay(1000);
7071

7172
Serial.println("Buzzer OFF");

examples/Example_07_Melody/Example_07_Melody.ino

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@
66
By Pete Lewis @ SparkFun Electronics
77
December 2023
88
9+
Based on original source code written by Tom Igeo in Jan 2010:
10+
https://www.arduino.cc/en/Tutorial/BuiltInExamples/toneMelody
11+
http://www.arduino.cc/en/Tutorial/Tone
12+
913
Based on code originally written by Fischer Moseley @ SparkFun Electronics
1014
Original Creation Date: June 28, 2019
1115
12-
This code is Lemonadeware; if you see me (or any other SparkFun employee) at the
13-
local, and you've found our code helpful, please buy us a round!
16+
SparkFun code, firmware, and software is released under the MIT License.
17+
Please see LICENSE.md for further details.
1418
1519
Hardware Connections:
1620
Connect QWIIC cable from Arduino to Qwiic Buzzer
@@ -23,28 +27,32 @@ QwiicBuzzer buzzer;
2327

2428
// notes in the melody:
2529
int melody[] = {
26-
NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4
30+
SFE_QWIIC_BUZZER_NOTE_C4,
31+
SFE_QWIIC_BUZZER_NOTE_G3,
32+
SFE_QWIIC_BUZZER_NOTE_G3,
33+
SFE_QWIIC_BUZZER_NOTE_A3,
34+
SFE_QWIIC_BUZZER_NOTE_G3,
35+
SFE_QWIIC_BUZZER_NOTE_REST, // silence (aka "rest")
36+
SFE_QWIIC_BUZZER_NOTE_B3,
37+
SFE_QWIIC_BUZZER_NOTE_C4
2738
};
2839

2940
// note durations: 4 = quarter note, 8 = eighth note, etc.:
3041
int noteDurations[] = {
3142
4, 8, 8, 4, 4, 4, 4, 4
3243
};
3344

34-
#define BUZZER_VOLUME 4 // loudest!!
35-
//#define BUZZER_VOLUME 3 // pretty good volume for most things
36-
3745
void setup() {
3846
Serial.begin(115200);
3947
Serial.println("Qwiic Buzzer Example_07_Buzz_Melody");
4048
Wire.begin(); //Join I2C bus
4149

42-
//check if buzzer will acknowledge over I2C
50+
//check if buzzer will connect over I2C
4351
if (buzzer.begin() == false) {
44-
Serial.println("Device did not acknowledge! Freezing.");
52+
Serial.println("Device did not connect! Freezing.");
4553
while (1);
4654
}
47-
Serial.println("Buzzer acknowledged.");
55+
Serial.println("Buzzer connected.");
4856

4957
Serial.println("Buzzing Melody now...");
5058
play_melody();
@@ -63,13 +71,12 @@ void play_melody()
6371
// to calculate the note duration, take one second divided by the note type.
6472
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
6573
int noteDuration = 1000 / noteDurations[thisNote];
66-
buzzer.on(melody[thisNote], noteDuration, BUZZER_VOLUME);
74+
buzzer.configureBuzzer(melody[thisNote], noteDuration, SFE_QWIIC_BUZZER_VOLUME_MAX);
75+
buzzer.on();
6776

6877
// to distinguish the notes, set a minimum time between them.
6978
// the note's duration + 30% seems to work well:
7079
int pauseBetweenNotes = noteDuration * 1.30;
7180
delay(pauseBetweenNotes);
72-
// stop the tone playing:
73-
buzzer.off();
7481
}
7582
}

0 commit comments

Comments
 (0)