Go Down

Topic: problem with Arduino Mega + ENC28J60 in 1.0.5 IDE (Read 615 times) previous topic - next topic

MikeLuo

:smiley-sweat:
I am using ENC28J60 module with Arduino Mega R3. I use EtherCard as the library to test the problem. I run backSoon example and trying to access the IP which is 192.168.1.200. , but it doesn't work. I don't know what's going on. I am using Mac, I try so many different ways to fix it, but it just won't work. Is there anyone who can help me with this issue.
P.S. the compiling process is good.

Erdin

Is that the IP number via DHCP, and written to the serial monitor ?
What is the output of the serial monitor, any error messages ?
Do you want to run a webpage ?


MikeLuo

Code: [Select]

// 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,1,200 };
// gateway ip address
static byte gwip[] = { 192,168,1,1 };
#endif

// ethernet mac address - must be unique on your network
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };

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.<br />"
      "Please try again later."
    "</em></p>"
  "</body>"
"</html>"
;

void setup(){
  Serial.begin(57600);
  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);
  }
}

Thanks for paying attention to my problem.
The Code above is the example given by the EtherCard library. I use backSoon as the example. After I uploaded the sketch, I was trying to connect Arduino to my Mac through RJ45 cable. I type in 192.168.1.200 as address on browser. The web page never show up any message. After a while, the browser displayed "safari can't open the page."
I am not sure if have problem to connect pins to Arduino Mega or connect the RJ45 cable to Mac from ENC28J60 module, or connect the setup of network.
the Pins connection as follow:
53->CS
52->SCK
51->SI
50->SO
2->Int
5v->vcc
GND->GND
RESET->RESET

Go Up