Ethernet shield sends garbage

Hi,

I'm not sure wether it's a software or hardware problem so im trying here.
I got a arduino ethernet shield with the sd port for my arduino duemilanove. My problem is that every sample programm from the playground doesn't work correctly. I'm using the new arduino 021 ide.
I always get packages like this:
[ch65533][ch65533]'[ch65533][ch65533][ch1072][ch65533][ch65533][ch623][ch65533]Q[ch65533]![ch65533]4"[ch65533][ch65533][ch65533]E[ch65533][ch65533][ch65533]@[ch65533]O[ch65533][ch65533][ch65533]([ch65533][ch65533][ch65533][ch1758][ch65533][ch65533][ch65533][ch65533][ch65533]JXa[ch65533][ch65533][ch65533]&z[ch65533]3rJ[ch65533][ch65533][ch65533][ch65533][ch65533][ch65533]Z[ch65533][ch65533][ch65533][ch65533]U[ch65533][ch65533][ch65533][ch65533]G.[ch65533]<l8Xe[ch65533][ch65533][ch65533][ch869][ch65533][ch65533] [ch65533][ch65533]vnY("*[ch65533]'[ch65533][ch65533]?[ch65533] "[ch65533][ch65533]|[ch49676]8x[ch65533][ch65533][ch65533][ch65533][ch65533]Jj@,[ch65533][ch65533]T[ch65533]H[ch1562]p[ch65533]2[ch1514] %X[ch65533]72[ch65533][ch65533][ch65533][ch65533]b[ch65533]4d[ch65533][ch65533]0"r[ch65533][ch65533]'2[ch65533][ch992][ch754]h[ch65533]H[ch65533]q[ch65533]P[ch65533][ch65533]tV2/v[ch65533]=]p[ch65533]oW^[ch65533][ch65533][ch65533]+NE[ch65533][ch65533]\y[ch65533]G[ch65533][ch65533]0[ch65533]/[ch65533]f[ch65533]z[ch65533][ch65533]NKI[ch65533][ch65533]a[ch65533]vK[ch65533]MX[ch65533]E[ch65533][ch65533]H[ch65533]![ch65533]g[ch65533]4[ch65533][ch65533][ch65533]([ch65533]0[ch65533]:a[ch65533][ch65533][ch65533]f[/[ch65533][ch65533]ch65533[ch65533][ch65533][ch65533]Z[ch65533][ch65533]t[ch65533]Q"[ch1995]Z[ch65533][ch65533][ch65533][ch65533][ch65533]"[ch65533][ch65533][ch65533]^+[ch65533]g[ch65533]1[ch1744]hc[ch65533][ch65533]$[ch65533][ch1316]zn[ch65533][ch65533]MW[ch65533][%[ch65533][ch65533][ch65533]:[ch1445][ch65533]2F=[ch65533][ch65533][ch65533]%[ch65533][ch65533]j[ch65533]#C

This is also sent, if the arduino shouldn't send anything at all.
That's the piece of code I'm using currently.

// Simple Network Connect 
#include <SPI.h>
#include <Udp.h>
#include <Client.h>
#include <Server.h>
#include <Ethernet.h>

// the media access control (ethernet hardware) address for the shield:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };  
//the IP address for the shield:
byte ip[] = { 192, 168, 2, 177 };
// the IP adress of the gateway
byte gateway[] = { 192, 168, 2, 1 };
// subnetmask
byte subnet[] = { 255, 255, 255, 0 };

// Create simple loopback server on port 23
Server server = Server(23);

void setup() {
  // Set LED mode
  pinMode(led, OUTPUT);
  // configure network
  Ethernet.begin(mac, ip, gateway, subnet);
  Serial.begin(9600);
  // start server
  server.begin();
  delay(2000);
}

void loop() {
  // turn off led
  //digitalWrite(led, LOW);
  // if an incoming client connects, there will be bytes available to read:
  Client client = server.available();
  //if (client == true) {
  if (client.available()) {
    // read bytes from the incoming client and write them back
    // to any clients connected to the server:
    //server.write(client.read());
    Serial.write("connect\n");
    server.write("test1\n");
    // turn on led
    //digitalWrite(led, HIGH);
  } else {
    Serial.write("no connection\n");
  }
}

thx in advice for every hint.

greetz
alex

(assumption it is software)

Looking at differences between your code and the sample code at Ethernet - Arduino Reference I see that you use Client.Available() . However if I read the reference pages
Ethernet - Arduino Reference correctly, you first have to test if (client == true). you commented it out
Think the call to client.available() makes no sense when client equals to false. (meaning no client object?). Have to check the lib code to be sure. And client.read() does not makes sense either, but the server will write it.

  Client client = server.available();
  //if (client == true) {
  if (client.available()) {

try this loop

void loop()
{
  // if an incoming client connects, there will be bytes available to read:
  Client client = server.available();
  if (client == true) {
    // read bytes from the incoming client and write them back
    // to any clients connected to the server:
    server.write(client.read());
  }
}

hopes this helps

Hi,

thanks for you answer. I tried the original code first but it didn't worked
so thats why I changed it.

 if (client == true) {
    // read bytes from the incoming client and write them back
    // to any clients connected to the server:
    //server.write(client.read());
    Serial.write("connect\n");
    server.write("test1\n");
  } else {
    Serial.write("no connection\n");
  }

If I have the code like this, I always get a "connect" printed out, thous I don't have connected to the obove ip. And when I connect
via telnet, it prints "no connection".
Thats why I changed the statement and now it works.
But all I get is garbage, and not only this. I just plugged the arduino
in after it was off for like a 1 day, and i get old messages from yesterday out on the line. I'm not sure of this is possible. I thought the Cache on the ethernet-controller were just ram, so empty if there is now power anymore.
the state

Oh and by the way. If I use the client example, and trie to sent http request, it sents the same garbage.

Is it possible to check on alternative hardware, a 2nd system?

No unfortunately i have (yet) only one arduino.

regards
alex

Hi all,
I have exactly the same problem....

Thanks.
Paolo.

If I have the code like this, I always get a "connect" printed out, thous I don't have connected to the obove ip. And when I connect
via telnet, it prints "no connection".

Sounds like the logic is inverted ???

What could cause this?

think .... eh, no idea, ... think harder ......... nop.

Have you changed the ethernetcables? ("reversed it")
Used another port on your router to connect the Arduino to your local network?
Is there a device with same MAC address in your netwerk?
Is there a device with same IP address in your netwerk?
What power supply do you use?
USB or a separate powersupply?
How strong is the powersupply?
Do you have a magnifying glass?
==> Check the ethernetshield circuitry for soldering faults.
Does the Arduino run non-ethernet sketches as expected?
When using Serial.write(client.read()) for devbugging do you have initialized the serial port ?
Serial.begin(115200) for max speed?
Is your PC serial port at the same speed as Arduino?
.......
</questioning mode>

That are many questions I know, but maybe they help find a cause as I have no idea yet.

hi,

I chaged usb cable/pc port, ethernet cable/switch port, arduino ip address and mac address, and I disconnected everything but the pc and arduino from the network switch, but the behavious is always the same.

However, arduino works well with the basic examples of the development environment that does not use the ethernet shield (blink and fade).

Thanks.
Paolo

Then it looks like your ethernetshield is broken, sorry. Contact your supplier maybe he will replace it.

hi all,

now my arduino is working perfeclty with the ethernet shield, and the only thing that I changed is the linux distribution.

The problems were on a fedora 13 64 bit, while arduino works well on the same pc with an ubuntu 10.10 64 bit. :slight_smile:

Many thanks for your support,
Paolo.