I have a new ethernet shield for my Arduino Duemilanove [Atmega 328 version] and it does not appear to work when plugged in to my router.
I have been trying to get the sample Ethernet sketches to run, all of which work perfectly when I plug the ethernet shield directly into a computer. However when I plug it into my router, the link doesn't appear to stay active. The 100M light flashes on and off periodically with the port connection light on the router. Some times it stays on for a few minutes, and the rx light remains on for this entire time. But normally it flashes every few seconds and wont maintain the link.
Below is the code I am running, which runs perfectly when connected directly to a computer.
Is there something weird going on in how my router identifies devices?
Any help would be greatly appreciated, as I will be needing internet access which will of course require me to connect it to the router.
Cheers,
Ed
***EDIT*** Will also add that the router is a netgear DG834G v4. And the mac address in the code there I have taken from the sticker which was on the bottom of my ethernet shield
Code: Select all
/*
Chat Server
A simple server that distributes any incoming messages to all
connected clients. To use telnet to your device's IP address and type.
You can see the client's input in the serial monitor as well.
Using an Arduino Wiznet Ethernet shield.
Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13
* Analog inputs attached to pins A0 through A5 (optional)
created 18 Dec 2009
by David A. Mellis
modified 10 August 2010
by Tom Igoe
*/
#include <SPI.h>
#include <Ethernet.h>
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network.
// gateway and subnet are optional:
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x88, 0x06 };
byte ip[] = { 192,168,1, 17 };
byte gateway[] = { 192,168,1, 1 };
byte subnet[] = { 255, 255, 255, 0 };
// telnet defaults to port 23
Server server(23);
boolean gotAMessage = false; // whether or not you got a message from the client yet
void setup() {
// initialize the ethernet device
Ethernet.begin(mac, ip, gateway, subnet);
// start listening for clients
server.begin();
// open the serial port
Serial.begin(9600);
Serial.print("Arduino Chat Server \n\nInitialised...\n\n");
}
void loop() {
// wait for a new client:
Client client = server.available();
// when the client sends the first byte, say hello:
if (client) {
if (!gotAMessage) {
Serial.println("We have a new client");
client.println("Hello, client!");
gotAMessage = true;
}
// read the bytes incoming from the client:
char thisChar = client.read();
// echo the bytes back to the client:
server.write(thisChar);
// echo the bytes to the server as well:
Serial.print(thisChar);
}
}