Power could be an issue. Both devices require a bit of current.
But as far as interfacing, the Mega 2560 has some software serial limitations last I heard. If you are using software serial (D2 and D3), the Mega may have problems.
This is from the software serial reference:
Not all pins on the Mega and Mega 2560 support change interrupts, so only the following can be used for RX: 10, 11, 12, 13, 14, 15, 50, 51, 52, 53, A8 (62), A9 (63), A10 (64), A11 (65), A12 (66), A13 (67), A14 (68), A15 (69).
void GSMShield::sendSMS(String text) {
Serial1.begin(19200);
delay(1000); //Wait for a second while the modem sends an "OK"
Serial1.println("AT+CMGF=1"); //Because we want to send the SMS in text mode
delay(1000);
Serial1.println("AT+CMGS=\"+xxxxxxxxxxx\""); //Start accepting the text for the message
//to be sent to the number specified.
//Replace this number with the target mobile number.
delay(1000);
Serial1.println(text);
delay(1000);
Serial1.print("\x1A");
Serial.println("Send sms");
delay(5000);
}
Class Ethernet Shield:
void Internet::connectToInternet() {
Ethernet.begin(mac, ip);
if(client.connect(gateway, 80)) {
Serial.println("SUCCESS: I have internet connection");
} else {
Serial.println("ERROR: I don't have internet connection. I will try new connection.");
delay(10000);
this->connectToInternet();
}
}
Main code:
Internet internet;
GSMShield gsm;
void setup() {
Serial.begin(19200);
pinMode(6, OUTPUT);
internet.connectToInternet();
digitalWrite(6, HIGH); // Power on GSM shield
delay(10000); // wait for connect to gsm network
gsm.sendSms("Any text")
}