Ethernet Shield IP Issues

Hello, I just got my Ethernet shield yesterday and I’ve been trying since to get it to work. I’m using my laptop’s ethernet port(I have the ethernet port set up as an internet sharing device as I’m using a mac), but every time I upload the code the IP address changes, I’ve tried doing it manually and using DHCP. It just won’t work and I can’t figure out why.

/*
Simple web client
Arduino 1.0 version
*/

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = {0x90, 0xA2, 0xDA, 0x0D, 0x11, 0xF2}; //Ethernet Shield's MAC address
byte ip[] = {169,254,51,100}; // My IP Address
byte server[] = {74,125,227,83}; //Google server address 
//byte subnet[] = {255,255,0,0}; //Ethernet shield's subnet


EthernetClient client; 

void setup()
{
  Serial.begin(9600); //start the serial library 
  Ethernet.begin(mac, ip);
  delay(1000); //give the ethernet hardware a second to initialize 
  
  Serial.println("Connecting...");
  
  if(client.connect(server, 80)) 
    {
      Serial.println("Connected");
      client.println("GET /search?q=arduino_HTTP/1.0"); //The HTTP request
      client.println();
    }
  else
    {
      Serial.println("Connection failed");   
    }
}

void loop()
{
  if(client.available())
    {
     char c = client.read();
     Serial.print(c); //echo all data received to the serial monitor  
    }
    
  if(!client.connected())
    {
      Serial.println();
      Serial.println("Disconnecting...");
      client.stop();
      for(;;)
      ; 
    }
}/code]

ebird97:
Hello, I just got my Ethernet shield yesterday and I’ve been trying since to get it to work. I’m using my laptop’s ethernet port(I have the ethernet port set up as an internet sharing device as I’m using a mac), but every time I upload the code the IP address changes, I’ve tried doing it manually and using DHCP. It just won’t work and I can’t figure out why.

/*

Simple web client
Arduino 1.0 version
*/

#include <SPI.h>
#include <Ethernet.h>

byte mac = {0x90, 0xA2, 0xDA, 0x0D, 0x11, 0xF2}; //Ethernet Shield’s MAC address
byte ip = {169,254,51,100}; // My IP Address
byte server = {74,125,227,83}; //Google server address
//byte subnet = {255,255,0,0}; //Ethernet shield’s subnet

EthernetClient client;

void setup()
{
  Serial.begin(9600); //start the serial library
  Ethernet.begin(mac, ip);
  delay(1000); //give the ethernet hardware a second to initialize
 
  Serial.println(“Connecting…”);
 
  if(client.connect(server, 80))
    {
      Serial.println(“Connected”);
      client.println(“GET /search?q=arduino_HTTP/1.0”); //The HTTP request
      client.println();
    }
  else
    {
      Serial.println(“Connection failed”);   
    }
}

void loop()
{
  if(client.available())
    {
     char c = client.read();
     Serial.print(c); //echo all data received to the serial monitor 
    }
   
  if(!client.connected())
    {
      Serial.println();
      Serial.println(“Disconnecting…”);
      client.stop();
      for(;:wink:
      ;
    }
}/code]

From you code I see two issues your not setting a default gateway and that static IP looks like it’s part of the MS autoconfig useless range. If your getting a different IP via DHCP each time change your DHCP server to fix that as there is nothing wrong with that happening just define a static reservation of the mac address if you want it to stay constant.