Arduino Ethernet, examples not working

I bought an Arduino Ethernet board [1] and I'm trying to run at least one example on it.

What I did so far:

  • downloaded the latest Arduino software
  • tools->board->arduino ethernet
  • file->examples->webserver
  • connect the arduino board to the laptop with an utp cable (mii-tool shows link)
  • setup ip with netmask 255.255.255.0 on laptop
  • upload the example on the arduino board
  • open firefox on the laptop try http://192.168.1.177

Nothing happens. Same with other examples.

Is there something I'm missing?

[1] http://arduino.cc/en/Main/ArduinoBoardEthernet

I think you might need a router. Do you have internet-sharing turned on on your laptop?

Just for the sake of argument I stuck the cable in a router that had dhcp enabled. I tried running the DhcpAddressPrinter but the only thing I get from the serial monitor is "Failed to configure Ethernet using DHCP".

While running mii-tool a couple of times I get either

eth0: negotiated 100baseTx-FD, link ok

or

eth0: no link

You did not mention it, but just out of curiosity, do you have a microSD card in the slot?

No sdcard, I'm also powering the board through FTDI.

Right now I'm running this code on the board

#include <SPI.h>         // needed for Arduino versions later than 0018
#include <Ethernet.h>
#include <EthernetUdp.h>         // UDP library from:
bjoern@cs.stanford.edu 12/30/2008


// Ent  er a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 0, 177);

unsigned int localPort = 8888;      // local port to listen on

// buffers for receiving and sending data
char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet,
char  ReplyBuffer[] = "acknowledged";       // a string to send back

// An EthernetUDP instance to let us send and receive packets over UDP
EthernetUDP Udp;

void setup() {
  // start the Ethernet and UDP:
  Ethernet.begin(mac,ip);
  Udp.begin(localPort);
  Serial.begin(9600);
}

void loop() {
  // if there's data available, read a packet
  int packetSize = Udp.parsePacket();
  Serial.print("Local IP ");
  Serial.println(Ethernet.localIP());
  if(Udp.available())
  {
    Serial.print("Received packet of size ");
    Serial.println(packetSize);
    Serial.print("From ");
    IPAddress remote = Udp.remoteIP();
    for (int i =0; i < 4; i++)
    {
      Serial.print(remote[i], DEC);
      if (i < 3)
      {
        Serial.print(".");
      }
    }
    Serial.print(", port ");
    Serial.println(Udp.remotePort());

    // read the packet into packetBufffer
    Udp.read(packetBuffer,UDP_TX_PACKET_MAX_SIZE);
    Serial.println("Contents:");
    Serial.println(packetBuffer);

    // send a reply, to the IP address and port that sent us the
packet we received
    Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
    Udp.write(ReplyBuffer);
    Udp.endPacket();
  }
  delay(10);
}

And the Rx led is constantly blinking.

I tried using this python code to send an UDP package to the board but still UDP.available() does not return true.

import socket

UDP_IP="192.168.0.177"
UDP_PORT=8888

MESSAGE="TEST"

sock = socket.socket( socket.AF_INET, socket.SOCK_DGRAM)

sock.sendto(MESSAGE, (UDP_IP, UDP_PORT))

And it didn't work.

I fired up wireshark and saw that the board was not responding to ARP requests so I added a static entry in the ARP table

arp -s 192.168.0.177 DE:AD:BE:EF:FE:ED

then ran the pyhton script again and saw that the board received the message on the serial monitor.

But it doesn't send anything back.

Also the biggest issue right now seems to be that it can't establish a link, mii-tool shows no link or link successfully negotiated every time I run it.

I uploaded the code again and neither Rx or Tx are blinking and link negotiation fails.

Any pointers?

Have you tried the DhcpAddressPrinter sketch in the ethernet examples? Does it display an ip address?

Did not work at all with the Dhcp examples. So now it's connected to my laptop.

I would get Dhcp timeout.

sqrtpi:
Did not work at all with the Dhcp examples. So now it's connected to my laptop.

