Вы находитесь на странице: 1из 32

Ethernet On Pi Zero How To Put An Ethernet Port On Your Pi RasPi.

TV

http://raspi.tv/2015/ethernet-on-pi-zero-how-to-put-an-ethernet-port-on-your-pi

21-11-2016 23.46.46
RasPi.TV RASPBERRY PI TUTORIALS, VIDEOS & REVIEWS

Home Site Map Downloads IC Raspberry Pi Linux Usage Python Prog. Input & Output Search

RasPi.TV Site Map - click here

Ethernet On Pi Zero How To Put An Ethernet Port On Your Pi


Dec

02
2015
Input and Output, interfacing, Raspberry Pi Hardware, Uncategorized Add comments Products Designed by Alex

RasPiO Duino - Combining Pi + Arduino +


The Pi Zero attracted a huge amount of attention, which is great for the educational mission of the Raspberry great learning materials
Pi Foundation. Whenever a new product is released, people air their opinions in the forums on what they would
have liked it to have.

One of the most common I wish it hads was an ethernet port. There are reasons why ethernet was not
included. The two most obvious ones are cost and board size (it would have almost doubled the size of the
Zero)

So Whats To Be Done If You Need Ethernet?


Well the obvious solution would be to buy a B model Pi. B+ is fairly inexpensive these days, but also the Pi2 B has ethernet.

The other option, that were going to cover today, is to add an external ethernet port using the SPI pins on the Pi. RasPiO GPIO Ruler with RPi.GPIO code
crib-sheet
Some time ago I managed to kill the ethernet/usb hub chip on one of my model B Pis. I thought it was a gonner. With no USB or ethernet,
the only way I could log into it was through the serial port. Then someone (I think it was Alex Bradbury) pointed out that you can add
ethernet over SPI. I looked into it. There was a forum thread about it, where people had done this, so I bought a little ethernet board for
Arduino. It has an ENC28J60 chip on it, an ethernet port, a 25 MHz crystal and some resistors and capacitors

ENC28J60 based ethernet board from DX.com

Mine came from DealExtreme and it cost around 3. You can still buy them here.

1
And Then It Sat In A Box
When it arrived I did a classic geek thing. I looked in the forum post again. It looked hard and a bit scary (nobody had RasPi.TVed the
procedure) and I had other stuff to do. So it sat on my desk for a while and eventually went in my box of Things Ill get around to using one
day perhaps. Its been in that box for a while now.

But Then Came The Zero


Provoked by the mass of I want an ethernet port on my Zero comments, I decided it was time to have a go. Fortunately, in the meantime,
a device-tree driver has been produced for this chip, which means there is no need to compile anything, mess about with the kernel or
even do very much at all. The procedure has been much simplified thanks to device-tree. (There I did it. I said something nice about
device-tree had to happen one day.)

It Took Me About Half An Hour


I rummaged in my box of Things Ill get around to using one day perhaps and found the ethernet board surprisingly quickly. As I had not
yet soldered a header to my Zero, I decided to try it on an A+ to start with to see if I could get it working.

I wired it up carefully, booted the Pi, tweaked a config.txt line, enabled SPI and rebooted.

And that was it. An ifconfig showed me I had an ethernet connection. It was almost boringly easy and took about half an hour. I
instantly soldered a header to my Zero and tried it on that. It worked perfectly. So I tweeted this terrible photo with two puns embedded at
no extra charge

So now youll want to know how to do it too.

How Do We Wire It? RasPiO PortsPlus Port ID for Pi2/B+/A+

Heres an annotated shot of the ethernet ports pin header so you can see which connections you need to make

2
How to wire your ethernet board to GPIO

This is what mine looks like Follow Me

Recent Posts

New Raspberry Pi 2B 1.2 with Pi3


BCM2837 Processor
get_iplayer on Raspberry Pi update
November 2016
Extending Python Vocab Tester With
Dictionary Lookups and Storage
How to Estimate Your Vocabulary Using
a Python Script and the Scrabble Word
List
Pixel Tips and Tweaks how to Tweak
Aspects of the new Raspbian Skin

Recent Comments

alex on New Raspberry Pi 2B 1.2 with


Pi3 BCM2837 Processor
Paul on New Raspberry Pi 2B 1.2 with
Pi3 BCM2837 Processor
sujit on How to use DropBox with

3
Raspberry Pi
sujit on How to use DropBox with
Raspberry Pi
sujit on How to use DropBox with
Raspberry Pi

Tweets by @RasPiTV
RasPi.TV
@RasPiTV

@JarJarGeek Just playing around with


cheap nanos and look what I found on
the same page as the drivers that
worked (Yosemite)...

2h

RasPi.TV
@RasPiTV
Embed
@RPi_Yaz14 Full length View
IMAX?onThat
Twitter
will
cook your brain ;p

All wired up and ready to go


Categories

As usual, I used one of my RasPiO Portsplus boards to make wiring easier on the Pis 40 pin header. You can find those here. Electronics
Gertboard
How Do We Configure It? get_iplayer
Input and Output
Ensure SPI Is Enabled
interfacing
Linux usage
Menu > Preferences > Raspberry Pi Configuration
Mailbag
Click the Interfaces tab
Product Launch
Ensure SPI is enabled and click OK
python programming
raspberry pi
If you changed anything, youll need to reboot for it to take effect.
Raspberry Pi Camera
Raspberry Pi Hardware
Tweak config.txt
raspberry pihardware
Add the following to your /boot/config.txt
RasPiO Duino

dtoverlay=enc28j60 Review

4
Then when you reboot, your ethernet port should just work. If you want to tweak the SPI clock speed or INT port you can use software installation

dtoverlay=enc28j60,int_pin=25,speed=12000000 and tweak those variables. The ethernet chip is specified at 20 MHz Uncategorized

maximum, so best avoid going above that.


Blogroll
Speed Testing Makersify

You can use a command line version of speedtest.net if you install it Oxford Raspberry Jam
Raspberry Pi Foundation

sudo apt-get install python-pip Raspberry Pi Spy

sudo easy_install speedtest-cli Raspberry PiPod


Robotics and Add-ons

Then run it with speedtest-cli See Adafruit Industries

Speed Test Results Archives

Pi Zero at 12 MHz 3.33 Mbaud down, 2.82 Mbaud up, 39.956 ms latency, 52.19km November 2016

Pi Zero at 16 MHz 3.67 Mbaud down, 2.90 Mbaud up, 37.749 ms latency, 43.57km October 2016

Pi Zero at 20 MHz 3.88 Mbaud down, 3.10 Mbaud up, 42.474 ms latency, 43.57km September 2016
August 2016

Pi2 with ethernet onboard 74 Mbaud down, 5.86 MBaud up July 2016
June 2016

What does that mean in real money? On my LAN, it took 3m 45s minutes to download an 85 MB file from Pi to Macbook Pro and 3m 18s May 2016

to upload it to the Pi Zero. So it isnt going to win any speed awards, and probably isnt good enough for streaming HD video. But for an April 2016

Internet of Things (IoT) device or for most purposes itll be enough. March 2016
February 2016

Its Not Supposed To Work January 2016


December 2015
Now Ive looked at the datasheet for the chip, Im surprised it works at all. November 2015
October 2015
According to that, page 80 states a power usage of 160 mA which is a lot more than the nominal 60 mA 3V3 rail limit on the Pi. It might September 2015
therefore be better practice to run it from a separate supply. Your mileage may vary. I hope you had fun. I certainly did. August 2015
July 2015
(Update to add) Sources close to RPi have told me unofficially that it will probably be fine to run this ethernet board on the 3V3 rail of the Pi
June 2015
Zero.
May 2015
April 2015
Share this: March 2015
February 2015
Tweet 292 Share 5 1 point
26 Email
January 2015
December 2014
Posted by alex at 10:17 am Tagged with: Ethernet on Raspberry Pi Zero, Raspberry Pi SPI ethernet November 2014
October 2014
81 Responses to Ethernet On Pi Zero How To Put An Ethernet Port On Your Pi
September 2014
August 2014

5
July 2014
1. Terry says:
June 2014
December 2, 2015 at 11:09 am
May 2014
April 2014
Alex Clever idea perhaps a 3.3v reg from the Zero 5V would be better. PCB smaller and cheaper on Ebay only 1.78
March 2014
http://www.ebay.co.uk/itm/Mini-ENC28J60-Ethernet-LAN-Network-Module-For-51-AVR-STM32-LPC-CF-/272037300936?
February 2014
hash=item3f56afcac8:g:7GsAAOSwQoFWOyxz
Sent Gordon a email as gpio readall not working on the Zero from the 1/11/15 Wiringpi release. he is looking into it. January 2014
December 2013
Keep up the good work
November 2013
Terry
October 2013
Reply September 2013
August 2013
alex says: July 2013
December 2, 2015 at 11:12 am June 2013
May 2013
Yes a reg from 5V is definitely a possible option. I havent actually measured the current draw on the ethernet board, so dont know if its April 2013
straining the Pi or not. But I put the warning there just so people dont cook their Pis and then blame me for it. :) March 2013
February 2013
Mine seems fairly stable so far.
January 2013
Reply December 2012
November 2012
October 2012
alanswindells72@googlemail.com says:
December 3, 2015 at 4:55 pm September 2012
August 2012
July 2012
and the same seller on ebay has 5 (five) suitable voltage converters for a princely sum of 1.10. I havent tried this yet but I shall.
June 2012
Reply

Meta
alex says:
Log in
December 3, 2015 at 9:07 pm
Entries RSS
Comments RSS
It looks like a reg wont be needed since it works well and Ive been told unofficially that it should be OK
WordPress.org
Reply

Stats since June 2012

blog posts: 259


2. Peter says:
word count: 169,051
December 2, 2015 at 2:26 pm

powerful

6
Reply

3. Terry says:
December 2, 2015 at 5:01 pm

