Sie sind auf Seite 1von 5

How to use enc28j60 ethernet shield with Arduino Mega 2560 http://en.code-bude.net/2013/06/22/how-to-use-enc28j60-ethernet-shie...

Home
Categories
Shop
About 0
RSS
Tweet
8
1
How to use enc28j60 ethernet shield with Arduino Mega 2560
posted on June 22,0 2013 by Raffi

Today it is time to talk again about one of my favourite gadgets my Arduinos. In particular, for the Arduino Mega 2560 and
how these can be used in combination with the enc28j60 ethernet adapters.

The enc28j60 Ethernet adapter should be known to one or the other of you, who has ever tinkered with an Arduino. These
are the low-cost ethernet shields, which are available for example at eBay for less then 5$. Sure, the wiring and the library
(the original ethernet library isnt compatible), are not quite as comfortable as those of the original ethernet shields, but you
can also save 30$ and more compared to the official ethernet shield.

For the Arduino Uno, there is already a handful of useful articles, which refers to the enc28j60 and Ethercard library.
However, for the Arduino Mega 2560, I could not find anything useful information, so I would like to address briefly below
on the intricacies of this combination.

How to wire Arduino Mega 2560 and enc28j60 ethernet shield

When cabling you must be a bit careful because of some other port assignment of the Arduino Megas. A 1-to-1 replica of the
Arduino Uno tutorials unfortunately does not work.

Below Ive graphed the the wiring for you. But you can also read the exact connections from to the table below the graphic.

Enc28j60 Arduino Mega 2560


GND GND
3.3 3.3V
SO Pin50
SI Pin51
SCK Pin52
CS Pin53

Actually for wiring only 6 pins on the ethernet board has to be used. The remaining 4 pins are not necessary. (At least as long
as you can live without things like wake-on-lan.)

The trick with the Ethercard library

When the Ethercard library is used with Arduino Mega a little piece of code needs to be adjusted. Thus, the begin()-method

1 of 5 18.11.2013 13:45
How to use enc28j60 ethernet shield with Arduino Mega 2560 http://en.code-bude.net/2013/06/22/how-to-use-enc28j60-ethernet-shie...

has to be called with a reference to the Pin53.

1 ...
2 if (ether.begin(sizeof Ethernet::buffer, mymac, 53) == 0)
3 {
4 Serial.println(P("Failed to access Ethernet controller"));
5 }
6 else
7 {
8 Serial.println(P("Ethernet is fine and up"));
9 }
10 ...

Thats all. If the pin has been adjusted in the begin()-method, the library can be used normally (as well as with the Arduino
Uno).

Some more tips

If there are questions or anything is unclear, simply write a comment.

p.s.: Anyone who is still looking for a cheap Arduino Mega, should move on to eBay. There, Ive already bought several
Arduino Megas for ~18$ per unit (including shipping costs).

About the author: This article, as well as 119 more on en.code-bude.net, were published by Raffi. Since
2011 I've been blogging here and on code-bude.net, the german counterpart, about programming and my software, write
tutorials and try to share my knowledge, as well as possible, with my readers. Furthermore I write at
derwirtschaftsinformatiker.de on subjects of my studies.
// Email Google + Facebook Twitter

Related posts:

1. RadioduinoWRT a do it yourself webradio

1. Graham says:
10/19/2013 at 21:41

Raffi

Thanks for this. Ive been struggling for 2 days trying to figure out how to get the Ethernet module to work with my
Mega 2560.

I appreciate you sharing this.

Graham

Reply

2. Mairtin says:
10/15/2013 at 17:31

Hi Raffi,
I bought an ethernet shield off ebay ( http://www.ebay.co.uk/itm/261086363306?ssPageName=STRK:MEWNX:IT&
_trksid=p3984.m1497.l2649 ) it is built to fit directly into the arduino uno, but it fits perfectly into the atmega2560,
with the only difference of CS which i cut off the shield so it wouldnt connect to pin 10(unos CS) and then brought a
wire from pin 53 (megas CS) to ethernet shield.
Ive also notices the number 53 in the snippet of code u have and had it changed before i tested it, but it still doesnt
work is th pin number referenced more than 1 place in the ethernet library?

