-
Notifications
You must be signed in to change notification settings - Fork 2
Add audio examples #15
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
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8ea8b84
Create base voice class
sfe-SparkFro 80ee412
Create audio example 1
sfe-SparkFro 9b7a8bc
Add note to audio example about needing a codec
sfe-SparkFro 1c0007a
Rename audio example 1 to match conventions
sfe-SparkFro 38c935a
Add audio resource enum
sfe-SparkFro e109e63
Add audio example 2 (loopback)
sfe-SparkFro 7efffde
Add RING URC handler
sfe-SparkFro 6c2da8c
Add audio example 3 (call control)
sfe-SparkFro 83d58c8
Space out exclamation marks in audio examples
sfe-SparkFro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
129 changes: 129 additions & 0 deletions
129
examples/Audio_Examples/AudioExample1_PlayTone/AudioExample1_PlayTone.ino
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
#include "SparkFun_u-blox_Cellular_Arduino_Library.h" | ||
|
||
// Uncomment the line below that you need for Serial on your platform | ||
#define mySerial Serial1 | ||
// SoftwareSerial mySerial(16, 17); | ||
|
||
// Uncomment the module you're using. If your module is not listed below, then | ||
// it's not supported for this example | ||
UBX_CELL_VOICE_BASE myModule; // This example works with all voice-enabled modules, so this base class can be used | ||
// LARA_R6001 myModule; | ||
// LARA_R6401 myModule; | ||
// LARA_R6801_00B myModule; | ||
|
||
void setup() | ||
{ | ||
Serial.begin(115200); // Start the serial console | ||
|
||
// Wait for user to press key to begin | ||
Serial.println(F("u-blox Cellular Audio Example 1 - Play Tone")); | ||
|
||
Serial.println(); | ||
Serial.println(F("!!!!!!!! ATTENTION !!!!!!!! ATTENTION !!!!!!!! ATTENTION !!!!!!!!")); | ||
Serial.println(F("This example requires an audio codec attached to the I2S interface")); | ||
Serial.println(F("of the cellular modem. Please add one and update this example as")); | ||
Serial.println(F("needed to configure your audio codec!")); | ||
Serial.println(F("!!!!!!!! ATTENTION !!!!!!!! ATTENTION !!!!!!!! ATTENTION !!!!!!!!")); | ||
Serial.println(); | ||
|
||
Serial.println(F("Press any key to begin")); | ||
|
||
while (!Serial.available()) // Wait for the user to press a key (send any serial character) | ||
; | ||
while (Serial.available()) // Empty the serial RX buffer | ||
Serial.read(); | ||
|
||
Serial.println(F("Beginning...")); | ||
|
||
// myModule.enableDebugging(); // Uncomment this line to enable helpful debug messages on Serial | ||
|
||
// For the MicroMod Asset Tracker, we need to invert the power pin so it pulls high instead of low | ||
// Uncomment the next line if required | ||
// myModule.invertPowerPin(true); | ||
|
||
// Initialize the module | ||
if (myModule.begin(mySerial, UBX_CELL_DEFAULT_BAUD_RATE) ) | ||
{ | ||
Serial.println(F("Module connected!")); | ||
} | ||
else | ||
{ | ||
Serial.println(F("Unable to communicate with the module.")); | ||
Serial.println(F("Manually power-on (hold the module's On button for 3 seconds) and try again.")); | ||
while (1) ; // Loop forever on fail | ||
} | ||
Serial.println(); | ||
} | ||
|
||
void loop() | ||
{ | ||
String inputString; | ||
char dtmfChar = 0; | ||
uint16_t frequency = 0; | ||
uint16_t duration = 0; | ||
uint8_t volume = 0; | ||
|
||
while(true) | ||
{ | ||
while(Serial.available() != 0){Serial.read();} | ||
Serial.println(F("Enter a frequency in Hz (300-3400) or a DTMF character (0-9, *, #)")); | ||
while(Serial.available() == 0){} | ||
|
||
inputString = Serial.readStringUntil('\n'); | ||
|
||
if(inputString.length() == 1) | ||
{ | ||
dtmfChar = inputString.charAt(0); | ||
if((dtmfChar >= '0' && dtmfChar <= '9') || dtmfChar == '*' || dtmfChar == '#') | ||
{ | ||
break; | ||
} | ||
} | ||
else | ||
{ | ||
frequency = inputString.toInt(); | ||
if(frequency >= 300 && frequency <= 3400) | ||
{ | ||
dtmfChar == 0; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
while(true) | ||
{ | ||
while(Serial.available() != 0){Serial.read();} | ||
Serial.println(F("Enter a duration in ms (50-1360)")); | ||
while(Serial.available() == 0){} | ||
|
||
inputString = Serial.readStringUntil('\n'); | ||
duration = inputString.toInt(); | ||
if(duration >= 50 && duration <= 1360) | ||
{ | ||
break; | ||
} | ||
} | ||
|
||
while(true) | ||
{ | ||
while(Serial.available() != 0){Serial.read();} | ||
Serial.println(F("Enter a volume (0-100)")); | ||
while(Serial.available() == 0){} | ||
|
||
inputString = Serial.readStringUntil('\n'); | ||
volume = inputString.toInt(); | ||
if(volume <= 100) | ||
{ | ||
break; | ||
} | ||
} | ||
|
||
if(dtmfChar == 0) | ||
{ | ||
myModule.generateToneFreq(frequency, duration, volume); | ||
} | ||
else | ||
{ | ||
myModule.generateToneDTMF(dtmfChar, duration, volume); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
examples/Audio_Examples/AudioExample2_Loopback/AudioExample2_Loopback.ino
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#include "SparkFun_u-blox_Cellular_Arduino_Library.h" | ||
|
||
// Uncomment the line below that you need for Serial on your platform | ||
#define mySerial Serial1 | ||
// SoftwareSerial mySerial(16, 17); | ||
|
||
// Uncomment the module you're using. If your module is not listed below, then | ||
// it's not supported for this example | ||
UBX_CELL_VOICE_BASE myModule; // This example works with all voice-enabled modules, so this base class can be used | ||
// LARA_R6001 myModule; | ||
// LARA_R6401 myModule; | ||
// LARA_R6801_00B myModule; | ||
|
||
void setup() | ||
{ | ||
Serial.begin(115200); // Start the serial console | ||
|
||
// Wait for user to press key to begin | ||
Serial.println(F("u-blox Cellular Audio Example 2 - Loopback")); | ||
|
||
Serial.println(); | ||
Serial.println(F("!!!!!!!! ATTENTION !!!!!!!! ATTENTION !!!!!!!! ATTENTION !!!!!!!!")); | ||
Serial.println(F("This example requires an audio codec attached to the I2S interface")); | ||
Serial.println(F("of the cellular modem. Please add one and update this example as")); | ||
Serial.println(F("needed to configure your audio codec!")); | ||
Serial.println(F("!!!!!!!! ATTENTION !!!!!!!! ATTENTION !!!!!!!! ATTENTION !!!!!!!!")); | ||
Serial.println(); | ||
|
||
Serial.println(F("Press any key to begin")); | ||
|
||
while (!Serial.available()) // Wait for the user to press a key (send any serial character) | ||
; | ||
while (Serial.available()) // Empty the serial RX buffer | ||
Serial.read(); | ||
|
||
Serial.println(F("Beginning...")); | ||
|
||
// myModule.enableDebugging(); // Uncomment this line to enable helpful debug messages on Serial | ||
|
||
// For the MicroMod Asset Tracker, we need to invert the power pin so it pulls high instead of low | ||
// Uncomment the next line if required | ||
// myModule.invertPowerPin(true); | ||
|
||
// Initialize the module | ||
if (myModule.begin(mySerial, UBX_CELL_DEFAULT_BAUD_RATE) ) | ||
{ | ||
Serial.println(F("Module connected!")); | ||
} | ||
else | ||
{ | ||
Serial.println(F("Unable to communicate with the module.")); | ||
Serial.println(F("Manually power-on (hold the module's On button for 3 seconds) and try again.")); | ||
while (1) ; // Loop forever on fail | ||
} | ||
Serial.println(); | ||
} | ||
|
||
void loop() | ||
{ | ||
while(Serial.available() != 0){Serial.read();} | ||
Serial.println(F("Enter any key to begin loopback")); | ||
while(Serial.available() == 0){} | ||
|
||
myModule.playAudioResource(UBX_CELL_AUDIO_RESOURCE_LOOPBACK); | ||
|
||
while(Serial.available() != 0){Serial.read();} | ||
Serial.println(F("Enter any key to stop loopback")); | ||
while(Serial.available() == 0){} | ||
|
||
myModule.stopAudioResource(UBX_CELL_AUDIO_RESOURCE_LOOPBACK); | ||
} |
129 changes: 129 additions & 0 deletions
129
examples/Audio_Examples/AudioExample3_CallControl/AudioExample3_CallControl.ino
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
#include "SparkFun_u-blox_Cellular_Arduino_Library.h" | ||
|
||
// Uncomment the line below that you need for Serial on your platform | ||
#define mySerial Serial1 | ||
// SoftwareSerial mySerial(16, 17); | ||
|
||
// Uncomment the module you're using. If your module is not listed below, then | ||
// it's not supported for this example | ||
UBX_CELL_VOICE_BASE myModule; // This example works with all voice-enabled modules, so this base class can be used | ||
// LARA_R6001 myModule; | ||
// LARA_R6401 myModule; | ||
// LARA_R6801_00B myModule; | ||
|
||
bool callInProgress = false; | ||
bool incomingCall = false; | ||
|
||
void ringCallback() | ||
{ | ||
Serial.println(F("Incoming call! Enter \"A\" to answer, or anything else to reject")); | ||
incomingCall = true; | ||
} | ||
|
||
void setup() | ||
{ | ||
String currentOperator = ""; | ||
|
||
Serial.begin(115200); // Start the serial console | ||
|
||
// Wait for user to press key to begin | ||
Serial.println(F("u-blox Cellular Audio Example 3 - Call Control")); | ||
|
||
Serial.println(); | ||
Serial.println(F("!!!!!!!! ATTENTION !!!!!!!! ATTENTION !!!!!!!! ATTENTION !!!!!!!!")); | ||
Serial.println(F("This example requires an audio codec attached to the I2S interface")); | ||
Serial.println(F("of the cellular modem. Please add one and update this example as")); | ||
Serial.println(F("needed to configure your audio codec!")); | ||
Serial.println(F("!!!!!!!! ATTENTION !!!!!!!! ATTENTION !!!!!!!! ATTENTION !!!!!!!!")); | ||
Serial.println(); | ||
|
||
Serial.println(F("Press any key to begin")); | ||
|
||
while (!Serial.available()) // Wait for the user to press a key (send any serial character) | ||
; | ||
while (Serial.available()) // Empty the serial RX buffer | ||
Serial.read(); | ||
|
||
Serial.println(F("Beginning...")); | ||
|
||
// myModule.enableDebugging(); // Uncomment this line to enable helpful debug messages on Serial | ||
|
||
// For the MicroMod Asset Tracker, we need to invert the power pin so it pulls high instead of low | ||
// Uncomment the next line if required | ||
// myModule.invertPowerPin(true); | ||
|
||
// Initialize the module | ||
if (myModule.begin(mySerial, UBX_CELL_DEFAULT_BAUD_RATE) ) | ||
{ | ||
Serial.println(F("Module connected!")); | ||
} | ||
else | ||
{ | ||
Serial.println(F("Unable to communicate with the module.")); | ||
Serial.println(F("Manually power-on (hold the module's On button for 3 seconds) and try again.")); | ||
while (1) ; // Loop forever on fail | ||
} | ||
Serial.println(); | ||
|
||
// First check to see if we're connected to an operator: | ||
if (myModule.getOperator(¤tOperator) == UBX_CELL_SUCCESS) | ||
{ | ||
Serial.print(F("Connected to: ")); | ||
Serial.println(currentOperator); | ||
} | ||
else | ||
{ | ||
Serial.print(F("The module is not yet connected to an operator. Please use the previous examples to connect. Or wait and retry. Freezing...")); | ||
while (1) | ||
; // Do nothing more | ||
} | ||
|
||
// Set callback function for when a new call is received | ||
myModule.setRingCallback(&ringCallback); | ||
|
||
Serial.println(F("Enter a number to dial")); | ||
|
||
// Clear any input | ||
while(Serial.available()){Serial.read();} | ||
} | ||
|
||
void loop() | ||
{ | ||
String inputString; | ||
|
||
myModule.bufferedPoll(); | ||
|
||
if(Serial.available()) | ||
{ | ||
inputString = Serial.readStringUntil('\n'); | ||
while(Serial.available()){Serial.read();} | ||
|
||
if(incomingCall) | ||
{ | ||
if(inputString == "A" || inputString == "a") | ||
{ | ||
Serial.println(F("Answering call, enter any key to hang up")); | ||
myModule.answer(); | ||
callInProgress = true; | ||
} | ||
else | ||
{ | ||
Serial.println(F("Rejecting call")); | ||
myModule.hangUp(); | ||
} | ||
incomingCall = false; | ||
} | ||
else if(callInProgress == false) | ||
{ | ||
Serial.println("Dialing " + inputString + ", enter any key to hang up"); | ||
myModule.dial(inputString); | ||
callInProgress = true; | ||
} | ||
else | ||
{ | ||
Serial.println(F("Hanging up, enter a new number to dial")); | ||
myModule.hangUp(); | ||
callInProgress = false; | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
#include "sfe_ublox_cellular.h" | ||
#include "sfe_ublox_cellular_voice.h" | ||
#include "sfe_sara_r5.h" | ||
#include "sfe_lara_r6.h" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You probably don't need to worry about it any more, but there was a time when
!!!
would crash avrdude and prevent your code from uploading (onto AVR boards)...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yes, good catch! Doing some research, looks like the problem is actually the original bootloader on the ATMega2560. I agree that we probably don't need to worry about it (I can't any references to it within the last year in Google), but it's easy enough to change.