I would get Dhcp timeout.

If you also connect the laptop to the router with that port, of course it will timeout. There will not be a dhcp server on the laptop.

I recommend connecting the arduino ethernet to the router, and try the DhcpAddressPrinter sketch again.

edit: And you are using a CAT5 crossover cable when connecting to the laptop? Otherwise, even with dhcp, it will probably not work. The ethernet port on the laptop would need a auto-crossover feature, and that is normally available only on routers.

SurferTim:
If you also connect the laptop to the router with that port, of course it will timeout. There will not be a dhcp server on the laptop.

I recommend connecting the arduino ethernet to the router, and try the DhcpAddressPrinter sketch again.

edit: And you are using a CAT5 crossover cable when connecting to the laptop? Otherwise, even with dhcp, it will probably not work. The ethernet port on the laptop would need a auto-crossover feature, and that is normally available only on routers.

Yes I tested dhcp when connected to the router.

"Failed to configure Ethernet using DHCP".

The only success I had was connecting the board to the laptop with static IP addresses and static ARP table on the laptop.

The ethernet port on the laptop would need a auto-crossover feature, and that is normally available only on routers.

I thought most modern laptops had auto-crossover ports. My MacBook Pro does, and I'm sure my mother's HP laptop does too.

dxw00d:

The ethernet port on the laptop would need a auto-crossover feature, and that is normally available only on routers.

I thought most modern laptops had auto-crossover ports. My MacBook Pro does, and I'm sure my mother's HP laptop does too.

Yes it does, most laptops do nowadays.

The issue, I think, remains autonegotiation. The LEDs stop blinking on the router and the board never blink once connected to the router.

The only success I had was connecting the board to the laptop with static IP addresses and static ARP table on the laptop.

OK, I will presume it does have auto-crossover.
What network settings are in the laptop? Is it dhcp or static? How does it normally connect to the router? Wireless or wired?

SurferTim:

The only success I had was connecting the board to the laptop with static IP addresses and static ARP table on the laptop.

OK, I will presume it does have auto-crossover.
What network settings are in the laptop? Is it dhcp or static? How does it normally connect to the router? Wireless or wired?

The laptop has nothing to do in this, but for the sake of argument let's say wired.

There's probably some misunderstanding here so let me try to clear this up once more. I have tested the board in two setups.

Setup1: Arduino Ethernet Board direct cable to laptop, NO router involved

Arduino and Laptop configured with static IP.
If you look into wireshark you see that the Laptop sends an ARP query in the form "Who has 192.168.0.177? Tell 192.168.0.2"

192.168.0.177 Arduino
192.168.0.2 Laptop

To fix this I add a static entry in the arp table on the laptop such as

arp -s 192.168.0.177 DE:AD:BE:EF:FE:ED

Now I send an UPD packet to the Arduino board, it receives the packet, prints the content on serial. Awesome stuff.

Now when it tries to send an UDP packet back nothing comes back to the laptop. I'm assuming the same thing, no arp entry for the laptop on the Arduino board.

Setup2: Arduino Ethernet Board and Laptop connected to the router (running openwrt) on LAN ports

The Arduino board timesout when I try to get an ip through DHCP. Laptop gets IP.

I set a static IP on the Arduino board. Now I'm back in the same place with the ARP issue.

Set static entry for the Arduino board on Laptop and the Arduino receives the UDP packet. Still no response from Arduino.

I used this connected to my laptop directly, and I can ping it. I set my laptop ethernet port to
ip = 192.168.0.2
subnet = 255.255.255.0
gateway = 192.168.0.1

Then I uploaded this code to the Arduino. The pinMode and digitalWrite calls are because I have a microSD card in the slot.

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

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

IPAddress ip(192,168,0,3);

void setup() {
  pinMode(4,OUTPUT);
  digitalWrite(4,HIGH);
  
  Ethernet.begin(mac,ip);
}

void loop() {
  
}

Can you ping 192.168.0.3 from the laptop? I can.