Gordon has just updated WiringPi it now covers the PiZero on gpio readall command

Reply

4. ThreeDogs says:
December 2, 2015 at 5:27 pm

Nice one. I assume that one could use an USB Port (or the existing connect to a Hub
for expansion) and just add a WiFi Dongle?

7
Reply

AndrewS says:
December 2, 2015 at 7:34 pm

Of course, which is exactly what many people do.


Alternatively, if you want to stick to wired Ethernet but dont want to go the SPI route, you can also get USB-connected Ethernet port
dongles.

Your device-tree comments made me giggle Alex :)

Reply

alex says:
December 2, 2015 at 8:59 pm

Your device-tree comments made me giggle Alex :)

In that case they were fit-for-purpose and you are not getting a refund on them. :)

Reply

5. Chris Butcher says:


December 2, 2015 at 8:54 pm

I managed the initial setup on my Zero via a Usb Ethernet Dongle that I use with my Tablet. It all worked fine with no additional setup. Once all software
was installed I swapped to a wifi dongle. Love the compact size of the Zero, so many options.

Reply

6. viktordite says:
December 3, 2015 at 9:25 am

May your Speed Problem results in the wiring w/o twisting an shielding the wires?

8
Reply

AndrewS says:
December 3, 2015 at 12:32 pm

The way I understand it, Ethernet cables need the twisted-pairs and shielding (to prevent interference on the long cables they use). But the
wires between the Pi and ENC28J60 are using SPI, and hence (AFAIK) the twisting and shielding isnt needed. The ethernet only happens
after the ENC28J60 chip.
I think the Speed Problem is simply that SPI is a much slower bus (comparatively speaking) than USB.

Reply

AndrewS says:
December 3, 2015 at 12:40 pm

and a quick google search shows that the ENC28J60 is only a 10Mbps ethernet chip, whereas the LAN9514 used on the Pi2 is
a 100Mbps ethernet chip.

Reply

7. guest says:
December 7, 2015 at 11:22 am

Hello.

Did this external Ethernet work fine with RaspberryPi Model B?


On your scheme (How to wire your ethernet board to GPIO) 3.3 goto 3.3 but on your foto (All wired up and ready to go) red wired that connected to 3.3
goto GP22. What that means?

Thanks.

9
Reply

alex says:
December 7, 2015 at 1:06 pm

Havent tried it on a B.

Parallax error on the photo makes it look wrong, which is why you should always trust diagrams over photos.
Also trust your common-sense. 3.3 should go to 3.3. :)

Reply

guest says:
December 7, 2015 at 1:48 pm

Thank for your answer.

Based on forum discuss http://www.raspberrypi.org/forums/viewtopic.php?f=44&t=18397


plus your article (I have no IRQ on ENC, so I see where you connect GPIO25, and understand that IRQ is INT) I think that
connection will be next
ENC RPi
=======
VCC 3v3
GND GND
CS CE0 (gpio 8)
SI MOSI (gpio 10)
SCK SCKL (gpio 11)
SO MISO (gpio 9)
IRQ (INT) GPIO 25

Some think like that


[img]http://i.imgur.com/7eac1F9.jpg?1[/img]

By the way, this ENC28J60 different that yours, not only by date made.

10
Reply

alex says:
December 7, 2015 at 2:27 pm

That wiring schema looks OK to me. Are you saying it isnt working? As Andrew says, youll need a recent Raspbian
distro for that to work.

Reply

guest says:
December 7, 2015 at 3:21 pm

No, I didnt say that.

I even do not connect it, because personally have not even work with GPIO, so I make a consultation with
people who already do that.

With ENC28J60 I have 10 pin connector


http://i.imgur.com/B1DPt6W.jpg?1
so there is need an adapter for right connection, or got an individual wires like in case on photo in article.

My current distribution, regular updating by apt-get, is Linux raspberrypi 4.1.7+ #817 PREEMPT Sat Sep
19 15:25:36 BST 2015 armv6l,

so from OS only /boot/config.txt may require an update (add dtparam=spi=on and dtoverlay=enc28j60).

alex, AndrewS thanks for your answers.

Wayne Manion says:


December 21, 2015 at 9:29 pm

I used the pinout described here with my ten pin enc28j60 board, and it works great.

AndrewS says:
December 7, 2015 at 2:16 pm

I cant see any reason why it wouldnt work on a Model B (as long as youre using an up-to-date OS). With the obvious caveat that itll be
slower than the built-in Ethernet port.

Reply

8. hystrix says:

11
December 7, 2015 at 7:18 pm

Hi Alex,

Thanks for posting this. As you say, it just works. It only took a few minutes with your excellent instructions :-)

Reply

9. Florent says:
December 8, 2015 at 11:00 am

Hello,
Why dont use a LAN9514 chip on external board (in replacement ENC28J60) connect on mini-usb ? you can reconnect a new ethernet and more usb !
its stupid idea ?
C-Y

12
Reply

alex says:
December 8, 2015 at 1:35 pm

