Serial connection doesn't work when using EthernetClient

Really odd problem.

Arduino 1.0, Mega 2560, Wiznet 5100 Ethernet board.

If I use the WebServer example and connect to the address in my browser I get results back, sometimes it works, sometimes not and sometimes there's lots of junk.

For example:

analog input 0 is 1023
ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddffffffff

and that continues. Other times it's other random characters. I can also ping the IP address.

However if I try any example that uses the EthernetClient client like the WebClient I can't ever get anything to show up in the Serial Monitor. Could something on the Ethernet board be conflicting with it?

If you look at the WebClient example code it should at least write either "Failed to configure Ethernet using DHCP" or "Connecting...". I don't see any way one of those wouldn't write to the Serial Monitor. Same result with DHCPAddressPrinter. Nada in the Serial Monitor.

I have a Mega and the ethernet shield, and they work well now. It took some debugging to get it that way tho.

A couple things can cause problems like that. The first is the microSD card reader SPI interface. Insure you disable that if you are not using it.

In setup()

pinMode(4,OUTPUT);
digitalWrite(4,HIGH);
// then do your Ethernet.begin() call

Also, there is the "605 bug". http://code.google.com/p/arduino/issues/detail?id=605

I do need to use the SD reader in my sketch.

I tried your code and it did fix the problem. Thank you. What are the tricks to using the SD and Ethernet together in the same sketch? I'm going to need to read a file from SD and send the results over the Ethernet.

Then use something like this:

void setup()
{
   SD.begin(4);
   Ethernet.begin(mac,ip);
   digitalWrite(10,HIGH);
   delay(2000);
   // rest of your setup stuff
}

Now you should be able to read and write to both devices without manipulating the Slave Select pins. That is accomplished in the libraries of both devices.

The SD.begin() routine returns with its SPI disabled, so nothing is requires there.
The Ethernet.begin() routine returns with its SPI enabled, so you need to disable it.