Ethernet shield + SM5100B GSM/GPRS Module

I’m using an ethernet shield to poll a php page for changes. It works great(ish)!

I also have a SM5100B shield from sparkfun: I’ve gotten it to send and receive texts.

Now, I’d like to get my chocolate in my peanut butter and have them to work together. The Ethernet shield gets an update from the web, the SM5100B sends a text.

I can connect fine to a server through the ethernet shield when I’m not stacking the boards, but as soon as I pop on the GSM shield, the ethernet no longer works, but the modem does. Any ideas why?

Code below (edited to add comments!):

#include <SPI.h>
#include <Ethernet.h>
#include <NewSoftSerial.h>  //Include the NewSoftSerial library to send serial commands to the cellular module.
#include <string.h>         //Used for string manipulations

byte mac[] = {  
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //MAC addresss (self-assigned)
byte ip[] = {
  192,168,1,177 };                      //my IPaddress
byte server[] = {
  173,236,156,236 };                    //Who are we talking to?

String content="                    "; //to hold stuff from the web, eventually to send out
int stringPos=0;                        //position in the array for writing web content
char inChar=0;                         //Will hold the incoming character from the Ethernet Interface 

char incoming_char=0;      //Will hold the incoming character from the Cell Serial Port

NewSoftSerial cell(2,3);  //Create a 'fake' serial port. Pin 2 is the Rx pin, pin 3 is the Tx pin.

// Initialize the Ethernet client library

void setup() {
  // start the Ethernet connection:
  Ethernet.begin(mac, ip);
    // give the Ethernet shield a second to initialize:
  // start the serial library:
  cell.begin(9600); //start cell communication

void loop()
// Initialize the Ethernet client library
  Client client =Client(server, 80); // 
    // Make a HTTP request if connected:
    client.println("GET /sms/out.php HTTP/1.1");
        // kf[sic] you didn't get a connection to the server:
    Serial.println("Error connecting");

//this strips out the header information 
   if (client.available()) {
       goto readAgain;}
       Serial.println("found message start");
//refill the buffer...   
  //this reads to the end of the 'data'
   if (client.available()) {
    goto getMore;}

//if we're all done, why not disconnect? Seems like a nice thing to do
  if (!client.connected()) {
//reset the parameters for the web reading
  content="                    ";
  //while there's stuff in the cell modem buffer
  {;    //Get the character from the cellular serial port.
    Serial.print(incoming_char);  //Print the incoming character to the terminal.

       goto readAgain;}

This can be done using a while loop, avoiding the dreaded goto statement.

while((inChar = !='`'){} // Do nothing until the right character is received

The SoftwareSerial class is obsolete. The NewSoftSerial class should be used, instead.

as soon as I pop on the GSM shield, the ethernet no longer works, but the modem does. Any ideas why?

Sounds like a pin incompatibility issue. The GSM shield only uses pins 0 and 1 or 2 and 3. Which pins does the ethernet shield use? Which shield is it?

The GSM shield only uses pins 0 and 1 or 2 and 3. Which pins does the ethernet shield use? Which shield is it?

The Ethernet shield is a recent vintage 'official' one, so pins 11, 12, and 13. (This is using a Duemilanove).

If I comment out the NewSoftSerial parts for communicating with the modem and leave the boards stacked, the Ethernet stil can't communicate.

Thanks for the tip on losing the goto, I hoped there would be a smarter way to do that.

The board file for the ethernet shield clearly shows connections to digital pins 2, 4, 10, and 13, and to analog pins 0 and 1. Since pin 2 is used by your other shield, when not using hardware serial, this seems to indicate that you can't use the two shields together.

Ok, missed that.

Though using the hardware serial on the GSM module would bypass this problem, yes?

If so, I suppose the question would be how to monitor while debugging (empty shield as passthrough?)

[edit]Or, would it be possible to jump the GSM board pin 2 to somewhere else and change the NewSoftSerial to read that?[/edit]

You could switch to the hardware serial port to talk to the GSM. Then, add a serial LCD, talking to it using NewSoftSerial on another pair of pins.

The serial LCDs are not cheap, but they are less expensive than either of the shields you have now.

Found a solution that did not require more equipment :wink:

I bent up pin2 on the cell shield and made a jumper to pin 4.

Changed the NewSoftSerial code to this :
NewSoftSerial cell(4,3); and I placed the cell shield on an extra set of make/female headers so it rests on top of the ethernet shield (which is typically too tall for other shields to sit on top).

The while loop doesn’t seem to work with my setup, so for the time being, I’m reverting back to the goto.

Thanks for your help.