Skip to content

Commit 6a73506

Browse files
authored
Merge pull request #15 from sparkfun/add_audio_examples
Add audio examples
2 parents 4c995f0 + 83d58c8 commit 6a73506

File tree

5 files changed

+379
-1
lines changed

5 files changed

+379
-1
lines changed
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
#include "SparkFun_u-blox_Cellular_Arduino_Library.h"
2+
3+
// Uncomment the line below that you need for Serial on your platform
4+
#define mySerial Serial1
5+
// SoftwareSerial mySerial(16, 17);
6+
7+
// Uncomment the module you're using. If your module is not listed below, then
8+
// it's not supported for this example
9+
UBX_CELL_VOICE_BASE myModule; // This example works with all voice-enabled modules, so this base class can be used
10+
// LARA_R6001 myModule;
11+
// LARA_R6401 myModule;
12+
// LARA_R6801_00B myModule;
13+
14+
void setup()
15+
{
16+
Serial.begin(115200); // Start the serial console
17+
18+
// Wait for user to press key to begin
19+
Serial.println(F("u-blox Cellular Audio Example 1 - Play Tone"));
20+
21+
Serial.println();
22+
Serial.println(F("! ! ! ! ! ATTENTION ! ! ! ! ! ATTENTION ! ! ! ! ! ATTENTION ! ! ! ! !"));
23+
Serial.println(F("This example requires an audio codec attached to the I2S interface"));
24+
Serial.println(F("of the cellular modem. Please add one and update this example as"));
25+
Serial.println(F("needed to configure your audio codec!"));
26+
Serial.println(F("! ! ! ! ! ATTENTION ! ! ! ! ! ATTENTION ! ! ! ! ! ATTENTION ! ! ! ! !"));
27+
Serial.println();
28+
29+
Serial.println(F("Press any key to begin"));
30+
31+
while (!Serial.available()) // Wait for the user to press a key (send any serial character)
32+
;
33+
while (Serial.available()) // Empty the serial RX buffer
34+
Serial.read();
35+
36+
Serial.println(F("Beginning..."));
37+
38+
// myModule.enableDebugging(); // Uncomment this line to enable helpful debug messages on Serial
39+
40+
// For the MicroMod Asset Tracker, we need to invert the power pin so it pulls high instead of low
41+
// Uncomment the next line if required
42+
// myModule.invertPowerPin(true);
43+
44+
// Initialize the module
45+
if (myModule.begin(mySerial, UBX_CELL_DEFAULT_BAUD_RATE) )
46+
{
47+
Serial.println(F("Module connected!"));
48+
}
49+
else
50+
{
51+
Serial.println(F("Unable to communicate with the module."));
52+
Serial.println(F("Manually power-on (hold the module's On button for 3 seconds) and try again."));
53+
while (1) ; // Loop forever on fail
54+
}
55+
Serial.println();
56+
}
57+
58+
void loop()
59+
{
60+
String inputString;
61+
char dtmfChar = 0;
62+
uint16_t frequency = 0;
63+
uint16_t duration = 0;
64+
uint8_t volume = 0;
65+
66+
while(true)
67+
{
68+
while(Serial.available() != 0){Serial.read();}
69+
Serial.println(F("Enter a frequency in Hz (300-3400) or a DTMF character (0-9, *, #)"));
70+
while(Serial.available() == 0){}
71+
72+
inputString = Serial.readStringUntil('\n');
73+
74+
if(inputString.length() == 1)
75+
{
76+
dtmfChar = inputString.charAt(0);
77+
if((dtmfChar >= '0' && dtmfChar <= '9') || dtmfChar == '*' || dtmfChar == '#')
78+
{
79+
break;
80+
}
81+
}
82+
else
83+
{
84+
frequency = inputString.toInt();
85+
if(frequency >= 300 && frequency <= 3400)
86+
{
87+
dtmfChar == 0;
88+
break;
89+
}
90+
}
91+
}
92+
93+
while(true)
94+
{
95+
while(Serial.available() != 0){Serial.read();}
96+
Serial.println(F("Enter a duration in ms (50-1360)"));
97+
while(Serial.available() == 0){}
98+
99+
inputString = Serial.readStringUntil('\n');
100+
duration = inputString.toInt();
101+
if(duration >= 50 && duration <= 1360)
102+
{
103+
break;
104+
}
105+
}
106+
107+
while(true)
108+
{
109+
while(Serial.available() != 0){Serial.read();}
110+
Serial.println(F("Enter a volume (0-100)"));
111+
while(Serial.available() == 0){}
112+
113+
inputString = Serial.readStringUntil('\n');
114+
volume = inputString.toInt();
115+
if(volume <= 100)
116+
{
117+
break;
118+
}
119+
}
120+
121+
if(dtmfChar == 0)
122+
{
123+
myModule.generateToneFreq(frequency, duration, volume);
124+
}
125+
else
126+
{
127+
myModule.generateToneDTMF(dtmfChar, duration, volume);
128+
}
129+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#include "SparkFun_u-blox_Cellular_Arduino_Library.h"
2+
3+
// Uncomment the line below that you need for Serial on your platform
4+
#define mySerial Serial1
5+
// SoftwareSerial mySerial(16, 17);
6+
7+
// Uncomment the module you're using. If your module is not listed below, then
8+
// it's not supported for this example
9+
UBX_CELL_VOICE_BASE myModule; // This example works with all voice-enabled modules, so this base class can be used
10+
// LARA_R6001 myModule;
11+
// LARA_R6401 myModule;
12+
// LARA_R6801_00B myModule;
13+
14+
void setup()
15+
{
16+
Serial.begin(115200); // Start the serial console
17+
18+
// Wait for user to press key to begin
19+
Serial.println(F("u-blox Cellular Audio Example 2 - Loopback"));
20+
21+
Serial.println();
22+
Serial.println(F("! ! ! ! ! ATTENTION ! ! ! ! ! ATTENTION ! ! ! ! ! ATTENTION ! ! ! ! !"));
23+
Serial.println(F("This example requires an audio codec attached to the I2S interface"));
24+
Serial.println(F("of the cellular modem. Please add one and update this example as"));
25+
Serial.println(F("needed to configure your audio codec!"));
26+
Serial.println(F("! ! ! ! ! ATTENTION ! ! ! ! ! ATTENTION ! ! ! ! ! ATTENTION ! ! ! ! !"));
27+
Serial.println();
28+
29+
Serial.println(F("Press any key to begin"));
30+
31+
while (!Serial.available()) // Wait for the user to press a key (send any serial character)
32+
;
33+
while (Serial.available()) // Empty the serial RX buffer
34+
Serial.read();
35+
36+
Serial.println(F("Beginning..."));
37+
38+
// myModule.enableDebugging(); // Uncomment this line to enable helpful debug messages on Serial
39+
40+
// For the MicroMod Asset Tracker, we need to invert the power pin so it pulls high instead of low
41+
// Uncomment the next line if required
42+
// myModule.invertPowerPin(true);
43+
44+
// Initialize the module
45+
if (myModule.begin(mySerial, UBX_CELL_DEFAULT_BAUD_RATE) )
46+
{
47+
Serial.println(F("Module connected!"));
48+
}
49+
else
50+
{
51+
Serial.println(F("Unable to communicate with the module."));
52+
Serial.println(F("Manually power-on (hold the module's On button for 3 seconds) and try again."));
53+
while (1) ; // Loop forever on fail
54+
}
55+
Serial.println();
56+
}
57+
58+
void loop()
59+
{
60+
while(Serial.available() != 0){Serial.read();}
61+
Serial.println(F("Enter any key to begin loopback"));
62+
while(Serial.available() == 0){}
63+
64+
myModule.playAudioResource(UBX_CELL_AUDIO_RESOURCE_LOOPBACK);
65+
66+
while(Serial.available() != 0){Serial.read();}
67+
Serial.println(F("Enter any key to stop loopback"));
68+
while(Serial.available() == 0){}
69+
70+
myModule.stopAudioResource(UBX_CELL_AUDIO_RESOURCE_LOOPBACK);
71+
}
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
#include "SparkFun_u-blox_Cellular_Arduino_Library.h"
2+
3+
// Uncomment the line below that you need for Serial on your platform
4+
#define mySerial Serial1
5+
// SoftwareSerial mySerial(16, 17);
6+
7+
// Uncomment the module you're using. If your module is not listed below, then
8+
// it's not supported for this example
9+
UBX_CELL_VOICE_BASE myModule; // This example works with all voice-enabled modules, so this base class can be used
10+
// LARA_R6001 myModule;
11+
// LARA_R6401 myModule;
12+
// LARA_R6801_00B myModule;
13+
14+
bool callInProgress = false;
15+
bool incomingCall = false;
16+
17+
void ringCallback()
18+
{
19+
Serial.println(F("Incoming call! Enter \"A\" to answer, or anything else to reject"));
20+
incomingCall = true;
21+
}
22+
23+
void setup()
24+
{
25+
String currentOperator = "";
26+
27+
Serial.begin(115200); // Start the serial console
28+
29+
// Wait for user to press key to begin
30+
Serial.println(F("u-blox Cellular Audio Example 3 - Call Control"));
31+
32+
Serial.println();
33+
Serial.println(F("! ! ! ! ! ATTENTION ! ! ! ! ! ATTENTION ! ! ! ! ! ATTENTION ! ! ! ! !"));
34+
Serial.println(F("This example requires an audio codec attached to the I2S interface"));
35+
Serial.println(F("of the cellular modem. Please add one and update this example as"));
36+
Serial.println(F("needed to configure your audio codec!"));
37+
Serial.println(F("! ! ! ! ! ATTENTION ! ! ! ! ! ATTENTION ! ! ! ! ! ATTENTION ! ! ! ! !"));
38+
Serial.println();
39+
40+
Serial.println(F("Press any key to begin"));
41+
42+
while (!Serial.available()) // Wait for the user to press a key (send any serial character)
43+
;
44+
while (Serial.available()) // Empty the serial RX buffer
45+
Serial.read();
46+
47+
Serial.println(F("Beginning..."));
48+
49+
// myModule.enableDebugging(); // Uncomment this line to enable helpful debug messages on Serial
50+
51+
// For the MicroMod Asset Tracker, we need to invert the power pin so it pulls high instead of low
52+
// Uncomment the next line if required
53+
// myModule.invertPowerPin(true);
54+
55+
// Initialize the module
56+
if (myModule.begin(mySerial, UBX_CELL_DEFAULT_BAUD_RATE) )
57+
{
58+
Serial.println(F("Module connected!"));
59+
}
60+
else
61+
{
62+
Serial.println(F("Unable to communicate with the module."));
63+
Serial.println(F("Manually power-on (hold the module's On button for 3 seconds) and try again."));
64+
while (1) ; // Loop forever on fail
65+
}
66+
Serial.println();
67+
68+
// First check to see if we're connected to an operator:
69+
if (myModule.getOperator(&currentOperator) == UBX_CELL_SUCCESS)
70+
{
71+
Serial.print(F("Connected to: "));
72+
Serial.println(currentOperator);
73+
}
74+
else
75+
{
76+
Serial.print(F("The module is not yet connected to an operator. Please use the previous examples to connect. Or wait and retry. Freezing..."));
77+
while (1)
78+
; // Do nothing more
79+
}
80+
81+
// Set callback function for when a new call is received
82+
myModule.setRingCallback(&ringCallback);
83+
84+
Serial.println(F("Enter a number to dial"));
85+
86+
// Clear any input
87+
while(Serial.available()){Serial.read();}
88+
}
89+
90+
void loop()
91+
{
92+
String inputString;
93+
94+
myModule.bufferedPoll();
95+
96+
if(Serial.available())
97+
{
98+
inputString = Serial.readStringUntil('\n');
99+
while(Serial.available()){Serial.read();}
100+
101+
if(incomingCall)
102+
{
103+
if(inputString == "A" || inputString == "a")
104+
{
105+
Serial.println(F("Answering call, enter any key to hang up"));
106+
myModule.answer();
107+
callInProgress = true;
108+
}
109+
else
110+
{
111+
Serial.println(F("Rejecting call"));
112+
myModule.hangUp();
113+
}
114+
incomingCall = false;
115+
}
116+
else if(callInProgress == false)
117+
{
118+
Serial.println("Dialing " + inputString + ", enter any key to hang up");
119+
myModule.dial(inputString);
120+
callInProgress = true;
121+
}
122+
else
123+
{
124+
Serial.println(F("Hanging up, enter a new number to dial"));
125+
myModule.hangUp();
126+
callInProgress = false;
127+
}
128+
}
129+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
#include "sfe_ublox_cellular.h"
2+
#include "sfe_ublox_cellular_voice.h"
23
#include "sfe_sara_r5.h"
34
#include "sfe_lara_r6.h"

0 commit comments

Comments
 (0)