Newby - Require help connecting ENC28J60 to internet

Hi there, I'm relatively new to Arduino but hoping for a little assistance.

I'm having an issue connecting a ENC28J60 ethernet module to the internet through an Arduino mego 2650.

I'm using the ethercard library which from what I've researched appears to be most commonly used. The ENC28J60 is connected directly to the router, and I'm confident pins are connected correctly to the Arduino board (triple checked).

I'm using the "back soon" sketch to determine if my connection is working, using my gateway IP address determined via CMD in windows. I've left the mac address as is in the sketch. Using the IP address in a web browser doesn't open anything up and no "back soon" message appears. All that appears in the serial monitor is a "back soon" text.

I've also tried the "test DHCP" sketch to see if I can get the router to assign an IP. All that I receive in this case is a "test DHCP" text in the serial monitor.

I have taken a look around the forums, but at this stage not a great deal is helping me. I'm guessing there could be an issue with the module? I do get some blinking lights on the RJ45 cable port on the module.

If anyone has had this problem or can point me in the right direction would be much appreciated!

I’m confident pins are connected correctly to the Arduino board (triple checked).

Provide a wiring diagram of how you connected it to the Arduino.

Post your code! The backSoon example allows configuration and the configuration you’ve chosen is relevant.

BTW, the backSoon example doesn’t show a “back soon” message but a 503 Service Temporarily Unavailable error page. You might be fooled into thinking that your browser generated that message.

I’ve also tried the “test DHCP” sketch to see if I can get the router to assign an IP. All that I receive in this case is a “test DHCP” text in the serial monitor.

In this case you modified the code in large parts because it should show another message ("[testDHCP]") and after that is should print the used MAC address. Again: post the code you’re using!

Don’t forget to use the code tags (use the “</>” button in the editor) when posting code!

Thanks for the quick response Pylon. Below is how I connected to the Arduino:

Enc28j60 SO → Arduino pin 12
Enc28j60 SI → Arduino pin 11
Enc28j60 SCK → Arduino pin 13
Enc28j60 CS → Arduino pin 10
Enc28j60 VCC → Arduino 3V3 pin
Enc28j60 GND → Arduino Gnd pin

Code of the “back soon” sketch below. All I receive in the browser is “site cant be reached…took too long to respond”

// 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,0,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

const 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);
 }
}

“Test DHCP” does actually seem to work, serial monitor response is:

[testDHCP]
MAC: 74:69:69:2D:30:31

Code is:

// Arduino demo sketch for testing the DHCP client code
//
// Original author: Andrew Lindsay
// Major rewrite and API overhaul by jcw, 2011-06-07
//
// Copyright: GPL V2
// See http://www.gnu.org/licenses/gpl.html

#include <EtherCard.h>

static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };

byte Ethernet::buffer[700];

void setup () {
 Serial.begin(9600);
 Serial.println(F("\n[testDHCP]"));

 Serial.print("MAC: ");
 for (byte i = 0; i < 6; ++i) {
   Serial.print(mymac[i], HEX);
   if (i < 5)
     Serial.print(':');
 }
 Serial.println();
 
 if (ether.begin(sizeof Ethernet::buffer, mymac) == 0) 
   Serial.println(F("Failed to access Ethernet controller"));

 Serial.println(F("Setting up DHCP"));
 if (!ether.dhcpSetup())
   Serial.println(F("DHCP failed"));
 
 ether.printIp("My IP: ", ether.myip);
 ether.printIp("Netmask: ", ether.netmask);
 ether.printIp("GW IP: ", ether.gwip);
 ether.printIp("DNS IP: ", ether.dnsip);
}

void loop () {}

Enc28j60 SO -> Arduino pin 12
Enc28j60 SI -> Arduino pin 11
Enc28j60 SCK -> Arduino pin 13
Enc28j60 CS -> Arduino pin 10
Enc28j60 VCC -> Arduino 3V3 pin
Enc28j60 GND -> Arduino Gnd pin

This is correct for an UNO but wrong for the Mega2560.

You have to change the following connections:

ENC28j60 Arduino
SO -> 50
SI -> 51
SCK -> 52

Leave CS on pin 10, the library expects it there.

"Test DHCP" does actually seem to work, serial monitor response is:

[testDHCP]
MAC: 74:69:69:2D:30:31

If it would work it would put out the received IP address (and other parameters).