|
| 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 | +} |
0 commit comments