Arduino Mega 168 with ENC28J60 Ethernet Shield

Wow, who would have thought it would be so hard.

I purchased a cheap Chinese Mega 168 on ebay, along with one of the many ENC28J60 Ethernet cards.  For my project, I needed all of the IO that the Mega supported.  This is my first Arduino project, so I’m new to the Arduino world.  I had no problem whipping together my analog circuitry, and even made it work using the USB serial libraries.  Then I got into the Ethernet game, bought some 75′ long Ethernet cables and thought I would be good to go.  Well, it took a while, but I have made it work.  Here is what I did to get all of those wonderful analog IO ports up on Ethernet.

There are really 2 issues that you must deal with.

1.  Hardware is not compatable

2. Libraries assume that the SPI interface is on pins 10-13

The first problem is that the hardware is not compatible.  The SPI interface on the Mega is different than other boards.  When I started, I just plugged the Ethernet shield into the Mega. The symptom was that initialization never returned.  I found this by adding serial output to the web server example, and moving a print statement down through the code until the serial output failed.



to your setup function.


Serial.println(“got to line x”)

Start at the top of setup and just move it down until you don’t get any print.

When I had the hardware problem, this is the line that failed for me.


To fix this hardware compatibility problem:

Bend pins 10,11,12,13 out your Ethernet shield.  The ports that they connect to on the Mega are not compatible.

Run a jumper wire from pin 10 on the Ethernet Shield to pin 53 on the Mega.

Run a jumper wire from pin 11 on the Ethernet Shield to pin 51 on the Mega.

Run a jumper wire from pin 12 on the Ethernet Shield to pin 50 on the Mega.

Run a jumper wire from pin 13 on the Ethernet Shield to pin 52 on the Mega.

You have finished the hardware problem.  More detailed instructions can be found here:

Now it gets a little interesting.  This fix is for the “standard” Ethernet shield.  So we must adapt it to our ENC28J60 Ethernet Shield.

The best (only) working library that I have found is here:

with the download that I used here:

BUT, we are not home yet.  This library assumes that we are running on a duemilanove processor.  So we will have to make some modifications to Andy’s library analogous to what did with the standard library.

I am running Ubuntu 10.10, although this fix should work for whatever system you are running.  On my system Andy’s code is installed at


In the file:


You will find the definitions for the SPI interface.  They are near the top line 28 for me.  Change the ports to be as follows:

#define DEFAULT_ENC28J60_CONTROL_CS             53
#define SPI_MOSI 51
#define SPI_MISO 50
#define SPI_SCK 52

Now you are ready to implement Andy’s web server demo.  It worked first time for me.  He also added ping support to the base library.  Test with ping first, it’s quick and easy, you can leave it running on your PC until the Mega begins to respond.

Good Luck!

Comments are closed.