Power Up Ethernet Shield W5200 OK until Power Down Up

Sketch works OK until disconnect/reconnect USB (power) to Arduino UNO.

SETUP: Windows 7, Arduino Uno, W5200 Ethernet Shield, Relay Shield

What do I have to do to make this sketch work stand alone without having to reload sketch after each power up?

include

include

byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 }; IPAddress ip(192,168,200, 2); IPAddress gateway(192,168,200, 1); IPAddress subnet(255, 255, 255, 0); // telnet defaults to port 23 EthernetServer server(23);

define W5200_CS 10

define SDCARD_CS 4

// int Relay1 = 4; Relay1 (pin 4) conflicts with W5200 Ethernet Shield) int Relay2 = 5; int Relay3 = 6; int Relay4 = 7; String commandString;

void setup() { delay(2000); pinMode(Relay2, OUTPUT); pinMode(Relay3, OUTPUT); pinMode(Relay4, OUTPUT); pinMode(SDCARD_CS,OUTPUT); digitalWrite(SDCARD_CS,HIGH);//Deselect the SD card Ethernet.begin(mac, ip, gateway, subnet); server.begin(); }

void loop() { // wait for a new client: EthernetClient client = server.available(); while (client.available()){ char newChar = client.read(); if (newChar == 0x0D) { processCommand(commandString); // gotAMessage = false; client.stop(); } else { commandString += newChar; } } } void processCommand(String command) { if (command.indexOf("RelayOn") > -1){ digitalWrite(Relay2,HIGH); digitalWrite(Relay3,HIGH); digitalWrite(Relay4,HIGH); commandString = ""; return; } if (command.indexOf("RelayOff") > -1){ digitalWrite(Relay2,LOW); digitalWrite(Relay3,LOW); digitalWrite(Relay4,LOW); commandString = ""; return; } commandString = ""; }

Which w5200 shield are you using? The DFRobot shield has a couple strange setup requirements.

Does it start to work if you press the reset button on the shield/Arduino?

This is incorrect, but may not be the cause of your problem.

// change this
  Ethernet.begin(mac, ip, gateway, subnet);

// to this
  Ethernet.begin(mac, ip, gateway, gateway, subnet);

// or this
  Ethernet.begin(mac, ip);

Thank you for your reply.

I am using W5200 Ethernet Shield v2.2 02/20/2014 06A14 by Seeed Studio purchased at Radio Shack

YES, If I press the reset button on the Ethernet Shield it will start working.

What do I need to do to eliminate the pressing of the "reset" button on power up?

==============================================

Why do you say "This is incorrect, but may not be the cause of your problem."

Is the documentation in error?

void setup() { // initialize the ethernet device Ethernet.begin(mac, ip, gateway, subnet);

// start listening for clients server.begin(); }

My code: Ethernet.begin(mac, ip, gateway, subnet);

You suggest: Ethernet.begin(mac, ip, gateway, gateway, subnet);

I don't know what to tell you about the boot problem. I have Due that suffers from the same malady.

The begin function has several prototypes. If you pass only 4 parameters, the last parameter is the gateway. You are using the subnet mask 255.255.255.0 as the gateway.

  void begin(uint8_t *mac_address, IPAddress local_ip);
  void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server);
  void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server, IPAddress gateway);
  void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet);