Update 2018: The cheapest ENC28J60 board I now could find is 2.25 Euro, the cheapest W5500 is 2.70 euro.
With prices of ENC28J60 Ethernet modules coming down drastically with some as low as 4,60 euro, (even cheaper here much cheaper even here), buying one of these to connect barebones Arduino projects to the web becomes more and more attractive. The ENC28J60 has astandard SPI interface. With the official ENC28J60 Ethershield and Ethercard, just sticking it in the Arduino is easy and takes care of the proper connections, but with one of these modules, we need to make these connections ourselves. Though the Vcc is 3.3 Volt, the datasheet states the I/O pins to be 5 V tolerant, which makes it easy to interface with the 5 Volt Arduino. The datasheet (blz. 10) shows that a level-shifter is recommended for the WOL (WakeOnLan), the interrupt and the chip’s MISO. However, this is a general recommendation, because the manufacturer does not know to what MCU you plan to connect the ENC28J60. For use with the Arduino the levelshifter is not necessary. So we just can make the following hardware SPI connections:
ENC28J60 | Arduino | |
---|---|---|
SO | D12 | (MOSI) |
SI | D11 | (MISO) |
SCK | D13 | (SCK) |
CS | D8 (or D10, read further) | SS |
VCC | Separate 3V3 | |
GND | GND |
Should you for any reason decide to use levelshifters, they need to be tri-state, to ensure proper SPI functioning when sharing the bus.
For the ENC28J60 chip/module, there are several Arduino libraries available: Ethershield (development has stopped) and Ethercard (the newest). There is also the UIPEthernet from Norbert Truchsess, that is compatible to the W5100 Ethernet library. To be clear: the Ethernet library is for the WIZ5100 ethernetshield, using the UIPEthernet library makes (most of) the WIZ5100 based programs suitable for the ENC28J60.
(Update: The Ethershield Library is no longer compatible with the Arduino IDE as the “prog_char” deftype is deprecated. Although it is simple to modify the various library files, you need to ask yourself if that is worth the trouble, as there are more modern libraries. If you still want to do it:Replace prog_char with const char, and do the same for other prog_”datatype” typedefs. If there is a PROGMEM const char *string_table[] =, replace with PGM_P const string_table[] PROGMEM =)
A note on the Chipselect CS
The use of the proper CS pin is depending on what library one uses for the ENC28J60.
there are defacto three libraries:
- The Ethershield library uses pin 10 as a chipselect
- The EtherCard library uses pin 8 as a chipselect
- The UUPEthernet library uses pin 10 as a chipselect
The reason for this change from 10 to 8 is to be able to use the Ethercard together with an SD card.
If you buy a module, rather than a shield, it is very easy to determine what chipselect pin you want to use. If you use the older EtherShield library, use pin 10 as CS, if you use the somewhat newer Ethercard library, use pin 8.
If for whatever reason you want to use the Ethercard library with pin 10, change the pin assignment in the library files ENC28J60.h (line 25 and 41 I believe) and the EtherCard.h (Line 134: uint8_t csPin = 8 ). (Depending on the version it can also be in line 154.)
It is also possible to add the declaration for pin 10 in the program itself like this:
This card works with a Mega2650 if you override the CS pin in the sketch. The pin mapping is –
ENC28J60 | Mega2650 | |
---|---|---|
SO | 50 | (MISO) |
SI | 51 | (MOSI) |
SCK | 52 | (SCK) |
CS | 53 | (SS) |
In the sketch you need to override the begin with ether.begin(sizeof Ethernet::buffer, mymac, 53) (note the 53) because the default is for pin 8 on a UNO. If you use another pin for the CS you will need to manually set pin 53 as an output or SPI doesn’t work.
The RST and INT pin can be connected as follows but it is not strictly necessary
ENC28J60 | UNO | Mega |
---|---|---|
Vcc | 3V3 | 3V3 |
RST | RST | RST |
INT | 2 | 2 |
GND | GND | GND |
SCK | D13 | D52 |
SO | 12 | 50 |
SI | 11 | 51 |
CS | 10 | 53 |
CLKout | – | – |
WOL | – | – |
Similar info here
Adding the ENC28J60 to a Raspberry Pi
ENC28J60 | Raspi BCM pins | Raspi Physical pins |
---|---|---|
INT | 25 | 22 |
SO | 9 (MISO) | 21 |
SCK | 11 (SCLK) | 23 |
SI | 10 (MOSI) | 19 |
CS | 8 (CE0) | 24 |
As there sometimes is confusion about the numbering of the pins I added the physical numbers of the pins as well as the BCM numbers
Obviously you connect ground to ground and the Vcc to a suitable source. If your ENC28J60 module has a 5Volt entrance (followed by a 3V3 regulator) you can connect it to the 5V pin of the raspberry.
If the module needs 3V3 on the Vcc, you could try and feed it from the 3v3 pin of the raspberry, but the current draw is a bit outside the specs of the raspberry. In that case it might be wise to add a small 3v3 LDO and feed it from the 5Volt line.
Once you have done that you need to enable SPI on the raspberry. You do that via the raspi-config utility or via Menu > Preferences > Raspberry Pi Configuration> Interfaces tab on the desktop. You could also just uncomment the line dtparam=spi=on in your /boot/config.txt file
Then add the following to your /boot/config.txt
dtoverlay=enc28j60
reboot and then your Ethernet should work