Error using ENC 28J60 Ethernet module

Am trying to learn to use Arduino with the Ethernet but cannot get started with the hardware.

i am getting this error but i don’t know what that means - is this a hardware error ?

Error inside Serial.serialEvent()	
java.io.IOException: Bad file descriptor in nativeavailable	
	at gnu.io.RXTXPort.nativeavailable(Native Method)
	at gnu.io.RXTXPort$SerialInputStream.available(RXTXPort.java:1532)
	at processing.app.Serial.serialEvent(Serial.java:258)
	at gnu.io.RXTXPort.sendEvent(RXTXPort.java:732)
	at gnu.io.RXTXPort.eventLoop(Native Method)
	at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1575)

it’s also not detected in the router so i don’t know the IP address - am simply using an IP address i know is not being used.
how would i get the MAC address - i’m not sure if that’s set in the hardware or it can be set in the code.

here’s the code if you’re interested;

  // ##############################
 // copy direct from backSoon-ino #
// ################################

// Present a "Will be back soon web page", as stand-in webserver.
// 2011-01-30 <jc@wippler.nl> http://opensource.org/licenses/mit-license.php
 
#include <EtherCard.h>

#define STATIC 0  // set to 1 to disable DHCP (adjust myip/gwip values below)

#if STATIC
// ethernet interface ip address
static byte myip[] = { 192,168,XX,XX };  
                    // NOT showing in DCHP Active IP table ?
                     // just pick one NOT currently in use
// gateway ip address
static byte gwip[] = { 192,168,XX,X };
#endif

// ethernet mac address - must be unique on your network
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
                      // DOESN'T SHOW - HOW TO KNOW ?!
                      
byte Ethernet::buffer[500]; // tcp/ip send and receive buffer

char page[] PROGMEM =
"HTTP/1.0 503 Service Unavailable\r\n"
"Content-Type: text/html\r\n"
"Retry-After: 600\r\n"
"\r\n"
"<html>"
  "<head><title>"
    "Service Temporarily Unavailable"
  "</title></head>"
  "<body>"
    "<h3>This service is currently unavailable</h3>"
    "<p><em>"
      "The main server is currently off-line.
"
      "Please try again later."
    "</em></p>"
  "</body>"
"</html>"
;

void setup(){
  Serial.begin(9600);
  Serial.println("\n[backSoon]");
  
  if (ether.begin(sizeof Ethernet::buffer, mymac) == 0) 
    Serial.println( "Failed to access Ethernet controller");
#if STATIC
  ether.staticSetup(myip, gwip);
#else
  if (!ether.dhcpSetup())
    Serial.println("DHCP failed");
#endif

  ether.printIp("IP:  ", ether.myip);
  ether.printIp("GW:  ", ether.gwip);  
  ether.printIp("DNS: ", ether.dnsip);  
}

void loop(){
  // wait for an incoming TCP packet, but ignore its contents
  if (ether.packetLoop(ether.packetReceive())) {
    memcpy_P(ether.tcpOffset(), page, sizeof page);
    ether.httpServerReply(sizeof page - 1);
  }
  Serial.println("WAITING!...");  // added this myself in the debugging
}

what does happen is "[backSoon]’ is displayed, but then nothing.

just tried another code - much simpler; no error but nothing happens either;

#include <EtherCard.h>
static byte mymac[] = {0xDD,0xDD,0xDD,0x00,0x00,0x01};
static byte myip[] = {192,168,XX,XX};
byte Ethernet::buffer[700];
 
void setup () {
 
  Serial.begin(9600);
  Serial.println("PING Demo");
 
  if (ether.begin(sizeof Ethernet::buffer, mymac, 10) == 0) 
    Serial.println( "Failed to access Ethernet controller");
 
  if (!ether.staticSetup(myip))
    Serial.println("Failed to set IP address");
}
 
void loop() {
 
  ether.packetLoop(ether.packetReceive());  
  Serial.println("PING?");  // added this myself just to see if it's passing through here
}

Can you upload a sketch to the Arduino board ? Please remove the Ethernet and try to upload a sketch, like the led blink example sketch. If that doesn't work, disconnect the Arduino and restart your computer. If that doesn't solve the problem, remove Java from your computer, and reinstall Arduino. Use the newest Arduino version 1.0.5. Or try the newest beta 1.5.6-r2, they have a different Java RxTx.

Hello Caltoa,
uploading other sketches is not a problem.
i am already using IDE 1.0.5

does that error mean there’s a problem with Java ?
my system resources are running a bit low, could that be related ?

i’m still thinking it’s a hardware issue with the 28J60 board itself - the router doesn’t even recognise it when connected via LAN - which i believe it should do.

EDIT:
ARGH - it was a case of SWAPPED wiring !!
i can now Ping the Arduino and also serve up the web page in the example;
BUT - the router still doesn’t list the Arduino as a client - so the IP address is still not ‘stable’ ?

Basically with these ethernet shields you can use any MAC address as long as no other devices use the same as you will get a conflict with the router.
The IP address should be one that fits within your network. Most people hjave either 192.168.1.xxx of 192.168.0.xxx or 10.0.0.xxx
where xxx must be one in the range of your router.
If you do not know what the IP range at you home is you can (if using windows) start a dos box : START->RUN-CMD
type ipconfig /all
this will show the ip address of your pc and the gateway.

in my case I use the following:

//
// ethernet settings
//
static byte mac[] 	= { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };	// just a random mac address
static byte ip[] 	= { 192, 168, 0, 200};						// static IP Address
//

hello nico, thanks for your comments. i know the IP range because i'm setting them up myself on the router.

i have now tried to set up a fixed pairing in a "DHCP Static IP Table" feature on the router. i had to find out what a Unicast MAC address is because the router wouldn't accept any MAC address.

so now i have it fixed, and i will keep this pairing for now while i slowly explore Ethernet locally.

what still "bothers" me is why the router doesn't detect the Arduino/ENC 28J60 in it's Client Table. i've just started learning - but i'm wondering if there's something like a passive or active connection - maybe the simple Arduino sketch isn't enough for the router to detect activity ?? (was just wondering because i noticed my Android phone isn't detected when it goes into sleep mode or screenlock or power-saving mode...whatnot !)