All Projects → turicas → Ethernet_enc28j60

turicas / Ethernet_enc28j60

Licence: gpl-2.0
[NOT MAINTAINED, NOT COMPLETED] Implementation of an Arduino-compatible socket layer library that uses Microchip ENC28J60 Ethernet controller.

Programming Languages

c
50402 projects - #5 most used programming language

Ethernet ENC28J60

Note: unfortunately I don't have time to maintain (and finish) this implementation. Please see arduino_uip.

Microchip ENC28J60 is an Ethernet controller with SPI interface that is used in some Arduino Ethernet Shields (these are called "etherShield"s). Unfortunatelly, the standard Arduino Ethernet Shield (called "Ethernet Shield") have the WIZnet W5100 controller - and only the version with W5100 is oficially supported by the Arduino standard library.

There is a library called etherShield but it is very hard to use (you need to manage ARP and TCP packets in the "application layer"). So, I decided to write a new socket.c (based on etherShield's code) that exposes the same API the standard Ethernet Shield library exposes.

The goal of the project will be achieved as an Arduino user can use the same code for both Ethernet controllers (W5100 and ENC28J60). With this project I can also identify architectural problems in the standard Ethernet library implementation and make it better.

   

    Arduino with etherShield (based on Microchip ENC28J60 Ethernet controller)

This library is developed to work with Arduino 1.0. It can run in older versions (like Duemilanove) with little modifications in the code, but it is not oficially supported.

Where to buy

Please read the file resources/resources.markdown.

Usage

Download the tarball at GitHub and put the library inside sketchbook/libraries/ folder. If you just want to test without debugging, use the examples WebServerSimple and WebServerSimpleLED.

WARNING: This is a work-in-progress project and need more tests to be used in production environments!

Using with Arduino Mega

This library is compatible with Arduino Mega, but you need a hardware-hack so ENC28J60 can communicate (using SPI) with Arduino. Please refer to http://mcukits.com/2009/04/06/arduino-ethernet-shield-mega-hack/ for more information.

Limitations

For now that are some limitations that will be removed in a near future:

  • Just one socket per time;
  • Only support for TCP server -- connect(), sendto() and recvfrom() don't work yet;
  • Can only "answer" to the last packet received.

Architecture

WIZnet W5100 Library

In the standard Ethernet library, the Ethernet, Server and Client classes use the socket API to send and received data over the network. The socket library uses the "driver", (w5100 library) to communicate with the controller. Something like this:

{Ethernet.cpp, Server.cpp, Client.cpp}socket.cw5100.c

Microchip ENC28J60 Library

In my implementation I have another layer: ip_arp_udp_tcp. This is a kind-of socket layer (it is really not a socket layer since it doesn't provide a kind of socket API -- merely we have here a lot of helper functions to read, identify, create and send packets using the "driver" enc28j60). For now, we have this:

{Ethernet.cpp, Server.cpp, Client.cpp}socket.cip_arp_udp_tcp.cenc28j60.c

In a near future I want to replace all ip_arp_udp_tcp layer in the socket layer, so the architecture will be more like the standard Ethernet library:

{Ethernet.cpp, Server.cpp, Client.cpp}socket.cenc28j60.c

When this goal is reached we can create a single socket.c that communicate with one or another controller (W5100 or ENC28J60).

Contributing

If you want to contribute, please run the tests with your board. The tests are made using shell script, so you need a UNIX environment. To run the tests:

  • Plug your Arduino with ENC28J60 module/shield in USB port
  • Plug the network cable in the Ethernet module/shield
  • Change Arduino path in make.sh (it is tested under Ubuntu GNU/Linux, you'll need to change the port if you use other UNIX-like SO)
  • Go to tests folder and run the file run

If you get some error, investigate if you can compile, reset and upload the Blink example using make.sh script (run the command: SKETCH_NAME=path-to-blink.pde ./make.sh).

Next Goals

  • Finish implementation of connect()
  • Modify send() to accomplish TCP client sockets
  • Implement sendto() and recvfrom() (UDP)
  • Support for multiple sockets
  • Put all the features of ip_arp_udp_tcp.c in socket.c

How To Debug

If do you want to test and modify this library, probably you will want also to enable debugging. You can see what is happening using the Serial Monitor on Arduino IDE if you uncomment the line below in the file utility/socket.h:

//#define ETHERSHIELD_DEBUG

Please use the examples WebServerDEBUG and WebClientDEBUG for debugging (and to learn how to do it).

Related Software

  • Nuttx
  • uIP
  • Cotiki
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].