Skip to content

Commit bd86a3d

Browse files
committed
Firmware Version read example
1 parent 91b4491 commit bd86a3d

File tree

4 files changed

+93
-0
lines changed

4 files changed

+93
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/******************************************************************************
2+
Example_09_FirmwareVersion
3+
4+
This example shows how to read the firmware version from the Qwiic Buzzer
5+
6+
By Pete Lewis @ SparkFun Electronics
7+
December 2023
8+
9+
Based on code orginally written by Fischer Moseley @ SparkFun Electronics
10+
Original Creation Date: June 28, 2019
11+
12+
SparkFun code, firmware, and software is released under the MIT License.
13+
Please see LICENSE.md for further details.
14+
15+
Hardware Connections:
16+
Connect QWIIC cable from Arduino to Qwiic Buzzer
17+
18+
Distributed as-is; no warranty is given.
19+
******************************************************************************/
20+
21+
#include <SparkFun_Qwiic_Buzzer_Arduino_Library.h>
22+
QwiicBuzzer buzzer;
23+
24+
// variables to store the firmware version (major and Minor),
25+
// read back from the Qwiic Buzzer
26+
uint8_t firmwareVersionMajor;
27+
uint8_t firmwareVersionMinor;
28+
29+
sfeTkError_t err; // used for checking for errors
30+
31+
void setup() {
32+
Serial.begin(115200);
33+
Serial.println("Qwiic Buzzer Example_09_FirmwareVersion");
34+
Wire.begin(); //Join I2C bus
35+
36+
//check if buzzer will connect over I2C
37+
if (buzzer.begin() == false) {
38+
Serial.println("Device did not connect! Freezing.");
39+
while (1);
40+
}
41+
Serial.println("Buzzer connected.");
42+
43+
err = buzzer.firmwareVersionMajor(firmwareVersionMajor);
44+
45+
// Check whether the firmware read was successful
46+
if (err != kSTkErrOk)
47+
{
48+
Serial.println("Could not read firmware version Major. Freezing.");
49+
while (1);
50+
}
51+
52+
err = buzzer.firmwareVersionMinor(firmwareVersionMinor);
53+
54+
// Check whether the firmware read was successful
55+
if (err != kSTkErrOk)
56+
{
57+
Serial.println("Could not read firmware version Minor. Freezing.");
58+
while (1);
59+
}
60+
61+
Serial.println("Firmware Version read successfully!");
62+
63+
Serial.print("Firmware Version Major: ");
64+
Serial.println(firmwareVersionMajor);
65+
Serial.print("Firmware Version Minor: ");
66+
Serial.println(firmwareVersionMinor);
67+
}
68+
69+
void loop() {
70+
// do nothing here
71+
}

keywords.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ begin KEYWORD2
1414
isConnected KEYWORD2
1515
setAddress KEYWORD2
1616
address KEYWORD2
17+
firmwareVersionMajor KEYWORD2
18+
firmwareVersionMinor KEYWORD2
1719
configureBuzzer KEYWORD2
1820
on KEYWORD2
1921
off KEYWORD2

src/sfeQwiicBuzzer.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,16 @@ sfeTkError_t sfeQwiicBuzzer::deviceId(uint8_t &deviceId)
6363
return _theBus->readRegisterByte(kSfeQwiicBuzzerRegId, deviceId);
6464
}
6565

66+
sfeTkError_t sfeQwiicBuzzer::firmwareVersionMajor(uint8_t &versionMajor)
67+
{
68+
return _theBus->readRegisterByte(kSfeQwiicBuzzerRegFirmwareMajor, versionMajor);
69+
}
70+
71+
sfeTkError_t sfeQwiicBuzzer::firmwareVersionMinor(uint8_t &versionMinor)
72+
{
73+
return _theBus->readRegisterByte(kSfeQwiicBuzzerRegFirmwareMinor, versionMinor);
74+
}
75+
6676
sfeTkError_t sfeQwiicBuzzer::configureBuzzer(const uint16_t toneFrequency, const uint16_t duration, const uint8_t volume)
6777
{
6878
// All of the necessary configuration register address are in sequencial order

src/sfeQwiicBuzzer.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,16 @@ class sfeQwiicBuzzer
6262
/// @return 0 for succuss, negative for errors, positive for warnings
6363
sfeTkError_t deviceId(uint8_t &deviceId);
6464

65+
/// @brief Reads the Firmware Version Major of the Qwiic Buzzer
66+
/// @param versionMajor Variable where the read results will be stored
67+
/// @return 0 for succuss, negative for errors, positive for warnings
68+
sfeTkError_t firmwareVersionMajor(uint8_t &versionMajor);
69+
70+
/// @brief Reads the Firmware Version Minor of the Qwiic Buzzer
71+
/// @param versionMinor Variable where the read results will be stored
72+
/// @return 0 for succuss, negative for errors, positive for warnings
73+
sfeTkError_t firmwareVersionMinor(uint8_t &versionMinor);
74+
6575
/// @brief Configures the Qwiic Buzzer without causing the buzzer to buzz.
6676
/// This allows configuration in silence (before you may want to buzz).
6777
/// It is also useful in combination with saveSettings(), and then later

0 commit comments

Comments
 (0)