Arduino Mega 2560 + ethernet+GSM shield: corrupted serial data

Hello friends,
I installed as above and run a simple program on the MEGA (which runs well on the UNO)

/*
  Web Server
 
 A simple web server that shows the value of the analog input pins.
 using an Arduino Wiznet Ethernet shield. 
 
 Circuit:
 * Ethernet shield attached to pins 10, 11, 12, 13
 * Analog inputs attached to pins A0 through A5 (optional)
 
 created 18 Dec 2009
 by David A. Mellis
 modified 9 Apr 2012
 by Tom Igoe
 
 */

#include <SPI.h>
#include <Ethernet.h>

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 
 xxxxxxxxxxxxxxxxxxxxxxxxx }; // not mentioned on forum
IPAddress ip(192,168,178,22); // vr browser: http://192.168.178.22/
IPAddress gateway(192,168,178, 1);
IPAddress subnet(255, 255, 255, 0);

// Initialize the Ethernet server library
// with the IP address and port you want to use 
// (port 80 is default for HTTP):
EthernetServer server(80);

void setup() {
 // Open serial communications and wait for port to open:
  Serial.begin(9600);
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }


  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip,gateway,gateway,subnet);
  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());
}


void loop() {
  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
    Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");  // the connection will be closed after completion of the response
	  client.println("Refresh: 5");  // refresh the page automatically every 5 sec
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
          // output the value of each analog input pin
          for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
            int sensorReading = analogRead(analogChannel);
            client.print("analog input ");
            client.print(analogChannel);
            client.print(" is ");
            client.print(sensorReading);
            client.println("
");       
          }
          client.println("</html>");
          break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        } 
        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);
    // close the connection:
    client.stop();
    Serial.println("client disonnected");
  }
}

I get a serial comm window with partially corrupted text:
"server is at 192.168.178.22
new client
G " followed by a number of control characters and then "client disconnected"
I have bended the pin 2 of the GSM shield and connected pin 2 to 10;
Can anybody see my mistake(s)? Thanks

AND sometimes I have also a wrong reading of the localIP (in comm. window: "server at 192.0.178.0" instead of the one started with in the begin() instruction). ???what could that be?

Forgot to mention both shields are Rev 3. I use the IDE 1.0.5.

And if I remove the top shield (GSM R3) then all OK. How can they work together?

Post a link to the GSM shield.

edit: Post to the other thread in Networking.
I guess AWOL wants you to use this thread.

Hello,
I described the problem in
Arduino Mega 2560 + ethernet+GSM shield: corrupted serial data - Suggestions for the Arduino Project - Arduino Forum and got some answers in

RECAP:I want to use ethernet shield R3 and GSM shiled R3 on MEGA 2650 an get control characters in the serial comm window when I put GSM shield on top of the ethernet shield. When I remove the GSM shield the server part works fine.
Somebody answered in Change SS pin on Ethernet Shield - Networking, Protocols, and Devices - Arduino Forum page 3., that i am using the wrong ports with the MEGA but the ports I use in the sketch mentioned in the first link is Serial. I think this is on pin 0 and 1. Do I only have to change the Serial.begin.. to e.g. SoftwareSerial mySerial(10, 11); // RX, TX.
And what about the connection of pin 10 to pin 2 and bended the GSM shield pin 2 ??

ps. The ethernet board has a six pin connector SPI

I also get the wrong answer in the ser. comm. window: "server at 0.0.0.0" with the "server" program from Tom Igoe and david Mellis. The server IP is identified when there is no GSM shield on top of it!
I read that the MEGA also uses pin 10 for the W5100 selection and apparently I also need this pin for the GSM shield... Please help

Don't use D10. What is wrong with D11? Or D12? Those are GPIO on a Mega.

BTW, you aren't going to get much help with a subject line like that. You should edit it to something more meaningful.

How are you powering your arduino mega? I have mega 2560 r3 and Ethernet shield r3 with sd card. I powered it with 12V DC from and ac adapter. Just couldn't get it to work properly. Turned out 12 V is too much for the particular arduino's voltage regulator. The 5V output starts to crap out after the board heats up. Some regulators can take the heat but others are not.

Hello Patpin,

I have the same problems with a Mega 2560 and the GSM shield. It's really weird. I see also corrupted data at the serial output. On the Uno everything works fine.

I have used different RX pins like: 11, 12, 50, 51 etc. But no good result.
I have also used an external power regulated between 7 -12 Volt. But no good result.

Do you know why you can use the interrupts written at http://arduino.cc/en/Reference/SoftwareSerial

"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)"

and not the hardware interupts written at http://arduino.cc/en/Main/ArduinoBoardMega2560
"External Interrupts: 2 (interrupt 0), 3 (interrupt 1), 18 (interrupt 5), 19 (interrupt 4), 20 (interrupt 3), and 21 (interrupt 2)"

I'm not really understand why I can use the change interrupts. What is special about these I/O?

I have also used the newest IDE 1.0.6. Then my sketch even don't compile a good code for the processor. With the new IDE 1.0.6. I become a lot of errors.

Could it be timingproblems?

Please who can help us with the same problem.

Then my sketch even don't compile a good code for the processor. With the new IDE 1.0.6. I become a lot of errors.

Could it be timingproblems?

I can't imagine how using a different version of the IDE, and not being able to compile some mystery code, could be construed as timing problems.

I can't imagine, either, why, with 4 hardware serial ports, you need to use SoftwareSerial.

PaulS:
I can't imagine how using a different version of the IDE, and not being able to compile some mystery code, could be construed as timing problems.

I can't imagine, either, why, with 4 hardware serial ports, you need to use SoftwareSerial.

The only thing I can think of is support for inverted TTL logic on software serial that the hardware serial doesn't have. The poster didn't say that was needed though.

liudr:
How are you powering your arduino mega? I have mega 2560 r3 and Ethernet shield r3 with sd card. I powered it with 12V DC from and ac adapter. Just couldn't get it to work properly. Turned out 12 V is too much for the particular arduino's voltage regulator. The 5V output starts to crap out after the board heats up. Some regulators can take the heat but others are not.

I am powering with 12V 2,5 A...