RETIRED - MG2639 Cellular Shield Hookup Guide

This Tutorial is Retired!

This tutorial covers concepts or technologies that are no longer current. It's still here for you to read and enjoy, but may not be as useful as our newest tutorials.

Contributors: jimblom
Favorited Favorite 8

Example 3: Phone Calls

Remember when cell phones were used to make and receive phone calls? When you would actually speak and listen to the person you were communicating with? They can still do that! The MG2639 Cell Shield can do that! If you're longing for the good old days, or want to create your own version of the Port-o-Rotary, here's an example that turns your MG2639 into a phone.

Before proceeding with this example, you'll need to connect a microphone and speaker to your shield. You'll also need to make sure your cell plan includes the ability to make and receive voice calls.

If you're using a passive microphone and speaker, you can simply connect them to the differential pins on the audio port. Connect the microphone pins to MIC+ and MIC- and speaker wires to SPK+ and SPK-. Or you can come up with a more elegant, amplified solution using the single ended inputs.

Speaker and microphone connected to cell shield

Full-size breadboards are perfect for creating a breadboard handset.

It is important to remember which pair of audio channels you use, the MG2639 can only interact with one at a time.

Running the Example

To load up the MG2639_Phone example, go to File > Examples > SparkFun MG2639 CellShield > MG2639_Phone.

Depending on which audio channel you use, you may need to alter the phone.setAudioChannel(AUDIO_CHANNEL_DIFFERENTIAL) line to phone.setAudioChannel(AUDIO_CHANNEL_SINGLE). Then click upload.

As with every other sketch, send any character in the serial monitor to make it run. Next, either try calling your MG2639 from another phone, or type D1234567890X to dial a phone number ("D" indicates the beginning of a phone number, "X" indicates the end, they're case-sensitive).

Example serial terminal phone call

If a call is coming in, the serial terminal will print a message saying so. Press any key to answer it. While the call is active, press any key to hang up.

Using the Library: Phone

Once again, to segment out the library, a separate class is defined for phone functions: phone. Here is a quick rundown of functions made available:

Incoming/Outgoing Phone Call Status

You can use phone.status() to check whether the phone is ringing, dialing, active or idle. This function will return one of the following constants:

  • CALL_ACTIVE -- Active phone call. Either an outgoing call has been picked up or an incoming call was phone.answer()'ed and hasn't been hung up yet.
  • CALL_DIALING -- An outgoing call is in the process of dialing. This status precedes ringing.
  • CALL_DIALED_RINGING -- An outgoing call has been dialed and is ringing on the other end.
  • CALL_INCOMING -- A call is coming in. If a speaker is attached it should be ringing.

Check out the comments in the example sketch for help using this function.

Caller ID

If a call is coming in, you can use the callerID(char * phoneNumber) function to attempt to get the number. This function only returns an error code, it requires a character array be passed to it by reference so it can store the calling number there.

Here's a simple function from the example that gets the caller ID and prints it to the serial monitor:

void printCallerID()
  char yourPhone[15];
  Serial.print("Phone call coming in from: ");
  Serial.println("Press any key to answer.");

Answering, Rejecting, and Hanging Up

If a call is coming in -- phone.status() is returning CALL_INCOMING -- you can use phone.answer() to pick it up.

If you've checked the caller ID and don't really feel like talking to the individual paired with that number, you have two options: ignore the call until they hang up or run phone.hangUp() to reject the call.

Likewise, if you've answered the call and want to end it, call phone.hangUp() to close the line.


If you want to initiate a phone call, use phone.dial(char * phoneNumber) to start dialing. phoneNumber should be a character array formatted like any phone number you would dial from a normal phone. If you're in the same area code, it may be as few as 7 digits (assuming it's a U.S. number). On the other end of the spectrum, with international codes included, the number can be as long as 15 digits.

Here's a quick example:

char destinationPhone[] = "13032840979"; // SparkFun HQ - 1-303-284-0979
phone.dial(destinationPhone); // Dial the phone number
    int phoneStatus = phone.status();
} while ((phoneStatus != CALL_ACTIVE) || (phoneStatus != CALL_IDLE))
if (callStatus == CALL_ACTIVE)
    Serial.println("Other end picked up!");

Again, you can use phone.hangUp() to end the call, unless the other party does so first.