2 of 5 18.11.2013 13:45
How to use enc28j60 ethernet shield with Arduino Mega 2560 http://en.code-bude.net/2013/06/22/how-to-use-enc28j60-ethernet-shie...

Also I am using the ICSP pins to talk to my shield, could that be an issue im having?
And final question is it 100% necessary to have my arduino and pc connected to a modem because im not using one at
the moment?
Thanks in advance,
Mairtin

Reply

Raffi says:
10/15/2013 at 21:18

Hey Mairtin,

its some time ago, that I wrote this article. But I seem to remember, that the Pin was referenced at more that one
point. I think it was referenced in the header files (*.h) also. Just open the documents in your favourite editor
and search for the pin number with help of Strg+F.

No, they dont have to be connected to a modem. You can give your Arduino a fixed IP. So you can connect it
directly to your pc and send traffic/messages/packets between your pc and your Arduino. Or you take two
PowerLAN (Ethernet over Powerline) adapters and connect your Arduino to your wifi router for example.

I hope I could answer your questions. If theres something not clear, just write me another comment.

Greets,
Raffi

Reply

3. rpg says:
08/25/2013 at 23:09

Man , you solve my problem !!

Thx , from Argentina!

Reply

4. Jackson says:
08/11/2013 at 19:58

Please advise on the cable to use ie cross over or straight through between Enc2860 aand PC. I have no router, can I
still put arduino on web with out router nor switch.

Reply

Raffi says:
08/12/2013 at 09:07

I use a simple patch cable. No crossover. Bringing up the Arduino to net without a router or switch? Sound hard!
What about buying a cheap used switch for ~5 bucks at eBay?

Reply

5. Greg says:
06/28/2013 at 15:31

Can the CS pin be changed to any pin? I would like to use pin 10 as I have a UTFT which uses pin 53.

Ive tried (ether.begin(sizeof Ethernet::buffer, mymac, 10) == 0)


but I cant seem to get it working.

Reply

3 of 5 18.11.2013 13:45
How to use enc28j60 ethernet shield with Arduino Mega 2560 http://en.code-bude.net/2013/06/22/how-to-use-enc28j60-ethernet-shie...

Raffi says:
06/30/2013 at 18:53

I think it should be possible to change the pin. But you have to have a look inside the Ethercard library. Sadly
there seems to be more than one point, where Pin 53 is hardcoded into the library. But if you change all
references, then it should work.

Reply

Name (required)

Email (won't be published) (required)

Website

Subscribe to comments.
Also possible: Subscribe without comment.

Language

TI's Tiva C Series MCUs


www.ti.com/tiva
First ARM Cortex-M4 MCU Implemented
On TI's 65-nm Process Technology.

Easy PIC Programming


Akcijske cijene Arduino
Midspan POE powersupply

Categories

Android (News & Apps) (16)


Android (programming) (2)
Arduino (2)
C#.Net (33)
Downloads (11)
Google (3)
Hardware Hacks (3)
HTML (4)
JavaScript (5)
Linux (15)
OpenWrt (3)

4 of 5 18.11.2013 13:45
How to use enc28j60 ethernet shield with Arduino Mega 2560 http://en.code-bude.net/2013/06/22/how-to-use-enc28j60-ethernet-shie...

Microsoft Office (3)


Perl (1)
Personal stuff (13)
PHP (8)
PowerPoint (2)
Raspberry Pi (1)
SAP (1)
Test (2)
Tutorials (58)
Web Tips (26)
Best of Web (3)
Wiki (2)
Windows 7 (9)
Windows 8 (10)
Wordpress (8)

Recent posts

Best of Web #3
RadioduinoWRT a do it yourself webradio
Best of Web #2
Update: WordPress2Doc 1.1.0.0
How to pixelate images using Javascript

Find us on Facebook

en.code-bude.net
Like

42 people like en.code-bude.net.

Facebook social plugin

Tags

HNBK.plan App wiki c#.net snippet Linux on Android C# OpenWrt Android BoW Heinz-Nixdorf-Berufskolleg freeware JavaScript download Linux Mint .NET Best of
Web PHP Wordpress free HNBK openssh Linux Tutorial TP-Link WR703N

Copyright 2011 - 2013 Raffael Herrmann - All Rights Reserved

A blog forged from coffee and love. Imprint.

5 of 5 18.11.2013 13:45

Das könnte Ihnen auch gefallen