Problem with Ethernet Library and Output Pins

I have an Arduino MEGA 2560 and the mega compatible Ethernet shield. The shield works fine, my problem is when I define output puts on the arduino using pinMode. I’ve found that starting the Ethernet Library with Ethernet.begin wreaks havoc with my output pins. For instance, the following code works just fine:

// Define control pins
#define outPin1 53
#define outPin2 52

void setup() {  
  pinMode(outPin1, OUTPUT);
  digitalWrite(outPin1, LOW);
  pinMode(outPin2, OUTPUT);
  digitalWrite(outPin2, LOW);
}

outPin1 & outPin2 are defined, set to LOW and I can control them in the loop function. However, the following code does not work as expected:

// Library Includes
#include <SPI.h>
#include <Ethernet.h>

// Define control pins
#define outPin1 53
#define outPin2 52

// Ethernet mac and ip
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192,168,1, 177 };

void setup() {  
  Ethernet.begin(mac, ip);
  server.begin();
  pinMode(outPin1, OUTPUT);
  digitalWrite(outPin1, LOW);
  pinMode(outPin2, OUTPUT);
  digitalWrite(outPin2, LOW);
}

outPin1 is successfully defined, set to LOW and is usable in the loop function, however, outPin2 is not. Furthermore, I have outPin2 connected to a relay and I can hear the relay humming as the contactor switches rapidly between states. Not good!

Has anyone seen this issue before? I’m not sure if the problem lies in the Ethernet library, or if perhaps its in the SPI Library but it is definitely caused by the call to Ethernet.begin. I can comment out Ethernet.begin and server.begin and the second code fragment works just fine.

Thoughts?

From: http://arduino.cc/en/Main/ArduinoEthernetShield

Arduino communicates with both the W5100 and SD card using the SPI bus (through the ICSP header). This is on digital pins 11, 12, and 13 on the Duemilanove and pins 50, 51, and 52 on the Mega. On both boards, pin 10 is used to select the W5100 and pin 4 for the SD card. These pins cannot be used for general i/o. On the Mega, the hardware SS pin, 53, is not used to select either the W5100 or the SD card, but it must be kept as an output or the SPI interface won’t work.

Ha, I should have caught that. Thanks for the quick reply!