Cheap Ethernet on the Raspberry Pi (A+/Zero/all probably)

Hey all,
Been a while since my last post. I'm currently embarking on a one-year compulsory Youth Service program, which for academic purposes means I'm going to be serving my country (Nigeria) for one year by working in an organization. Its formally called the National Youth Service Corps (NYSC) and it begins with a three-week orientation course in the state one has been posted to. The orientation camp was really fun. Met some really amazing people..(I'm thinking of you as I write this, B...)
Shortly after the formal end of the orientation camp I returned home, and some time later I saw the announcement for the Raspberry Pi Zero (which for those who don't know is a single-board computer sporting an ARMv6/ARM11 SoC running at 1GHz with 512MB of RAM, no network options by default and one microUSB host port....for $5..yes, five US dollars). Naturally I was intrigued - I mean, its not exactly monster hardware, but the cost is certainly compelling. Sadly it was sold out either that day or the next day, so I'll probably not be able to lay my mitts on one till after the new year or thereabouts. However, the lack of networking options bugged me...I mean, we all love IoT gizmos and all, but at least wired Ethernet is like a basic necessity right? Obviously one could easily buy a USB Ethernet module or even a USB WiFi module and that'd be that. However, a good number of these things tend to be more expensive than $5, and using such a thing would eat up the one (micro)USB port on the Zero unless one got a USB hub, which would increase costs and possibly drive a person into depression...
So I wondered whether Ethernet could be provided over SPI the way the Arduino Ethernet Shield and modules do it...I mean, the BCM2835 SoC used on the Zero certainly has an SPI port, and there's a fair chance that it may not be in use. Initially I started with the Wiznet W5100 chip as this is the same chip used on the Arduino Ethernet shield, but I didn't really find much. One serendipitous morning, I stumbled across a StackExchange post asking the same question. One of the answers mentioned that the ENC28J60 from Microchip could infact be used for such a purpose. In fact, it had been done already. The ENC28J60 is a half-duplex (I think) Ethernet thingy operating at 10Mbps i.e Ethernet, not Fast Ethernet. However, for "IoT" projects, 10Mbps would be sufficient for a good number of use cases. More importantly, the ENC28J60 modules could be found for ridiculous prices on sites like AliExpress.
I then went ahead to obtain one of these modules from this retailer here in Nigeria at a thousand Naira (approximately $5) and received the module the next day. I'd also been wanting to test drive the new Raspberry Pi Jessie Lite image, which is a standard image with lots of cruft stripped out (I like my Pis lean and mean, you know what I'm sayin'?) so I got that too (the November 2015 version). Burning that to an 8GB SD card (technically the Lite image can fit on a 2GB SD card), I followed the steps from here. In summary:

1) I edited the config.txt file and added "dtoverlay=enc28j60,int_pin=25" to the end of the file (without the quotes)
2) Wired the module up using the pinout described on the page

I then slipped the SD card into a Raspi A+ (could've worked on any one really, but the others have Ethernet you could get a second Ethernet port on the cheap in theory), plugged an Ethernet cable in and powered it up. With bated breath, I looked at my router's DHCP Lease table....and Lo and Behold, the Raspberry Pi actually shows up!
The link provided earlier puts the speed of the thing at ~300Kbps max, but that's fine. I was actually able to SSH into the Pi and do some apt-get update'ing, which is okay for now. I haven't done any stress testing, but the link seems to work fine thus far (I've been pinging the module for over half an hour now, currently at 2377 packets, not a single loss) and it can be configured with the standard Linux utilities: ifconfig, etc. For some reason, I couldn't ping another address because I kept getting some weird error about socket creation not being permitted or something like that. Long story short, prepend your ping command with sudo and Bob's your uncle. Not sure whether this is particular to the ENC28J60 setup or its a Raspbian Jessie thing.
So if you have an A+ or a Zero, this is totally worth the effort. However, it seems that the module gets a different MAC address on every power cycle. Depending on your use case, this might not be ideal. I will look into solving the problem...

[Update (21st May 2018): the parent link (this one) now has a solution for this. Haven't tested it myself but it looks good]

Until then, I remain, your humble servant.



Popular posts from this blog

Enabling SPI1 on the Raspberry Pi B+/Zero/2/3

Bitbanging SPI on the Raspberry Pi (via spi-gpio)

Getting Started with Logic Analyzers and Pulseview