7

SerialGSM is a library for simplifying GSM shields.

This is sample code for sending SMS:

#include <SerialGSM.h>
#include <SoftwareSerial.h>
SerialGSM cell(2,3);
void setup(){
 Serial.begin(9600);
 cell.begin(9600);
  cell.Verbose(true);
  cell.Boot();
  cell.FwdSMS2Serial();
  cell.Rcpt("+972123456789");
  cell.Message("hello world");
  cell.SendSMS();
}


void loop(){
  if (cell.ReceiveSMS()){
    Serial.println(cell.Message());
    cell.DeleteAllSMS();
  }

}

As you can see, he uses software serial.

I intend to use this for my school thesis, but I am using a shield, so I won't be using Software Serial.

What bothers me is this line

SerialGSM cell(2,3);

In my case, do I declare it like this?:

SerialGSM cell(0,1); 

Or will there be conflicts with serial?

EDIT: In other words, how do I declare the SeralGSM object using hardware serial and not software serial?

Greenonline
  • 3,152
  • 7
  • 36
  • 48
user1584421
  • 1,425
  • 3
  • 26
  • 36

2 Answers2

5

SerialGSM is designed to work with software serial, as you can see that from the class declaration in the SerialGSM.h header:

class SerialGSM : public SoftwareSerial {
...
};

Unfortunately, changing it to use hardware serial is more complicated than it looks. There are two potential ways you could go about it:

  1. Derive from HardwareSerial instead of SoftwareSerial. This would give you flexibility, but you'd have to take care of passing all the right data to the HardwareSerial constructor, which is quite messy.

  2. Don't derive from anything. Use the global Serial object, and manually replace all serial function calls with their Serial.xxx() equivalents. This is probably easier, but it restricts you to a specific serial port.

Both approaches involve quite a lot of coding, so they aren't trivial tasks. It's also important to note that SerialGSM currently uses the global Serial object to output debug information. You'd have to remove or modify that before converting to hardware serial, or else it could interfere.

Peter Bloomfield
  • 10,982
  • 9
  • 48
  • 87
2

Never mind, i went with the GSM SMS example from arduino 1.0.5 (Don't know the version of arduino IDE that included this) and works fine.

If you are considering using the SerialGSM library there is no need to!

CAUTION: In the Arduino's library, when you declare the phone number, you have to use international format

(Thanks bloomfield for the info you provided in the previous answer)

user1584421
  • 1,425
  • 3
  • 26
  • 36