I used what I had. Perhaps someone else has a board with a LAN9514 on? WJDK.

Reply

AndrewS says:
December 8, 2015 at 1:54 pm

Not a stupid idea, but LAN9514 boards are a tiny bit more expensive than ENC28J60 boards ;-)
http://uk.farnell.com/microchip/evb9514/lan9512-enet-phy-eval-board/dp/2321379

Reply

Florent says:
December 8, 2015 at 3:29 pm

Maybe remake just a board with LAN9514:


http://fr.farnell.com/microchip/lan9514-jzx/ic-usb2-enet-cntrl-4-port-hub/dp/2292587
and the block schematic page3 Raspberry-Pi-Rev-2.1-Model-AB-Schematics.pdf

:)

Reply

AndrewS says:
December 8, 2015 at 5:25 pm

If you have the skills to do so, then go for it!

But I suspect for most people itll be easier to add a ready-made ENC28J60 board or a USB ethernet adaptor ;)
(Or just buying a Raspberry Pi B+ or Raspberry Pi 2 is another alternative of course!)

Reply

10. Tim says:


December 13, 2015 at 3:37 pm

Thank you for another very useful article. I believe this particular ENC28J60 module has a 3.3V regulator on board (underneath, perhaps marked
AMS1117-3.3). So, you should be able to power it through the 5V pin instead of the 3.3V pin, and sidestep the 3.3V current limit.

13
Reply

alex says:
December 13, 2015 at 3:48 pm

It does. Youre right. I havent tried 5V power though as I was unsure if it would then think the logic level was 5V too (not looked into it very
far)

Reply

Colin says:
January 29, 2016 at 3:05 pm

I can confirm that using the 5V pin to power via the built-in regulator seems to work fine, with no blue smoke release so far.

Reply

jogco says:
March 21, 2016 at 10:29 am

I have also tried this with 5V. I have a different board, also with a 3.3V regulator, but from looking at
http://www.microchip.com/wwwproducts/en/en022889, it seems the enc28j60 is 3.3V in supply and i/o, so it shouldnt
be a problem? I see no components to convert 3.3V signalling to 5V.

Reply

11. Wayne Manion says:


December 21, 2015 at 9:30 pm

I used these instructions with my Raspberry Pi Model A+. It works great except for one thing:

I assign IP addresses using a MAC ID to DHCP table on my router. The enc28j60 appears to use a different MAC ID every time the Pi reboots. How can
I specify a specific MAC ID to use every time?

Thanks

14
Reply

alex says:
December 21, 2015 at 9:33 pm

Ive noticed that happens too. I suppose you could force a static IP address. I know it can be done, but never having done it myself, I cant
tell you how.

Reply

AndrewS says:
December 22, 2015 at 2:53 am

I dont have an ENC28J60 myself, but I did a bit of digging

The enc28j60 MAC address is randomised at bootup, because just like the LAN9514 chip used on Pis with built-in Ethernet, the
MAC address needs to be programmed from an external EEPROM (see http://www.microchip.com/forums/m435924.aspx ). The
boards being used here obviously dont have an EEPROM, so you need to program the MAC address yourself (at runtime). On
the Pis with a LAN9512/LAN9514 chip (B, B+, Pi2) the MAC address is automatically calculated from the Pis serial number, and
the firmware adds a kernel command-line parameter (smsc95xx.macaddr=B8:27:EB:xx:yy:zz), which is read by a RPi-kernel-
specific module parameter (see https://github.com/raspberrypi/linux/commit/683a06a250e735c94ec3640d9288528ee50ddf16 ).

The ENC28J60 DeviceTree overlay (see https://github.com/raspberrypi/linux/blob/rpi-


4.1.y/arch/arm/boot/dts/overlays/README#L204 and https://github.com/raspberrypi/linux/blob/rpi-
4.1.y/arch/arm/boot/dts/overlays/enc28j60-overlay.dts ) doesnt seem to offer any way of setting the MAC address, but the actual
kernel driver itself does (see http://lxr.free-electrons.com/source/drivers/net/ethernet/microchip/enc28j60.c#L1537 ), so possibly
something like http://www.aboutlinux.info/2005/09/how-to-change-mac-address-of-your.html would do the trick? (which I guess
youd want to run from a startup script to ensure the same MAC at every bootup see e.g. http://www.raspberrypi-
spy.co.uk/2015/10/how-to-autorun-a-python-script-on-boot-using-systemd/ but ignore the Python bits)

Alternatively I guess you could try hacking something like


https://github.com/raspberrypi/linux/commit/683a06a250e735c94ec3640d9288528ee50ddf16 into
https://github.com/raspberrypi/linux/blob/rpi-4.1.y/drivers/net/ethernet/microchip/enc28j60.c , compiling your own kernel module,
and then adding a enc28j60.macaddr=aa:bb:cc:dd:ee:ff parameter to your /boot/cmdline.txt .

15
Reply

Wayne Manion says:


December 22, 2015 at 7:39 pm

Thanks for your help. I made a startup script with those commands, and the problem is solved!

Reply

AndrewS says:
December 22, 2015 at 11:14 pm

Yay! :-D

Arduino having11 Guy says:


January 21, 2016 at 8:14 pm

hahahahahah NERD!

Reply

AndrewS says:
January 21, 2016 at 8:47 pm

Thanks, I prefer the term geek myself :)

Richard says:
January 24, 2016 at 4:19 am

Here is a somewhat simpler way to assign a fixed MAC address at boot time:
1) Create the file /lib/systemd/system/setmac.service
Add the following contents:

[Unit]
Description=DSet the MAC address for the ENC28J60 enet adapter at eth0
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 00:00:00:00:00:00

16
ExecStart=/sbin/ip link set dev eth0 up

[Install]
WantedBy=multi-user.target

Change the MAC address to whatever you want. Be careful, the first byte must be 00
make the file mode 644

Execute the following two commands to enable the service


sudo systemctl daemon-reload
sudo systemctl enable myscript.service

Reboot.

Reply

paul says:
February 4, 2016 at 2:43 pm

Hi,

Ive tried running the script to set the MAC, no joy.


No matter how I try to run it, it always fails..

sudo systemctl enable setmac.service gives Job for setmac.service failed


sudo systemctl enable myscript.service gives Failed to execute operation: Invalid Argument

Id really like to have the lanport grab the same IP, but whatever I do, it keeps bed hopping!!

TIA,
Paul.

BG says:
February 4, 2016 at 7:43 pm

I dont know about the ethernet address but I set a static IP address for my zeroPi running Jessie as
follows. Of course add your own ip addresses but note the /24 after the static ip address (but I dont know
why just cribbed from others on various forums)

For static IP on an ethernet connection:


sudo nano /etc/dhcpcd.conf

Then type in the following lines into the file:

#for wired:
interface eth0
static ip_address=10.0.1.181/24
static routers=10.0.1.1
static domain_name_servers=10.0.1.1

17
#for wireless:
interface wlan0
static ip_address=10.0.1.171/24
static routers=10.0.1.1
static domain_name_servers=10.0.1.1

then do a sudo reboot to take effect.

This may not be what you are after, but I hope it helps and it works for me.

paul says:
February 4, 2016 at 8:04 pm

Ta for the info


Its the MAC I need to be static, as I use DHCP with strict bind MAC reservations for my outside facing kit..
Ive set a static IP as shown, and it appears to work.. Only time will tell if the Pi Zero and the cheapo
adapter will work as I need them to, or do I just bung in a B+?

Thanks for the info!! :-D

AndrewS says:
February 4, 2016 at 8:40 pm

https://github.com/raspberrypilearning/networking-lessons/blob/master/lesson-1/rpi-static-ip-address.md
shows the more usual way to set a static IP address.

And since you seemed curious, the /24 on the end of the IP address is an alternative way of specifying the
255.255.255.0 netmask, as it signifies the first 24 bits (out of 32) in the netmask are 1.
https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing
But be careful, because different config files may expect the info provided in different formats.

BG says:
February 4, 2016 at 9:12 pm

Hi Andrew, thanks for the info. Editing the /etc/network/interfaces file for a static ip as per your link was
what I did when using wheezy but my new zero pi came with Jessie and the interfaces file says:
# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and man dhcpcd.conf
so hence I edited the dhcpcd.conf file. Actually I can remember exactly what was in the wheezy pi
interfaces file as Ive moved all on the Jessie. But mybe Im doing it all wrong??

AndrewS says:
February 4, 2016 at 10:03 pm

18
Oooh, I didnt know that, I always just rely on dynamic addressing! Ill have to do a bit of experimentation at
some stage, and perhaps the Raspberry Pi Learning Resource needs updating?

Richard says:
February 5, 2016 at 5:01 am

Paul wrote:
>sudo systemctl enable setmac.service gives Job for setmac.service failed
>sudo systemctl enable myscript.service gives Failed to execute operation: Invalid Argument

Yes. It looks like I had a typo. The command should be sudo systemctl enable setmac.service However,
the error you noted for that command you entered would seem to indicate there is a typo in the
setmac.service description. Check /var/log/messages to see if there is any more detailed information.

12. samano says:


December 23, 2015 at 5:11 am

How about Real time clock , How can I add ?

Please tell me.

19
Reply

alex says:
December 23, 2015 at 10:07 am

Its not something Ive yet tried, but I think Matt Hawkins blogged it over at raspberry pi spy

Reply

AndrewS says:
December 23, 2015 at 10:49 am

The 40-pin GPIO header on the Pi Zero is the same as the GPIO header on the Pi B+, so any of the usual Raspberry Pi RTC addons will be
fully compatible
https://www.google.co.uk/#q=raspberry+pi+rtc

Reply

13. BG says:
January 14, 2016 at 5:31 pm

Thanks for the info, I now have an ethernet running on my zeroPi. What Im not sure about, being a noob, is if the pins used for the ethernet can also be
used for other purposes at the same time. In particular can I use the Dunino board at the same time? Sorry for a dum question.

20
Reply

alex says:
January 14, 2016 at 7:15 pm

Unfortunately the Duino uses the SPI pins for its programming, so no I dont think you can use them both at once unless there is a way to
tweak the chip select on the ethernet driver to use GPIO7(CE1), as its hard-wired on the Duino.

Reply

AndrewS says:
January 14, 2016 at 7:51 pm

I suspect theres probably a way to configure which SPI chip-select gets used for which driver by doing something with the
DeviceTree stuff ( https://www.raspberrypi.org/documentation/configuration/device-tree.md ), but not being familiar with
DeviceTree myself (nor having an ENC28J60), I wouldnt know where to begin. Best bet is probably asking on the Raspberry Pi
forums http://www.raspberrypi.org/forums/

If you do find a solution, keep us updated :-)

21
Reply

BG says:
January 14, 2016 at 10:58 pm

Just maybe something here http://discohat.com/miscap/ not sure thought. (Ive got one of these boards from a
knowledgeable Mr Karri, but found my ENC28J60 board was different to the one required for this board though I did
have the same as the one as in this rpi-tv article).

This board comes with dip switches and appears to allow for 2 alternative pin selection for the ethernet board. One

with pins 8,9,10,11,25 and one using pins 18,19,20,21,17. However I may have misunderstood this entirely as this is
my first foray into electronics. Theres a nice electronic schematic on the site which you may understand.

However, whatever pins are used I expect they may interfere with the Duino board. I was thinking a combination of the
ZeroPi and Duino would be an excellent choice to create some smallish sensor nodes. A Pi in each node may be a bit
OTT, but at 4 a pop, why not. I would need network comms, preferably wired hence my interest in getting wired
ethernet to work, but wireless may suffice I will experiment some more.

Thanks to all.

22
Reply

AndrewS says:
January 15, 2016 at 1:17 am

A few different bits of terminology, which can be confusing to a beginner, so Ill try to take things slowly
(without sounding patronising!)

When you use an SPI bus (with the Raspberry Pi being the master device), its possible to hook up
multiple slave devices to the same MOSI, MISO and CLK pins, as long as each slave device uses a
different CS (ChipSelect) pin. The Raspberry Pi then uses the CS lines to tell all the connected slave
devices which one is currently active (any inactive slave devices ignore the signals on the SPI bus).
https://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus#Independent_slave_configuration
On the Raspberry Pi, the SPI0 bus (which is available on both the 26-pin-header Model A/B Pis and 40-
pin-header Model A+/B+/2B/Zero Pis) has two CS pins labelled CE0 and CE1. In earlier comments, myself
and Alex were referring to connecting both the Duino and ENC28J60 to this SPI0 bus, with the Duino using
CE0 and the ENC28J60 using CE1. (although having just looked at the Duino manual, Im not sure if it
actually uses either of the CE lines?)

However on the 40-pin-header Model A+/B+/2/Zero Pis theres *also* an additional (separate) SPI1 bus
available, which has 3 ChipSelect pins (see http://elinux.org/RPi_BCM2835_GPIOs for full details). The
approach taken by the miscap board seems to be manually switching the ENC28J60 between SPI0 and
SPI1 (using the CE0 of each), rather than switching the CS/CE of the SPI0 bus; and you did indeed read
the schematic correctly (although strictly-speaking its more correct to call them *GPIOs* 8,9,10,11,25 and
*GPIOs* 18,19,20,21,17, rather than the (physical) pins that you referred to). It seems a bit short-sighted
for the miscap board to assume a particular ENC28J60 header pinout :-/ The http://rasp.io/duino/ is
designed to work with the first 26-pins of the GPIO header only (so that it works with all flavours of Pi), and
so the pins needed for SPI1 are still free :-)
**However** (and I may well be wrong here, as I havent been following things very closely) AFAIK theres
not yet a native Linux driver available for the SPI1 bus on the Raspberry Pi? Google doesnt turn up much
either https://www.google.co.uk/search?q=Raspberry+Pi+SPI1 only hinting that theres a 3rd-party library
that supports it (which I guess wouldnt work with the ENC28J60 driver?). Although to fill in the gaps in my
knowledge, Id be very interested to hear if Karri did get the miscap working with SPI1.
(And just for SPI-completion, theres also a SPI2 bus with 3 ChipSelects which is only accessible on the
Compute Module, which again doesnt have a driver yet AFAIK.)

Alternatively, you could look at using a wired USB Ethernet interface, as I mentioned in earlier comments.
Or, if youre not going to be re-programming the Duino at the same time as using Ethernet (which I assume
will be the case for sensor nodes), you could program the Duino with the Ethernet disconnected, then
move the programming pins on the Duino, and then connect the ENC28J60 to the (now unused) SPI0 pins
as usual.

And the final option would be to bypass the Pi, and just connect the ENC28J60 directly to the Duino
running in standalone mode.

Lots of different possibilities, which is part of what makes hacking so fun! :-)

alex says:
January 15, 2016 at 7:26 am

23
From memory Andrew, CE0 is hard wired to the reset pin on the atmega and also pulled up via a 10k
resistor. Although the protocol is bit banged, the correct pins were used that it could be native spi as well.

BG says:
January 15, 2016 at 8:36 am

Thanks to AndrewS for the detailed info which is very helpful for a beginner, much appreciated. Lots of
different possibilities indeed. :-)

AndrewS says:
January 15, 2016 at 11:07 am

Just out of curiosity Alex, is the schematic for RaspioDuino available anywhere?
If the CE0 of SPI0 is connected to the reset pin on the atmega, then I suspect you couldnt use two devices
on the SPI0 bus, because whenever the Pi switched which slave-device it was talking to, then the atmega
would get reset? Which may or may not be a problem, depending on what your duino sketch actually does
;-)

alex says:
January 15, 2016 at 1:03 pm

Im afraid there is no schematic because I laid out the board in PCB mode directly. The pullup would
prevent that though wouldnt it? (Im not sure about that or the exact protocol details of SPI).

14. Marcel Hecko says:


February 1, 2016 at 5:06 pm

A project has been lauched on Kickstarter that uses this Ethernet chip to add ethernet to Raspberry PI zero:
https://www.kickstarter.com/projects/755102253/pijack-add-ethernet-to-raspberry-pi-zero

24
Reply

AndrewS says:
February 2, 2016 at 12:20 pm

Nice, but its a shame it doesnt include the HAT-style eeprom for that price. If I plugged it onto a B+, and did the config.txt edit, would I then
automatically get eth0 and eth1?

Reply

AndrewS says:
February 2, 2016 at 12:28 pm

Hmmm, given that the RaspberryPi has two ChipSelect lines on its default SPI interface, thats now got me wondering if itd be
possible to hook up two of the ENC28J60 breakout modules Alex uses in the original article, to get eth0, eth1 *and* eth2 on a B+
or Pi2? ;-)

Reply

alex says:
February 2, 2016 at 7:02 pm

Theres only one way to find out. Ive only got one myself.

Reply

15. eozoresduardo says:


May 26, 2016 at 11:10 am

any idea to plug TWO ethernet, at the same time?

Reply

16. ahmedkousta says:


June 7, 2016 at 1:59 pm

Thanks brother very helpful, works greet

Reply

17. ben says:


June 30, 2016 at 5:27 pm

25
Is there a list of network chips this procedure should work for?

For example, I understand linux implements a full tcp/ip stack, but the driver for the actual ethernet hardware must be developed and somehow
configured to hook into what linux expects?

Im using a Lantronix ethernet solution, that communicates via a uart (ttl rs232), what would be the general steps involved in getting this to work with
linux?

Reply

AndrewS says:
June 30, 2016 at 11:01 pm

Can you provide the exact model number of the device youre trying to use? I had a poke around on the Lantronix website, and it seems like
they sell serial communication encapsulated over an ethernet connection modules, rather than ethernet networking via a serial connection
modules. I.e. the uart device that the lantronix module is talking to thinks its directly connected to another computer via a null-modem cable,
so in fact theres no special driver-software that needs to be written. But its only a point-to-point null-modem-like connection, and cant be
used to add full networking capabilities. (unless you wanted to start mucking about with PPP)

I guess itd be a bit like SSHing from your PC into a Pi B+, and then using minicom to talk to a PiZero connected to the B+s UART. The
PiZero only sees the UART connection, it doesnt suddenly become network-enabled, even though its indirectly communicating with your
PC over an ethernet connection.

Reply

18. Graham says:


July 11, 2016 at 8:17 pm

Plenty of old RTL8139 PCI NIC cards kicking about. Should be possible to pick off the power and IO s from the edge connector, all of which are utterly
standard? With a Zero costing a mere 4, its not smart to shell out another 3 for another commercial dongle to add an ethernet port? Just need to
know the interconnects. Anyone able to help please?

Reply

AndrewS says:
July 11, 2016 at 11:03 pm

Thats far more effort than its worth. And even if you *did* have a software driver to bit-bang a PCI bus over GPIO pins (I dunno if such a
thing is even possible), the PCI bus is 32-bit (along with interrupt pins etc.), whereas there are only 28 GPIO pins available on the RPis 40-
pin header.
http://pinouts.ru/Slots/PCI_pinout.shtml
http://pinout.xyz/

Reply

19. Matt Lowe says:

26
July 28, 2016 at 2:53 pm

Hi,
First off, thanks, great article, just what i needed :)

Do you know if you can add 2 of these to a PiZero at once? could you use the 2 chip enable pins, one connected to each module? If so does anyone
know how to get the Pi to recognise each module? Would love to be able to place a PiZero with 2 ethernet ports connected to it, into a VERY small
case.

thanks again for a great article

Matt

Reply

AndrewS says:
July 28, 2016 at 4:49 pm

It might be possible to do that by messing about with some of the DeviceTree stuff, but I dunno how to do that myself. My earlier comment
might have some useful links http://raspi.tv/2015/ethernet-on-pi-zero-how-to-put-an-ethernet-port-on-your-pi#comment-60275

Reply

20. Tobias Matt says:


July 29, 2016 at 9:22 pm

Thank you sooo much for this, works like a charm.


Perfect for integrating a Pi Zero as printserver directly into my printer.

27
Reply

Dave C says:
October 27, 2016 at 5:46 am

Tobias,
Please give a few more details. Surely theres much sw work to do? As in drivers? Will a printer driver that happily prints to a USB printer,
just as easily find it and send jobs to it once its networked via Alexs creative hack?

I have visions of taking my very capable USB flatbed scanner and doing the same. But I balk, thinking of drivers that expect a USB scanner.

Id like to hear all about your success.

Dave

Reply

Dave C says:
October 27, 2016 at 6:48 am

This discusses the details of sharing a printer and scanner connected via Alexs creative hack:

http://www.raspberry-pi-geek.com/Archive/2013/01/Converting-the-Raspberry-Pi-to-a-wireless-print-server/(offset)/4

More reading to do

Dave

Reply

AndrewS says:
October 31, 2016 at 10:45 am

Yeah, thats looking at using standard printing and scanning network protocols (CUPS, etc.), and is probably your
easiest option https://en.wikipedia.org/wiki/CUPS

But if you want pure USB over network (which in theory might allow you to use features not directly supported by
CUPS) you could have a look at http://usbip.sourceforge.net/ although its something Ive never looked into myself. Or
https://www.raspberrypi.org/forums/viewtopic.php?f=36&t=36851

Reply

21. Alan Walker says:


August 24, 2016 at 3:05 pm

28
Hello, I just bought one of these, it has the same part number, but two less pins. The download speed is okay, but when I upload, I get a kernel panick.
The pins are labelled slightly differently as well.

Mine has CLC, WOL, SI, CS 3v3, NT, SO, SCT, RST and GND. I used SI for ST, SCK for SCR, NT for LNT.

Any tips would be welcome :)

Reply

AndrewS says:
August 25, 2016 at 11:23 pm

Sounds like that might be a question for https://github.com/raspberrypi/linux/issues


If the downloading works then the SPI protocol between the Pi and the ethernet chip is obviously working okay, so perhaps youre getting a
kernel panic because your board has a slightly different revision of the ethernet chip?

Reply

AndrewS says:
August 26, 2016 at 10:19 am

Oooh, just spotted this: https://github.com/raspberrypi/linux/issues/1385

Looks like the kernel panic might be fixed if you do an rpi-update to get the latest bleeding-edge kernel :-)

Reply

Ajwxp2k7 says:
August 26, 2016 at 9:07 pm

Oh yes :) I had to use a USB Nic to do the update (I did sudo apt-get upgrade, sudo apt-get update, then sudo rpi-update) and
the little board works like a charm. I get 4Mb/s down and 3Mb/s up (on a normal PC I would get 50Mb/s down and 18Mb/s up)

The reason I wanted to use this was mainly because cheap USB/NICs seem to drop out a lot, and expensive ones work but
anything that costs 3x the pi zero is a bit pointless. Now I also have a free USB port.

Nice work chaps.

Reply

22. Conundrum1885 says:


September 7, 2016 at 11:56 am

Found another use for this, reflashing hosed BIOS chips on laptops after a mishap involving a required update that didnt check battery state before
flashing (standby=dead BIOS). In fact this could probably be done in-circuit and include a facility to read back the old (dead) chips binary image to see
what broke.

29
Interestingly on some laptops it still responds to pings on the NIC in 10 base T mode so perhaps the problem is recoverable with some The Martian
level binary hacking?

Reply

23. Ross Potts says:


November 8, 2016 at 10:29 pm

Very interesting. I have a project starting up where I just want to see how many I can run from a single ATX psu. Given that there are a good number of
Amps available at 3v3, 5v, and 12v, and the fact that I dont have an oscope to measure for myself, what could I expect a zero to draw in total using
OTG to power and communicate with the head node of a cluster? I understand there is a 128 USB node (including the hubs) limit due to USB specs. I
am planning to power the hubs and zeros separately, and just use them for the comms portion.

I dont need arguments about how serious power cant be gotten using a zero-node cluster, I just need to find out what a zero will generally draw at 3v3
and 5v on an OTG connection.

Anybody know?

30
Reply

AndrewS says:
November 9, 2016 at 1:30 am

All models of Pi are only powered by 5V, theres no 3V3 input. The power consumption is probably very similar to
http://raspi.tv/2015/raspberry-pi-zero-power-measurements

Reply

Leave a Reply

Enter your comment here...

Raspberry Pi Zero Updated Pi Family Photo RasPiO Pro Hat Putting Pi Ports in Perfect Positions for Productive Play

2012-16 RasPi.TV Site Map | Reviews Policy Suffusion theme by Sayontan Sinha

31

Вам также может понравиться