Tuesday, 23 December 2014

EFCom Pro GSM connecting to Arduino

I ordered the EFCom Pro GSM module this month and to be honest it was beyond "fun" to get it working. Being cheap I ordered it for half of what the official Arduino GSM modules goes for so was determined to get it to work (even though the documentation available at present pretty much doesn't exist.


Arduino software serial has a limit of 38400 in baud rate due to the processing that would be required for faster baud rates. Unfortunately the EFCOM GSM Pro comes with auto-bauding enabled (mine seemed to always go to 115200) - causing insane headaches for anyone trying to connect it to an Arduino. 

You may be getting funky characters, a favourite seems to be y...

The sketch below seemed to do the trick, after a power off/on cycle the GSM came back at 19200. To do this you need to use the hardware pins on the Arduino, I have the Arduino UNO so pin 0 for RX (connects to the GSM module's TX pin) and pin 1 for TX (connects to the GSM module's RX pin), then I loaded the ugly sketch:

void setup()             
{
  Serial.begin(115200);        
}

void loop()                   
{
  if (Serial.available()){
    Serial.println(Serial.read());
  }
  Serial.println("AT");
  Serial.println("AT+IPR=19200");
}

The above sketch could be skipped if you plan to keep using the pin 0 and pin 1 on the Arduino at 115200. The GSM module should flash a light every 3 seconds to indicate it's on a network and that part is okay.


You can also connect the RST from the EFCom Pro to a digital pin, in my case pin 5 and PWR I connected to pin 6. I connected two switches, the aim was to send an SMS when either switch was triggered and a voice call with if the first switch was triggered.

The example sketch is below:

const int switchOne = 2;     // Digital 2 -> Door switch 1
const int switchTwo = 4;     // Digital 4 -> Door switch 2
int switchOneState = 0;
int switchTwoState = 0;
int messageOneSent = 0;
int messageTwoSent = 0;

void setup()
{
 Serial.begin(19200);
 //Serial.print("Setup complete...\n");

 delay(1000);
 digitalWrite(6, LOW);   // Turn the GSM Modem OFF - connect PWR from GSM board to pin 6 digital
 digitalWrite(6, HIGH);   // Turn the GSM Modem ON
 //digitalWrite(5, LOW);  // Reset the GSM Modem - connect RST from GSM board to pin 5 digital

 pinMode(switchOne, INPUT);
 pinMode(switchTwo, INPUT);

 delay(20000);//Wait for GSM to come online
 send_message("GSM system has been turned on and is ready...");
}

void loop()
{

 //Serial.print("Looping\n");
 switchOneState = digitalRead(switchOne);
 switchTwoState = digitalRead(switchTwo);

 if (switchOneState == LOW){
  //Switch one
  if (messageOneSent == 0){
   voice_call();
   send_message("Door one closed :-)\n");
   messageOneSent = 1;
  }//else don't keep sending for a determined condition
 } else {
  messageOneSent = 0;
 }

 if (switchTwoState == LOW){
  //Switch two
  if (messageTwoSent == 0){
   send_message("Door two closed :-)\n");
   messageTwoSent = 1;
  }//else don't keep sending for a determined condition
 } else {
  messageTwoSent = 0;
 }
 delay(1000);
}

void send_message(char msg[255])
{
  //Serial.print("Sending message:");
  //Serial.print(msg);
  //Serial.print("\n");
  Serial.print("AT\r");
  delay(100);                    //Wait for a second while the modem sends an "OK"
  Serial.print("AT+CMGF=1\r");    //Because we want to send the SMS in text mode
  delay(100);
  Serial.print("AT+CMGS=\"+27xxxxxxxxx\"\r");
  delay(100);
  Serial.print(msg);   //The text for the message
  delay(100);
  Serial.print(char(26));    //Because we want to send the SMS in text mode
  delay(10000);
}

void voice_call()
{
  Serial.println("ATD + +27xxxxxxxxxx;");
  delay(10000);
  Serial.print("ATD + ATH");
  delay(100);
}

The amount of time the module takes to register on the network does vary, on Cell C in South Africa it took around 8 seconds before I could start sending messages. Sending an SMS however took about 5-7 seconds, so I have a delay of 10000, ideally I should have a loop checking for serial available but it wasn't such a complex project that required the additional code.

Another issue I encountered was the power requirement for the GSM module, many websites including the official one claims a need for a 2A supply (testing I couldn't get it to consume more than 0.1A).

I followed the advice nonetheless and powered both the Arduino and GSM module from a 5V 3A supply (the smallest I had in the cupboard above 2A) - just remember that the serial comms rely on having a common ground so if you power the Arduino from USB and the GSM module from a supply the serial seems to be a complete failure.

Hope the above helps someone not pull out as many hairs as I have...