Saturday, January 14, 2012

Arduino + ENC28J60 Ethernet Module - Part 2

So at the end of my last adventure with the ENC28J60 and my Arduino Uno I got it working with the 0021 IDE  (so I expect it will work with 0022 and 0023 but I have not tested) and the nuelectronics.com library available from here http://www.nuelectronics.com/download/projects/etherShield.zip  using the following wiring to an Uno.

VCC - 3.3V
GND - GND
SCK - Pin 13
SO - Pin 12
SI - Pin 11
CS - Pin 10

After my success with this I thought I'd try it with IDE 1.0 and it failed.  The nuelectronics library for the ENC28J60 does not work (as of writing) with IDE 1.0.

After a little more hunting I found the ethercard library https://github.com/jcw/ethercard that works with IDE 1.0.  I loaded up the backSoon web server sketch that even uses DHCP to get it's IP addess.
FAIL...

I was beaten and abandoned the effort until today.
Well, not really today as between Thursday and today I have been trawling the web to find anything that would help me and I found it.  Not any official update or guide but a post in the forum for the ethercard with the statement:
a new optional 3rd arg to EtherCard.begin() lets you specify the chip select pin (8..10, default is 8)
Wait a second the EtherCard library uses Pin 8 by default for CS.

So, today I setup up the Arduino and ENC28J60 with the following wiring

VCC - 3.3V
GND - GND
SCK - Pin 13
SO - Pin 12
SI - Pin 11
CS - Pin 8

Started IDE 1.0, loaded the backSoon Sketch.
Compiled and ran it.
Checked my routers list of DHCP clients and there was 1 for Arduino-DB witn an IP of 192.168..1.2
Well an IP address has been assigned
Fired up Firefox and went to 192.168.1.2
SUCCESS!!!!!

Now it's all about figuring out all the technical gubbins on the library so I can do my own stuff.
I want to be able to send data to a webserver and also read data from a webserver and do something based on the data.


Not asking too much but at the moment I have no idea how to make the most of the EtherCard library so a bit of Googling and testing required.  This will keep me entertained through the cold winter months...


UPDATE August 2012: OK, maybe the cold winter  months passed before I got back to this.  A bit more fun with the ENC28J60 and using a web server coded in PHP to control it. http://winkleink.blogspot.co.uk/2012/08/arduino-ethernet-ethercard-xamp-web.html

Thursday, January 12, 2012

Arduino + ENC28J60 Ethernet Module

For Christmas I got a small ENC28J60 Ethernet module from eBay in my stocking.
All the advertisers stated it worked with Arduino so I thought let's have a go.

This is a small cheap, less capable Ethernet connection than the official Ethernet Shield.
The official shield has support built into the IDE but this board has code from very clever contributors.

Last night I rigged up the board using instruction from http://www.electrodragon.com/?p=1112 and it failed.
Not the best start.  So, I tried a few other libaries and again no success. I added voltage buffers (74HC125) to do the voltage change from 3.3V on the ENC28J60 to 5V on the Arduino.   
I asked a question at electrondragon and in fairness to him (I'm assuming him - never met them) he came back straight away with some helpful tips.
Still no luck.
Beaten, off to bed I went and then did a bit more digging today.  The 1 thing I didn't try was using an older IDE.  I took this opportunity to upgrade to Arduino IDE 1.0 where before I was using Arduino IDE 0021.

So, tonight was my second attempt.

I copied the libraries to Arduino IDE 0021 that I had been using.  I uploaded the sketch for the web server.
Opened up Firefox and browsed to 192.168.1.25.
Success 1st time.

I uploaded the ping sketch.  Success 1st time.

I then wired up an LED to Pin 4 and loaded the etherShield_web_switch sketch that allows you to control the LED from a web browser.
Again - success 1st time

Looks like the library referenced on http://www.electrodragon.com/?p=1112 from nuelectronics does not work with the latest IDE 1.0.

If you do a search for Arduino ENC28J60 in Google it will come up with stuff about using voltage convertor to convert the boards 3.3V level to the Arduino's 5V level.  At the same time it is mentioned that the Arduino can handle lower voltage (I think as low as 2V) as a HIGH, so based on the recommendation from electrondragon I just wired the ENC28J60 directly to the pins of the Arduino with no problems at all.
It worked and there was no smoke.
NOTE: As always this is FYI and your smoke and funny smells may be different.

The final hurdle I had to overcome was that the kit I have has male-male jumper wires and as you can see from the picture the ENC28J60 board has pins rather than sockets, so my wires would not work.
I considered buying some male-female wires but then figured out I could use an old HDD IDE cable to convert the pins on the ENC28J60 board to sockets for my jumper wires.

All worked really well.


Now I have the test sketches working I'll have to examine the code and figure out how to do some more interesting things now that the Arduino is connected to the network.

From searching eBay it looks like the Chinese are now manufacturing cheap W5100 based shields that also include a micr-SD slot like the offical Arduino Ethernet shield.  More expensive than the ENC28J60 board but potentially more cost effective as from my readings the W5100 based boards are supported by the built in Ethernet library so no messing with 3rd party libraries that may be out of sync with the IDE (like my experience her)  Also the W5100 by all accounts provides more of the Ethernet stack so uses less memory on the Arduino and more robust.
After messing with the ENC28J60 I expect I will get a cheap W5100 board for doing anything serious.



Finally, there is no video for this one as I'm just running the standard Examples so nothing unique or special and I thought showing my screen equivalent to the electrondragon screens would be a bit of a waste.

Onwards and upwards.


UPDATE: Below is  a follow up post to this one giving a bit more detail on the wiring and the coding.
http://winkleink.blogspot.co.uk/2012/01/arduino-enc28j60-ethernet-module-part-2.html

UPDATE August 2012: A bit more fun with the ENC28J60 and using a web server coded in PHP to control it. http://winkleink.blogspot.co.uk/2012/08/arduino-ethernet-ethercard-xamp-web.html