Skip to content
David A. Mellis edited this page Jan 10, 2014 · 18 revisions

This library complements the Arduino GSM library by providing additional commands for controlling the Quectel M10 GSM module found on the Arduino GSM shield, DIY Cellphone, and Cellphone Module.

Classes: GSM3VolumeService, GSM3ClockService, GSM3DTMF

GSM3VolumeService

Set and get the volume of the speaker, as used for voice calls. To use: #include <GSM3VolumeService.h>

void setVolume(int);

Set the volume, from 0 to 100.

void checkVolume();

Query the GSM module for the current volume. Use ready() to check if the module has responded and getVolume() to retrieve the current volume.

volume.checkVolume(); // query the GSM module for the current volume
while (!volume.ready()); // wait for it to respond

// if the response was successful, get the volume and print it
if (volume.ready() == 1) {
  Serial.print("volume: ");
  Serial.println(volume.getVolume());
}

int getVolume();

Returns the current volume, either the last volume set with setVolume() or the last volume returned by the module through a call to checkVolume().

int ready();

Check the status of the latest query of the GSM module (with checkVolume()). Returns 0 if the command is still pending, 1 on success, and greater than 1 on error.

Example Code

#include <GSM.h>
#include <GSM3VolumeService.h>

GSM gsm(true);
GSMVoiceCall vcs;
GSM3VolumeService volume;
int potval;

void setup()
{
  pinMode(31, INPUT_PULLUP);
  pinMode(19, OUTPUT);
  digitalWrite(19, LOW);
  delay(12000);
  digitalWrite(19, HIGH);  
  while (gsm.begin(0, false) != GSM_READY);
}

void loop()
{
  if (vcs.getvoiceCallStatus() == RECEIVINGCALL && digitalRead(31) == LOW) { vcs.answerCall(); delay(500); }
  if (vcs.getvoiceCallStatus() == TALKING && digitalRead(31) == LOW) { vcs.hangCall(); delay(500); }
  
  // if the reading from the analog input has changed by some small amount, set the volume
  if (abs(analogRead(A0) - potval) > 10) {
    // analogRead() returns values from 0 to 1023, map that to 0 to 100 (the range for setVolume).
    potval = analogRead(A0);
    volume.setVolume(map(potval, 0, 1023, 0, 100));
  }
}

GSM3ClockService

Get and set the time on the GSM module. To use #include <GSM3ClockService.h>

int setTime(int year, int month, int day, int hour, int minute, int second);

Set the time on the GSM module.

Parameters:

  • year: the current year, two digits (0 to 99)
  • month: the current month (1 to 12)
  • day: the day of the month (1 to 31)
  • hour: the hour of the day (0 to 23)
  • minute: the minute of the hour (0 to 59)
  • second: the second of the minute (0 to 59)

int checkTime()

Ask the GSM module for the current time. After calling, checkTime(), use ready() to check if the module has responded and the getXXX() functions to retrieve the current time. If you don't call checkTime(), the getXXX() functions will use the last value passed to setTime().

int ready()

Use to check if the module has responded to the query initiated by checkTime(). Returns 0 if the module hasn't responded yet, 1 on a successful response, or greater than 1 on an unsuccessful one.

int getYear()

Returns the current year, two digits (0 to 99). (Call checkTime() first.)

int getMonth()

Returns the current month (1 to 12). (Call checkTime() first.)

int getDay()

Returns the current day of the month (1 to 31). (Call checkTime() first.)

int getHour()

Returns the current hour of the day (0 to 59). (Call checkTime() first.)

int getMinute()

Returns the current minute of the hour (0 to 59). (Call checkTime() first.)

int getSecond()

Returns the current second of the minute (0 to 59). (Call checkTime() first.)

Example Code

#include <GSM.h>
#include <GSM3ClockService.h>

GSM gsm(true); // Main gsm object. Pass true to the constructor to enable serial debugging output.
GSM3ClockService clock;

void setup()
{
  Serial.begin(9600);
  
  pinMode(19, OUTPUT);
  digitalWrite(19, LOW);
  delay(12000);
  digitalWrite(19, HIGH);
  
  while(gsm.begin(0, false) != GSM_READY);
  
  // set the time to 10 am on January 11, 2014
  clock.setTime(14, 1, 11, 10, 0, 0);
}

void loop()
{
  clock.checkTime();
  while (!clock.ready());
  Serial.print(clock.getMonth());
  Serial.print("/");
  Serial.print(clock.getDay());
  Serial.print("/20");
  Serial.print(clock.getYear());
  Serial.print(" ");
  Serial.print(clock.getHour());
  Serial.print(":");
  if (clock.getMinute() < 10) Serial.print("0");
  Serial.print(clock.getMinute());
  Serial.print(":");
  if (clock.getSecond() < 10) Serial.print("0");
  Serial.print(clock.getSecond());
  Serial.println();
  
  delay(1000);
}

GSM3DTMF

Plays DTMF tones on a voice call (for navigating automated menus, entering voicemail passwords, etc).

void tone(char);

Play a tone on the remote end of the voice call (i.e. audible to the person or system you're calling, but not to you). The parameter can be '0' to '9', '#', or '*'.

void localTone(char);

Play a tone on the local end of the voice call (i.e. audible to you, but not the person or system you're calling). The parameter can be '0' to '9', '#', or '*'.