Intro: Super Cheap Ethernet for the Raspberry Pi
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.
Step 1: Parts List
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.
Step 2: Wiring Up
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.
Step 3: Before You Turn It On!
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...)
Step 4: Configure the Software
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
If the Pi responds simply with
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:
(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.txthere).
You can now reboot the system with
Step 5: Reboot and Test
Reboot the Pi, and log in again. Back at the command prompt, check the network configuration with
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!
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:
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:
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
LotEnDo made it!