Facebook Twitter Instagram Pinterest YouTube
    Trending
    • CrowPi L Raspberry Pi Laptop and Learning Platform
    • Pi Pico W Launched
    • Add Kodi to RetroPie Menu
    • Disable Auto-login in Raspberry Pi OS
    • Raspberry Pi Cloud Storage with MEGA
    • RetroPie Temperature Monitor from Menu
    • Pi Pico Pinout and Power Pins
    • Install Arduino IDE on Raspberry Pi
    Facebook Twitter Instagram Pinterest YouTube RSS
    Raspberry Pi SpyRaspberry Pi Spy
    • Home
    • Categories
      • General
      • Hardware
      • Programming
      • Python
      • Software
      • Tutorials & Help
    • BerryClip
      • BerryClip Instructions
      • BerryClip Plus Instructions
      • Videos & Reviews
    • Buy
      • Buy Pi
      • Buy Pi Accessories
      • Buy Books
    • Tools
      • Ultimate Raspberry Pi Alexa Skill
      • Pi Power Estimator App
      • Pi-Lite 14×9 LED Matrix Sprite Editor
      • RPiREF Pin-out Reference App
      • Simple Ohm’s Law Calculator
      • Web Sites & Links
    • Tutorials & Help
        Featured
        November 9, 20200

        Raspberry Pi Temperature Monitoring

        Recent
        May 6, 2022

        Add Kodi to RetroPie Menu

        February 26, 2022

        Disable Auto-login in Raspberry Pi OS

        February 2, 2022

        Raspberry Pi Cloud Storage with MEGA

      1. Contact Us
      2. Site Map
      Raspberry Pi SpyRaspberry Pi Spy
      You are at:Home»Hardware»Pi Zero»Adding Ethernet to a Pi Zero

      Adding Ethernet to a Pi Zero

      9
      By Matt on May 20, 2020 Pi Zero, Tutorials & Help

      The Pi Zero has no Ethernet port. If your project requires Ethernet you can add it using either an Ethernet module or a USB to Ethernet adapter.

      At this point someone is going to question why you would want to add Ethernet to a Pi Zero. Why not just use a standard Pi which already includes the port? I guess the answer is that there are some projects where using a Pi Zero is desirable due to power consumption or size considerations but you also need the functionality of Ethernet devices. I’ve got a project in mind which I will blog about in the future (if it proves to be successful).

      ENC28J60 Ethernet SPI Module

      Microchip make the ENC28J60 which is a stand-Alone Ethernet Controller with SPI Interface. It is available as a cheap module which can be connected to the Pi’s SPI interface.

      ENC28J60 Ethernet Module

      The pin-out can vary but most modules will contain a block of 10 pins carrying the following signals :

      ENC28J60 Module Pin Connector
      • VCC & Gnd
      • CLK
      • INT
      • WOL
      • MISO & MOSI
      • SCK
      • CS
      • RST

      Some modules require 5V while others will work with 3.3V. Pay attention to the details when purchasing one so that you can connect it to the correct voltage. My module runs from 3.3V.

      Connecting ENC28J60 to the Pi Header

      The module can be connected to the Pi’s GPIO header using female-female Dupont style jumper cables.

      Pi HeaderModuleModulePi Header
      –CLKINTPin 22 (GPIO25)
      –WOLMISOPin 21 (GPIO9)
      Pin 19 (GPIO10)MOSISCKPin 23 (GPIO11)
      Pin 24 (GPIO8)CSRST–
      Pin 17 (3.3V)
      Pin 2 (5V)
      VCCGNDPin 25 (Gnd)

      As only 7 pins need to be connected you can connect the module to the Pi Zero using 7 cables.

      Connect the ENC28J60 to your Network

      Obviously you should connect the ENC28J60 module to your network using an Ethernet patch cable. I connect mine to a network switch but you could connect directly to a spare port on your router.

      Given how light the Pi Zero and module are you may want to tape your cables to a surface to prevent them dragging your setup onto the floor.

      Pi Zero connected to ENC28J60 Ethernet Module

      You may notice in this photo that rather than use Pin 25 for Ground I used Pin 39. This was due to a faulty bit of soldering on my Pi Zero header.

      Pi Zero Ethernet Software Setup

      The software setup is really easy. You only need to edit the config.txt file and make two potential changes. I recommend starting with a freshly imaged SD card using the latest version of Raspbian.

      The config.txt file can be edited on any computer that can read the boot partition on the SD card. Or it can be edited directly on the Pi if you have a keyboard and monitor attached.

      sudo nano /boot/config.txt

      Find the line:

      #dtparam=spi=on

      and delete the # character to leave :

      dtparam=spi=on

      Then add the following line :

      dtoverlay=enc28j60

      You should end up with a section in your config.txt looking like this:

      Enable ENC28J60 overlay in config.txt

      Save and exit using CTRL-X, Y and ENTER.

      Power-up or Reboot

      If you are working directly on the Pi you can now reboot :

      sudo reboot

      If you configured the SD card on a PC you can now insert it into the Pi and power-up.

      Your Pi should connect to your network automatically.

      Set MAC Address

      Unlike most other network devices you might have used in the past the ENC28J60 has no preset MAC address. This means it is randomly generated every time the device is started. This may not bother you but could cause your router to keep allocating a different IP address. If you need a consistent MAC address you have to set it in software.

      In the following example I use “b8:27:eb:00:00:01”. If you have multiple devices using this technique you should make sure they are all unique and never clash with other devices on your network.

      Start by creating the following file:

      sudo nano /lib/systemd/system/setmac.service

      Add the following contents:

      [Unit]
      Description=Set MAC address for ENC28J60 module
      Wants=network-pre.target
      Before=network-pre.target
      BindsTo=sys-subsystem-net-devices-eth0.device
      After=sys-subsystem-net-devices-eth0.device
      [Service]
      Type=oneshot
      ExecStart=/sbin/ip link set dev eth0 address b8:27:eb:00:00:01
      ExecStart=/sbin/ip link set dev eth0 up
      [Install]
      WantedBy=multi-user.target

      Save and exit using CTRL-X, Y and ENTER.

      sudo chmod 644 /lib/systemd/system/setmac.service
      sudo systemctl daemon-reload
      sudo systemctl enable setmac.service

      Reboot

      With everything configured you can now reboot your Pi using:

      sudo reboot

      Once you are back at the command line you can check what IP and MAC addresses your Pi is using with :

      ifconfig

      Which should give you an output looking something like :

      Pi Zero ifconfig example output

      Here we can see the Pi is using the MAC address we set and has been given an IP address of 192.168.001.131 by my router.

      Performance

      Using the speedtest-cli utility I measured the speed of the network link to be between 3.15 and 3.7 Mbits/s. Whether this is adequate will depend entirely on the project you are building.

      Pi Zero ENC28J60 speed test results.

      Power & Current Requirements

      Lots of people are happy using these devices powered directly from the Pi’s 3.3V pin. However the datasheet for the ENC28J60 states it can require 180mA of current when transmitting which is beyond the 50mA limit of the Pi’s onboard 3.3V regulator.

      For this reason I decided to ensure my ENC28J60 was never starved of current and added a small 5V to 3.3V regulator (HK1117). This small 3-pin module is easy to connect and provided the Ethernet device with all the current it might ever need.

      Pi HeaderHK1117ENC28J60
      Pin 2 (5V)Vin–
      Pin 6 (Gnd)Gnd–
      –VoutVcc (3.3V)

      Pi Zero Ethernet Troubleshooting

      While setting up my module and writing this article I came across a few issues. These were solved by taking note of the following points :

      • Double check all your connections
      • Check for loose connections
      • Be careful not to confuse CLK and SCK
      • Be careful not to confuse MISO (SO) and MOSI (SI)
      • Consider using a separate 3.3V regulator to provide adequate current

      Buy an Ethernet Module

      The ENC28J60 is available from lots of retailers including :

      • ENC28J60 on eBay

      My device was described as a “Mini ENC28J60” and cost £4.

      Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
      Previous ArticleNtablet an Open-source Tablet
      Next Article Raspberry Pi VPN Setup Guide

      Related Posts

      Add Kodi to RetroPie Menu

      Disable Auto-login in Raspberry Pi OS

      Raspberry Pi Cloud Storage with MEGA

      9 Comments

      1. Henry on May 20, 2020 6:21 pm

        Brilliant! The only negative I can see to this is that neither unit has a case to enclose them. Someone who’s into 3D printing should perhaps try to design a case that will hold a Raspberry Pi Zero and a ENC28J60 module side by side or end to end or even one on top of the other, just anything that will keep them from moving around in relation to each other and possibly shorting out!

        Reply
        • Matt on May 20, 2020 6:47 pm

          The project I have in mind will definitely require the components to be secured in an enclosure. The cables weigh more than the Zero and the module so I taped then to my desk to avoid the whole setup getting dragged onto the floor. Once I know exactly what items I need for my project I’ll have to decide what enclosure to use and how best to fit everything inside.

          Reply
      2. Steve on May 27, 2020 1:21 am

        Interesting post — welcome back! I had about given the website up for dead. Quick question for you: on the face of it, this seems like overkill; is there any reason why you couldn’t just use a Ethernet->USB port? These are readily available on the market and work well. It seems to me like this would be a much simpler approach.

        Reply
        • Matt on May 27, 2020 8:14 am

          I’ve got an Ethernet-USB adaptor and plan to give that a try as well. I think the reason the ENC module might be useful is that you could pack it into a smaller space and it wouldn’t require a USB plug to stick out the side of the Pi. Although the USB plug could be cut off and the wire soldered directly to the back of the Pi PCB. The ENC modules are also marginally cheaper so if you needed a lot of them it might bring the total cost down.

          Reply
          • steve on May 28, 2020 8:37 am

            Fair enough…although there are 90-degree USB connectors that could considerably lower the profile of the connection. In my experience, the Eth-USB adaptors are completely plug-and-play — no configuration, nothing to troubleshoot, so that would be a big win in my book.

            Looking forward to future posts!

            Reply
      3. Colin on June 20, 2020 1:09 pm

        You can get those SPI to Ethernet modules with a 5v regulator included on the module, the couple I have which I got on ebay as well have the AMS1117 3.3 regulator on the bottom of the board and on the header there is one for a 3.3v supply and one for a 5v supply which feeds the regulator which then supplys the module.

        Reply
      4. Adam Insanoff on August 8, 2020 3:21 pm

        Many thanks for the instruction. Worked from first try.

        Reply
      5. Daniel on June 3, 2021 10:21 am

        Does this prevent anything else working e.g. the camera? I’d love to try and implement this for CCTV…

        Thanks

        Reply
        • Matt on June 18, 2021 10:45 pm

          Creating a CCTV camera was the reason I started playing with these devices. I didn’t get around to tying it but there is no reason it shouldn’t work.

          Reply

      Leave A Reply Cancel Reply

      This site uses Akismet to reduce spam. Learn how your comment data is processed.

      Recent Posts
      July 26, 2022

      CrowPi L Raspberry Pi Laptop and Learning Platform

      June 30, 2022

      Pi Pico W Launched

      May 6, 2022

      Add Kodi to RetroPie Menu

      February 26, 2022

      Disable Auto-login in Raspberry Pi OS

      February 2, 2022

      Raspberry Pi Cloud Storage with MEGA

      Categories
      • 1-wire
      • 3D Printing
      • Add-ons
      • BBC Micro:bit
      • BerryClip
      • Books
      • Camera Module
      • Cases
      • Events
      • General
      • Hardware
      • I2C
      • Infographics
      • Interfaces
      • Minecraft
      • Model A+
      • Model B+
      • News
      • Pi Models
      • Pi Pico
      • Pi Zero
      • Power
      • Programming
      • Python
      • Raspberry Pi OS
      • Raspbian
      • RetroGaming
      • Robotics
      • Sensors
      • Software
      • SPI
      • Tutorials & Help
      Tags
      3D Printing Arduino audio battery berryclip Birthday bluetooth cambridge camera CamJam DigiMakers display games GPIO I2C interface Kickstarter LCD LED Linux media Minecraft Model A Model B motionEyeOS PCB photography photos Pi-Lite portable power python Raspberry Jam Raspberry Pi Bootcamp raspbian Retrogaming retroPie screen SD card security sensor SPI temperature ultrasonic video
      Raspberry PI Related
      • Adafruit Blog
      • Average Maker
      • Official RaspBerry Pi Site
      • Raspberry Pi Pod
      • RasPi.tv
      • RaspTut
      • Stuff About Code
      Tech Resources
      • MattsBits – Pi Resources
      • Microbit Spy
      • Technology Spy
      Archives
      About

      Unofficial site devoted to the Raspberry Pi credit card sized computer offering tutorials, guides, resources,scripts and downloads. We hope to help everyone get the most out of their Pi by providing clear, simple articles on configuring, programming and operating it.

      Popular Posts
      September 19, 2014

      Top 5 Reasons The Raspberry Pi Sucks

      July 27, 2012

      16×2 LCD Module Control Using Python

      October 20, 2013

      Analogue Sensors On The Raspberry Pi Using An MCP3008

      Recent Posts
      July 26, 2022

      CrowPi L Raspberry Pi Laptop and Learning Platform

      June 30, 2022

      Pi Pico W Launched

      May 6, 2022

      Add Kodi to RetroPie Menu

      Facebook Twitter Instagram Pinterest YouTube RSS

      Entries RSS | Comments RSS

      This site is not associated with the official Raspberrypi.org site or the Raspberry Pi Foundation. Raspberry Pi is a trademark of the Raspberry Pi Foundation.

      Copyright © 2022 - All Rights Reserved - Matt Hawkins

      Type above and press Enter to search. Press Esc to cancel.