Go Down

Topic: Can't get ethernet shield to work :( (Read 377 times) previous topic - next topic

PM5K

Frustrated. Ran the code from this website:

Quote
#include <SPI.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[] = { 10, 0, 0, 177 };   

void setup()
{
  Ethernet.begin(mac, ip);
}

void loop () {}


I can see the shield is getting an ip address, but when I try to connect to it using iDK and Arduino  CTRL on my iPhone I can't connect to it. I'm connecting locally via WIFI and using port 80.

Any suggestions?

oric_dan

Well, I honestly have no idea what you're trying to do here. However, forgetting about "wifi" and an "iphone", if you can connect your ethernet shield to a local router via CAT5 cable, you can try my sketch here. I just wrote it today, and don't know much as yet, but it works great and tells me all about my local network. If what you really have is a Wifi shield, then never mind.

Code: [Select]
/****************************************************
file:  LocalIP_test1
date:  07/17/13 (orig 07/17/13).
author: oric_dan.

status: works good.
------------------------------------------------------

This program gets IP information from the local router
the Arduino Ethernet shield is connected to using DHCP.

Note - once the IP info is obtained, it should be possible
  to connect a PC to the router via wifi, and use Windows
  "Start > Run > cmd" to ping the dnsserver, router, and
  Ethernet shield using, for instance, "ping 192.168.1.100",
  to find the hardware on the local network.
///////////////////////////////////////////////////////////

Setup
-----
1. PC/notebook USB port should be able to provide enough
   current to power UNO or Mega2560 board and the Ethernet
   shield.
2. on UNO or Mega2560 board, just plug in Ethernet shield.
3. connect Ethernet shield to router via CAT5 cable.
   
Comments
--------
1. Enter MAC address for the Ethernet shield below if known.
    Ethernet shields may have a MAC address printed on the shield,
    but anything will do, as long as it's unique for the local
    network.
2. on power up, PWR,Link,100M,FULLD leds should light on the
   Ethernet shield.
3. if connection goes correctly, then Rx,Tx,Link leds on the
   Ethernet shield will blink during data download from router.
4. local shields will commonly be assigned an IP address such as
   "192.168.1.100".
////////////////////////////////////////////////////////////////

File References
---------------
1. for our machine, ".." refers to Arduino IDE directory
   c:\winapps\ArduinoIDE\arduino-1.0.5-windows
2. IPAddress.h located in ..\hardware\arduino\cores\arduino
3. Ethernet.h located in ..\libraries\Ethernet

Based on a program found in the Arduino Cookbook.
**************************************************************/

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

// **** Program name ****
char *progname = "\nIP-Interrogate ...";

// ethernet params - uses default MAC address, should
//   be changed to unique for specific ethernet shield.
byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };


/*******************************************/
void setup()
{
  Serial.begin(57600);  // 230400);
//  while (!Serial) {
//    ; // wait for serial port to connect. Needed for Leonardo only
//  }
  Serial.println( progname );
  Serial.println(">configuring Ethernet using DHCP");
  Serial.println("");
  delay(1000);
 
  display_mac();
  setup_Ethernet();
  display_IPinfo();
 
  endless_loop();
}

/*******************************************/
void loop()
{
}

/*******************************************/
void setup_Ethernet()
{
  int ret=0;
 
  // start the Ethernet connection:
  if( (ret=Ethernet.begin(mac)) == 0) {
    Serial.println(">>Failed to configure Ethernet using DHCP ");
    // no point in carrying on, so do nothing forevermore:
    Serial.println(ret);
    endless_loop();
  }
  // give the Ethernet shield a second to initialize:
//  delay(1000);
}

/*********************************************/
void display_IPinfo()
{
  IPAddress ipa, submask, gateip, srvrip;

  Serial.println("DNS Server");
  srvrip = Ethernet.dnsServerIP();
  Serial.print("- dnsServerIP = ");
  Serial.println(srvrip);
   
  Serial.println("Router:");
  gateip = Ethernet.gatewayIP();
  Serial.print("- gatewayIP   = ");
  Serial.println(gateip);
 
  Serial.println("Ethernet shield:"); 
  ipa = Ethernet.localIP();
  Serial.print("- IP Address  = ");
  Serial.println(ipa);
 
  submask = Ethernet.subnetMask();
  Serial.print("- subnetMask  = ");
  Serial.println(submask);
}

/*******************************************/
void display_mac()
{
  int i;
 
  Serial.print("Ethernet shield MAC = "); 
  for( i=0; i<5; i++) {
    Serial.print( mac[i], HEX );
    Serial.print(", ");
  }
  Serial.print( mac[i], HEX );
  Serial.println(""); 
}

/***************************************************/
void endless_loop()
{
  Serial.println("\n>going into endless loop now - goodbye");
  while(1);
}

PM5K

Yeah disregard all of this, I  have no idea what I am doing but I was totally doing it wrong anyhow.

zoomkat

You need to specify just what type of Ethernet shield you are using. There are several different types.
Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   8)

shahan312


I can see the shield is getting an ip address, but when I try to connect to it using iDK and Arduino  CTRL on my iPhone I can't connect to it. I'm connecting locally via WIFI and using port 80.

Any suggestions?


Since you're not setting the gateway and network mask, you could get some networking problems. If you're router has DHCP enabled (most routers do), you could try making the Ethernet shield get an ip, by not specifying the IP:

Code: [Select]

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

/*
Adapted from:
http://arduino.cc/en/Reference/EthernetLocalIP
*/

byte mac[] = { 0x90, 0xA2, 0xDA, 0x0E, 0x99, 0x4A };

void setup() {
 
  Serial.begin(9600);
 
  if(Ethernet.begin(mac) == 0) {
     Serial.println("Could not configure Ethernet using DHCP");
  } else {
     Serial.println(Ethernet.localIP());
  }
}


void loop() {
 
}

Go Up