Super Cheap Ethernet for the Raspberry Pi
by TheSpodShed in Circuits > Raspberry Pi
49228 Views, 67 Favorites, 0 Comments
Super Cheap Ethernet for the Raspberry Pi
![P1110707_title_hires.jpg](/proxy/?url=https://content.instructables.com/FN3/A90Q/IKWVEXQ7/FN3A90QIKWVEXQ7.jpg&filename=P1110707_title_hires.jpg)
This Instructable shows how you can add an Ethernet interface to any Raspberry Pi computer, for the lowest possible cost. You can get a Pi Zero or Model A/A+ connected to the Internet, or add a second network interface to a Model B, for $5 or less. Because it's connected via the GPIO lines, it leaves the USB port free, and doesn't require any extra power supplies or hubs.
Parts List
![P1110700_module_jumpers.jpg](/proxy/?url=https://content.instructables.com/FKS/Z4EJ/IKWVDHK4/FKSZ4EJIKWVDHK4.jpg&filename=P1110700_module_jumpers.jpg)
You'll need just two items here:
- A Microchip ENC28J60 Ethernet module
- 7 jumper wires (female-female type)
I found the module from a supplier on aliexpress.com - a set of three cost all of $9 including shipping from China! There are plenty of other versions on Amazon, Banggood and elsewhere for similar prices - just search for "ENC28J60". Most have a 10-way header for connection, with the signal names printed on the PCB next to it.
The jumper wires I used were from cpc.farnell.com, stock code SC12901, but again there are many alternatives.
You'll also need to ensure you're using a recent Raspberry Pi OS version. The instructions here were written using the Raspbian "Jessie Lite" distribution from February 2016. To be precise, you'll need a version with Device Tree support, which was added to Raspbian distributions at the start of 2015.
Wiring Up
![Pi-GPIO-header.png](/proxy/?url=https://content.instructables.com/F2O/ED8E/IKWXL6J7/F2OED8EIKWXL6J7.png&filename=Pi-GPIO-header.png)
![P1110701_pi_hdr_1.jpg](/proxy/?url=https://content.instructables.com/FAW/2SOM/IKWVF54I/FAW2SOMIKWVF54I.jpg&filename=P1110701_pi_hdr_1.jpg)
![P1110702_pi_hdr_2.jpg](/proxy/?url=https://content.instructables.com/FVU/L3JX/IKWVF54O/FVUL3JXIKWVF54O.jpg&filename=P1110702_pi_hdr_2.jpg)
![P1110704_enc_hdr_1.jpg](/proxy/?url=https://content.instructables.com/FV6/SO77/IKWXL4WM/FV6SO77IKWXL4WM.jpg&filename=P1110704_enc_hdr_1.jpg)
![P1110705_enc_hdr_2.jpg](/proxy/?url=https://content.instructables.com/FK3/EGEB/IKWXL4WN/FK3EGEBIKWXL4WN.jpg&filename=P1110705_enc_hdr_2.jpg)
There are seven wires - two power, four SPI, and an interrupt line - to be connected between the Pi and the ENC28J60. It helps to plan which colour jumper wire you're going to use for each signal beforehand - you can use the suggestions below as a starter.
The PI GPIO header is described in detail at http://www.elinux.org/RPi_Low-level_peripherals - for convenience I've reproduced the 40-pin version here. The ENC28J60 connections should be printed on the PCB itself.
Signals should be wired between the Pi and the ENC28J60 as follows:
Pi ENC28J60 Colour --------------------------------- +3V3 VCC Red GPIO10/MOSI SI Green GPIO9/MISO SO Yellow GPIO11/SCLK SCK Blue GND GND Black GPIO25 INT Blue CE0#/GPIO8 CS Green
If you've followed the suggested wire colours, the headers should look exactly like the photographs.
Before You Turn It On!
![21987012084_51d9607630_k.jpg](/proxy/?url=https://content.instructables.com/FZ4/RZ5T/IKWXLBRO/FZ4RZ5TIKWXLBRO.jpg&filename=21987012084_51d9607630_k.jpg)
If you've miswired it, chances are nothing bad will happen, unless you've got the power supply connections wrong! If you have a multimeter, check for continuity between the +3.3V supply (pin 1 on the Pi GPIO header) and the VCC terminal on the Ethernet module, and between GND (pin 39 on the Pi) and ground on the module.
(Image (c) NASA, from https://www.flickr.com/photos/nasahqphoto/albums/7...)
Configure the Software
![P1110693_config_txt.jpg](/proxy/?url=https://content.instructables.com/FJC/6UVR/IKWVDHM5/FJC6UVRIKWVDHM5.jpg&filename=P1110693_config_txt.jpg)
If you're happy with the wiring, boot up the Pi and log in as usual.
The Linux kernel will now need to be configured to recognise the new device. If you're not familiar working with the command line, check out this introduction on the Raspberry Pi website.
First we'll do a quick check. At the command prompt, type
ls /boot/overlays/enc28*
If the Pi responds simply with
/boot/overlays/enc28j60-overlay.dtb
then you're good to go. If not (i.e. "No such file or directory"), the OS version is too old and you'll need to update it. These instructions assume you're using Raspbian "Jessie" release.
If all's well, type
sudo nano /boot/config.txt
This will start the nano text editor, editing the system configuration file /boot/config.txt.
Scroll down until you find a section starting # Uncomment some or all of these and enter the following two lines:
dtparam=spi=on dtoverlay=enc28j60
(For the first of these, if you can see a line #dtparam=spi=on, you can just remove the # character from the start of the line).
Save the file with Control-O Enter Control-X. (For the curious, there's a lot of information on config.txt here).
You can now reboot the system with
sudo /sbin/reboot
Reboot and Test
![P1110668_perspective.jpg](/proxy/?url=https://content.instructables.com/FSF/4FON/IKWVDHJ3/FSF4FONIKWVDHJ3.jpg&filename=P1110668_perspective.jpg)
Reboot the Pi, and log in again. Back at the command prompt, check the network configuration with
ifconfig
If all is well you can see something like this:
eth0 Link encap:Ethernet HWaddr 9e:df:83:ec:38:91 inet addr:192.168.1.33 Bcast:192.168.1.255 Mask:255.255.255.0 inet6 addr: fe80::a74c:6e6b:de3f:11b2/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:3756 errors:0 dropped:130 overruns:0 frame:0 TX packets:207 errors:15 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:289970 (283.1 KiB) TX bytes:27617 (26.9 KiB) Interrupt:163
(On a Model B, you should of course now have both eth0 and eth1).
If this is working, check your Internet connection (e.g. ping www.google.com) and it's all done!
Troubleshooting
If you don't see any eth0 device, try one of the following troubleshooting tips:
- Re-check the jumper wiring. All wires need to be connected correctly for the interface to function at all.
- Check the link lights on the ENC28J60 module (and on the network hub where you plugged it in). Note that the module provides good old 10-Mbit half-duplex Ethernet; it's possible your hub isn't configured to expect this.
- Check to see the driver module is loaded with:
lsmod<br>
You should see a line starting enc28j60 in the output. If not, re-check the /boot/config.txt contents.
- Check for boot-time messages with the command:
dmesg<br>
You should see messages similar to the following when the driver starts up:
[ 13.012797] spi spi0.0: setting up native-CS0 as GPIO 8 [ 13.013115] spi spi0.1: setting up native-CS1 as GPIO 7 [ 13.128148] enc28j60 spi0.0: enc28j60 Ethernet driver 1.01 loaded [ 13.187818] net eth0: enc28j60 driver registered
followed a short while later by:
[ 18.684532] net eth0: link up - Half duplex [ 18.684755] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready