Go Down

Topic: Arduino Mega 2560 + ethernet+GSM shield: corrupted serial data (Read 4677 times) previous topic - next topic

patpin

Hello friends,
I installed as above and run a simple program on the MEGA (which runs well on the UNO)
Code: [Select]
/*
  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("<br />");       
          }
          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

patpin

Hello friends,
I installed as above and run a simple program on the MEGA (which runs well on the UNO)
Code: [Select]
/*
  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("<br />");       
          }
          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?

patpin

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

patpin

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

SurferTim

Post a link to the GSM shield.

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



liuzengqiang

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.

Wveenstra

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.


 

PaulS

Quote
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.

liuzengqiang

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.

patpin

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...

Go Up