Implementation for Microchip ENC28J60 Ethernet controller

Hello guys,
I have one "etherShield" (an Ethernet shield that uses the Microchip ENC28J60 controller) and it does not work with the standard Arduino Ethernet library. It works with the etherShield library (http://www.nuelectronics.com/estore/?p=12) but is very very painful to write code for it (we need to implement ARP and TCP actions in the "application" layer - you can see examples in http://www.nuelectronics.com/download/projects/etherShield.zip).
The good news is that Microchip ENC28J60 is cheaper than WIZnet W5100. So I decided to write a new library (for now it's called Ethernet_ENC28J60) compatible with Arduino Ethernet examples, Ethernet.cpp, Server.cpp and Client.cpp - to do it I'm writing a socket layer that exposes the same API the standard Ethernet library does.
For now I can create a TCP server with some limitations -- but it works! :slight_smile: I modified the WebServer example to make it more simple and actually I can complete a HTTP request successfully.

I'm planning to turn it fully-compatible with Arduino Ethernet shield library and want to know if we can merge this code in the Ethernet library when it is done -- so we can support both controllers, with the same code (maybe adding "#define ENC28J60" to application's code so the Ethernet library can switch between the "card driver").

The code is available at GitHub (GitHub - turicas/Ethernet_ENC28J60: [NOT MAINTAINED, NOT COMPLETED] Implementation of an Arduino-compatible socket layer library that uses Microchip ENC28J60 Ethernet controller.) -- please read the README to know about architecture and other things.
If you want to test, put Ethernet_ENC28J60 at ~/sketchbook/libraries and run the WebServerSimple example (Ethernet_ENC28J60/WebServerSimple.pde at master · turicas/Ethernet_ENC28J60 · GitHub). I also created an example that controls a LED using the Web interface (available at Ethernet_ENC28J60/WebServerSimpleLED.pde at master · turicas/Ethernet_ENC28J60 · GitHub).
Please let me know your opinion!

Note: I posted an email about this in the developers mail list but as it wasn't answered, I'm posting here. What is the best place to this kind of topic?

Thanks.

Sounds great!
Might use it in a future project that I have been delaying because of this (expensive wiznet and bad support for the enc28j60).
I'm now watching the project @github (awesome code sharing platform by the way) to be up-to-date.

One question, which are the differences between the ethernet and fullstack repos at github?

Keep up the good work!

chiva:
Might use it in a future project that I have been delaying because of this (expensive wiznet and bad support for the enc28j60).
I'm now watching the project @github (awesome code sharing platform by the way) to be up-to-date.

Very nice! :slight_smile:

chiva:
One question, which are the differences between the ethernet and fullstack repos at github?

Please ignore FullStack - I started with this project trying to change Ethernet.cpp, Server.cpp and Client.cpp but I decided to rewrite only socket.c instead of all those files. Rewriting just socket.c may be more painful but it'll more easy to maintain compatility with Arduino Ethernet Library, write "drivers" for other controllers and also improving the actual Ethernet library.
I'll delete the FullStack repository in a near future.

If you can, please try the examples I sent to the repository and send news about it! Now working on connect().

I don't have a board to test it, but I am now more interested in getting one

alvarojusten:
So I decided to write a new library (for now it's called Ethernet_ENC28J60) compatible with Arduino Ethernet examples, Ethernet.cpp, Server.cpp and Client.cpp - to do it I'm writing a socket layer that exposes the same API the standard Ethernet library does.

Very nice! Happy to hear it. Bringing up my ENC28J60 is my next project, so I will definitely check this out. I mostly need a client, so maybe I can pitch in for your efforts :slight_smile:

As to getting it in as an official library, definitely finish it first. Then the code can be reviewed and really proposed.

Hello,

what about this instructable. He claims, that you can use the Arduino-Ethernet-library. I didn´t test it so far.

themroc:
what about this instructable. He claims, that you can use the Arduino-Ethernet-library. I didn´t test it so far.
http://www.instructables.com/id/A-credit-card-sized-Ethernet-Arduino-compatable-co/

Hello,
it uses the code from etherShield I mentioned above. "etherShiled" is different from "Ethernet shield" - "etherShield" refers to code (for ENC28J60 controller) that is hard to use and is not present on Arduino IDE; "Ethernet shield" refers to standard Arduino Ethernet shield and code (for controller W5100). If you download the .pde file he attached to the instructable you'll see that this code does not use the Arduino standard Ethernet library.
What I'm trying to do is to create a Arduino Ethernet-compatible library that works with both controllers (so you can use the same code for both).

Hi

This is perfect timing. I have a board and are about to start writing a skecth for it.

I would like very much to have support for DHCP and DNS

Best regards

Wolle:
This is perfect timing. I have a board and are about to start writing a skecth for it.

I would like very much to have support for DHCP and DNS

Hello Wolle,
firstly I'm trying to finish the socket layer (implementing part of TCP and UDP stacks). In the future I can work in another protocols (such DHCP, DNS etc.), but first I need to finish socket layer. :slight_smile:
If you can use the library, please give me your feedback.
Thanks.

Hi,

Compiling gives me errors ?

arduino-0022\libraries\turicasEthernet\utility\socket.c: In function 'connect':
arduino-0022\libraries\turicasEthernet\utility\socket.c:190: error: 'destinationPort' redeclared as different kind of symbol
arduino-0022\libraries\turicasEthernet\utility\socket.c:189: error: previous definition of 'destinationPort' was here
arduino-0022\libraries\turicasEthernet\utility\socket.c:210: error: redeclaration of 'sourcePort' with no linkage
arduino-0022\libraries\turicasEthernet\utility\socket.c:190: error: previous declaration of 'sourcePort' was here
arduino-0022\libraries\turicasEthernet\utility\socket.c:211: error: redeclaration of 'destinationPort' with no linkage
arduino-0022\libraries\turicasEthernet\utility\socket.c:190: error: previous declaration of 'destinationPort' was here

Hi alvarojusten,

This is fantastic news !

I am sure there are lots of people out there who are eagerly waiting your library. I just wanted to send you encouragement !!!

Cheers from Sg,
Keff

Enn40:
Hi,

Compiling gives me errors ?

arduino-0022\libraries\turicasEthernet\utility\socket.c: In function 'connect':
arduino-0022\libraries\turicasEthernet\utility\socket.c:190: error: 'destinationPort' redeclared as different kind of symbol
arduino-0022\libraries\turicasEthernet\utility\socket.c:189: error: previous definition of 'destinationPort' was here
arduino-0022\libraries\turicasEthernet\utility\socket.c:210: error: redeclaration of 'sourcePort' with no linkage
arduino-0022\libraries\turicasEthernet\utility\socket.c:190: error: previous declaration of 'sourcePort' was here
arduino-0022\libraries\turicasEthernet\utility\socket.c:211: error: redeclaration of 'destinationPort' with no linkage
arduino-0022\libraries\turicasEthernet\utility\socket.c:190: error: previous declaration of 'destinationPort' was here

Hello Enn40,
excuse me for that - I pushed a code that I didn't compile to verify syntax problems (it'll not happen again). Please download the library again and try it: the last commit I did to repository is working fine (maybe you can experience some bugs if you enable debugging, but the normal usage of the library is OK now).

keff_in_sg:
Hi alvarojusten,

This is fantastic news !

I am sure there are lots of people out there who are eagerly waiting your library. I just wanted to send you encouragement !!!

Hello Keff,
thanks! It'll be nice if you have an etherShield, test the library and give me more feedback.

Thanks ,

Web server simple led example gives me:

/arduino-0022/arduino-0022/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/bin/ld.exe: WebServerSimpleLED.cpp.o: No such file: No such file or directory

Enn

Enn40:
Web server simple led example gives me:

/arduino-0022/arduino-0022/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/bin/ld.exe: WebServerSimpleLED.cpp.o: No such file: No such file or directory

Sorry, I don't use Windows and don't know how to add customized libraries. What I can suggest is to move the Ethernet_ENC28J60 folder from sketchbook/libraries to the libraries folder in the Arduino installation path.

Sometimes the Arduino IDE gives me some errors about paths but I just need to recompile and it works fine -- maybe it could be your case too.

Yeah, I just pulled this, and compiled the examples, and they all compiled without any complaints. This is on OSX.

alvarojusten:
firstly I'm trying to finish the socket layer (implementing part of TCP and UDP stacks).

So, what's left to be done to get clients working?

maniacbug:
Yeah, I just pulled this, and compiled the examples, and they all compiled without any complaints. This is on OSX.

Nice! Did you opened your browser to test if page load fine?

alvarojusten:
Nice! Did you opened your browser to test if page load fine?

Nono, haven't touched the hardware yet. Just pulled down the software and started to dig through it.

What do you suggest as a simple test to see if the connections are even hooked up right?

Ok, actually just for fun, I threw this together.

Running WebServerDEBUG, I get this:

DEBUG:
  INIT
DEBUG:
  ANSWERING_RECEIVED_ARP_REQUEST
DEBUG:
  INIT
DEBUG:
  INIT
DEBUG:
  ANSWERING_RECEIVED_ARP_REQUEST
DEBUG:
  INIT
DEBUG:
  INIT
DEBUG:
  INIT
DEBUG:
  INIT
DEBUG:
  INIT
DEBUG:
  INIT
DEBUG:
  INIT
DEBUG:
  ANSWERING_RECEIVED_ARP_REQUEST
DEBUG:
  INIT
DEBUG:
  IGNORING_PACKET_NOT_FOR_ME
DEBUG:
  INIT
DEBUG:
  INIT
DEBUG:
  INIT

And this is what I did to trigger it (and yes, I changed the IP address in the example to this one)

$ wget http://192.168.1.98/
--2011-03-27 20:47:21--  http://192.168.1.98/
Connecting to 192.168.1.98:80... connected.
HTTP request sent, awaiting response... Read error (Operation timed out) in headers.

maniacbug:
And this is what I did to trigger it (and yes, I changed the IP address in the example to this one)

$ wget http://192.168.1.98/

--2011-03-27 20:47:21--  http://192.168.1.98/
Connecting to 192.168.1.98:80... connected.
HTTP request sent, awaiting response... Read error (Operation timed out) in headers.

I know about this problem. The fact is that debugging uses too much memory and probably it needs more memory than an Arduino have. The version without debugging works perfectly. In the next days I'll work on this problem to reduce memory usage of debugging routines and hope it be fixed. Please see for updates on GitHub!