How to choose the right library to add ethernet (Enc28j60) to your Arduino

These last days I spent some time playing with ethernet on my Arduino. The main goal is to make the Arduino accessible directly for the web via the Web. To do so I played with several shields or modules.

Tested Modules

Arduino Yun

arduino-yun-en

Arduino Yun is smart and well integrated but the price is quite elevated (about $75 on Amazon).

The important thing: The ethernet layer is integrated via a linux system running on parallel with the Arduino: no Arduino resources used by this layer

Pros Cons
Built by Arduino Expensive more than $70
Linux to manage Ethernet Need Bridge to access to Linux Layer
Wifi support
Library maintained by Arduino Team

 

Arduino Ethernet Shield

The Arduino ethernet shield is built by the Arduino team (about $15 on Amazon).

With this shield a SD card is integrated. It can be useful for data loging

Pros Cons
Built by Arduino A full shield. Can not be integrated in a standalone Atmega project
SD card socket Price. Not really expensice but about $15
Library maintained by Arduino Team

 

Enc28j60 Module


Enc28j60 is cheap module (about $7 on Amazon).

It is dedicated to the ethernet and easy to plug to the Arduino via the SPI

Pros Cons
Cheap library no maintained by Arduino Team
Lot of open source libraries Need to make a choice to select the right librairie
Can be used directly on atmega (without arduino card)

 

As you understood reading the title of this article I choose enc28j60 module mainly because of the price and also because I want to use it without the full Arduino Card (see one of my previous article: http://www.homautomation.org/2014/03/06/running-atmega328-in-a-standalone-mode-without-arduino-shield/).

Now it is time to choose a good library but before choosing a lib. How to wire it?

 

Wiring a Enc28j60 module

  • 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

 

Choosing a librairie for Enc28j60

Now your system is ready. It is time to choose a library. There are 2 main libraries:

EtherCard

EtherCard is a driver for the ENC28J60 chip, compatible with Arduino IDE.
Adapted and extended from code written by Guido Socher and Pascal Stang.

License: GPL2

The documentation for this library is at http://jeelabs.net/pub/docs/ethercard/

EtherCard is available for download here: https://github.com/jcw/ethercard

It is compliant with :

  • DHCP
  • DNS
  • UDP

NB: pin Connected to Enc28j60 CS can be chosen programmatically

Exemple of a simple server


NB: on this exemple, if you use the previous wiring, you have to change the setup fonction:

void setup () {
  //CS is connected to pin 10
  if (ether.begin(sizeof Ethernet::buffer, mymac, 10) == 0)
    Serial.println(F("Failed to access Ethernet controller"));
  ether.staticSetup(myip);
}

UIPEthernet

A plugin-replacement of the stock Arduino Ethernet library for ENC28J60 shields and breakout boards. Full support for persistent (streaming) TCP-connections and UDP (Client and Server each), ARP, ICMP, DHCP and DNS. Build around Adam Dunkels uIP Stack.

License: GPL v3

UIPEthernet is available for download here: https://github.com/ntruchsess/arduino_uip

This library uses the same API as the official Arduino Ethernet. It’s useful to integrate ENC28J60 in project on the same way you integrate Arduino Shield

It is compliant with

  • DHCP
  • DNS
  • UDP
  • TCP
  • ARP
  • ICMP

Exemple of simple server

NB: As it is compliant with classical Arduino Ethernet Lib. You can use Webduino on top of it.

Webduino is an Arduino-based Web Server library, originally developed for a class at NYC Resistor. It’s called Webduino, and it’s an extensible web server library for the Arduino using the Wiznet-based Ethernet shields. It’s released under the MIT license allowing all sorts of reuse.

 

Conclusion

For my needs I use:

  • ENC28J60 module (the cheaper)
  • UIPEthernet as library (because it is fully compliant with Arduino Ethernet Lib)
  • Webduino on top of it to easier write code.

Hope this helps!

12 Comments

  1. Thanks for useful information, Vincent.
    I have a question though..
    “This library (UIPEthernet) uses the same API as the official Arduino Ethernet. It’s useful to integrate ENC28J60 in project on the same way you integrate Arduino Shield”

    Should I just replace standard library with UIPEthernet? For example:
    #include
    #include
    //replace with #include
    #include

    So all the standart library functions supported from the box? For example:
    //setup ethernet and udp socket
    Ethernet.begin(mac,ip);
    Udp.begin(localPort);

    Reply
  2. Nice article! UIPEthernet is great! I was wondering about the size though, I take it the EtherCard is smaller in kB than UIPEthernet? I ask because I ran into problems trying to send gyro data over internet. I couldn’t for both gyro library and UIPEthernet into Arduino Nano/Duo.

    Reply
  3. Hoy can I chance the port i/o, I wanna send byte by port 80 but I wanna receive by another port… How can I do it?

    Please help me

    Reply
  4. I am trying to connect ENC28J60 using network bridge. since the connection are fine but the output is not found. the Ip address i am browsing there is no web content available. help me out.

    Reply
  5. Hi,
    Do you have a full project that shows how all the pieces (enc286j60, uipethernet, webduino) fit together to form a working example?
    Thanks!
    Ben

    Reply
  6. Hi Vencent,
    Thank you for this article!
    I am trying to make this work with Arduino Mega 2560 and ENC28j60 using the UIPEthernet library (latest release and/or forks) to run one of the Webduino examples (“Web_Params”), replacing relevant includes with “#include ”. The problem I am facing happens during compilation, here is a bit of a stack trace I get:
    In file included from C:\Users\[USER]\Documents\Arduino\libraries\UIPEthernet\src/UIPEthernet.h:28:0,
    C:\Users\[USER]\Documents\Arduino\libraries\UIPEthernet\src/ethernet_comp.h:5:24: error: redefinition of ‘class UIPClient’
    #define EthernetClient UIPClient
    C:\Program Files (x86)\Arduino\libraries\Ethernet\src/EthernetClient.h:8:7: note: in expansion of macro ‘EthernetClient’
    class EthernetClient : public Client {

    Can you point me in the right direction of how to compile this?
    Thank you!

    Reply

Leave a Comment.