Saturday, August 21, 2010

An Arduino Compatible Web Server for £12

In the last 2 weeks I have been working towards making a very low cost Arduino compatible web server based on the ATmega328 interfaced to an ENC28J60 ethernet controller.

With a spare afternoon this weekend - I finally got around to finishing the wiring up of the breadboard and getting it running.

It's fairly standard stuff, having been done by Tuxgraphics, NuElectronics and others - but for me the attraction was the simplicity of the stripped down design and making something a lot cheaper than you can buy it - slowly eroding at the myth that there is anything complex or costly about the Arduino.

This combination usually costs about £40 if you buy an Arduino and a low cost ethernet shield from NuElectronics. So I decided to make my own and show that it could be done for considerably less. It is my intention to get down to having a web connected microcontroller for under £10 - but even as a prototype this can be done for about £12.

The board consists of just 3 ICs, the ATmega328, the ENC28J60 and a 74AHC125 quad buffer which acts as a 3.3V to 5V level converter. Additionally there are two crystals, 25MHz and 16MHz, two voltage regulators 3V3 and 5V and about 30 other passive Rs and Cs. The connection to the ethernet is done using the RJ45 "Magjack" breakout board from CoolComponents. This costs just £1.99. The ATmega328 and the ENC28J60 were also sourced from CoolComponents.

The webserver connects to my laptop using a FTDI USB to serial cable. This saves having to put an FTDI chip on the breadboard. The serial connection and the power is at the top right of the picture. The Magjack is at the top left. The 3V3 regulator to power the ENC28J60 is at the extreme lower left.

The next plan is to get these components onto a professionally made double sided pcb. It will be the same size as the Arduino, and share the same connector footprint - but using entirely through hole components, can be built by anyone who can solder.

This project is being done is association with the London Hackspace. With the introduction of a low cost ethernet enabled microcontroller board, many fun projects are possible, and the low cost and easy construction allows many more people to tinker with web connected hardware.

Andrew Lindsay has written code for a Pachube client to run on this combination of chips. With this you can read data from sensors such as temperature, humidity and light sensors and publish this data up on the Pachube site.

My Pachube feed features between 4 and 6 thermistors - measuring various temperatures around my house.

Making it.

With a little forethought, the stripped down version can be built on a single (63 row) breadboard.

Make sure you connect all the 5 Vdd pins and the 4 Vss pins of the ENC28J60 to 3V3 and 0V respectively. Fit a 100nF decoupling capacitor on each of the Vdd pins.

Both the 16MHz and 25MHz crystals can be loaded with 22pF capacitors. Fit the crystal and the capacitors right next to the pins of the ICs.

The Magjack breakout board makes it very easy to connect the ethernet. You need to fit pin headers onto the breakout board - except for the pins marked SH and SH2 (shield) and then it will plug neatly into the breadboard.

Keep the wiring to the ethernet magjack short and neat - we are expecting quite a lot from breadboard at the sort of frequencies used in ethernet. I used 51ohm 1% resistors for the ethernet termination circuitry. Most designs say 49.9 ohm 1%, but as long as you are close to 50 ohm it's not an issue.

The ATmega328 and 74AHC125 run off the 5V rail, but the ENC28J60 runs off 3V3. Make sure your 3V3 regulator is producing 3V3 before you make the final connection to the ENC28J60.

The purpose of the 74AHC125 is to convert the 3V3 levels output from the ENC28J60 up to 5V so that they are compatible with the 5V used by the ATmega328. The two lines that need buffering are /INT and MISO (master in slave out). The buffer used for MISO is enabled with the /CS line - this means that when the ENC28J60 is not selected, the MISO line is tristated by the buffer and available for use by any other SPI device. There are 2 spare buffers in the 74AHC125 package and they could be used for other purposes.

I splashed out and bought a ATmega328 which was already pre-programmed with the Arduino bootloader. Whilst you pay a significant premium for this, I wanted to make sure that my '328 would run Arduino code first, and was not the cause of any failure in the build. Subsequent '328s will be bought unprogrammed and blown with the bootloader code, using this neat AVRISP trick using an Arduino board.

I use an FTDI cable both to program and power this design. Note that the 5V supply form the FTDI cable is limited to around 70mA. The FTDI cable, whilst it offers a programmable output pin in the form of /RTS is not compatible with the Arduino programming which uses DSR to reset the ATmega328. Some changes would be needed to the programming code in the IDE to support this cable. In the meanwhile I just keep pushing the reset button until the IDE recognises the bootloader and begins the programming sequence.

Parts List

1 ATmega328 microcontroller (with preprogrammed Arduino bootloader) - CoolComponents £5.00 or £2.81 without bootloader
1 ENC28J60 ethernet controller - CoolComponents £1.99
1 Magjack breakout board - CoolComponents £1.99

The remainder of the parts came from Farnell Components:

1 74AHC125 quad buffer 174-9617
1 16MHz crystal 161-1761
1 25MHz crystal 161-1783
4 22pF ceramic capacitors 114-1760
10 100nF ceramic capacitors 121-6444
2 10nF ceramic capacitors 121-6435
2 10uF electrolytic capacitors 945-1056
1 7805 5V regulator 156-4483
1 78L33 3V3 regulator 146-7768
1 2K resistor 934-1480
4 51ohm 1% resistors 934-3342
2 270 ohm resistors 933-9353
3 10K resistors 933-9060
1 tact switch 181-3689

You will also need:

1 breadboard
1 FTDI USB-serial cable - becoming a standard bit of kit for talking to microcontrollers.


AndyL said...

Excellent write up. Do you have the schematic drawn up?
Did you use the 74AHC125 for the interrupt pin?I know its not used in the library, but having it there keeps it compatible and open to future use.

Ken Boak said...


The 74AHC125 buffers the /INT pin, and the other '125 solves the problem of the MISO line being held by the ENC28J60, and not released for other SPI devices to use the bus. I have the schematic in EagleCAD format which I will forward to you or post up somewhere.

Schamp said...

Excellent work.

I would also love to see the eagle schematic, and also the PCB layout, if you're willing to share that.

Ken Boak said...


I'm just finding somewhere sensible to post the EagleCAD schematic. Will get back to you - or email me directly for it at ken dot boak at gmail dot com


Carson said...

Two Questions:
What is Your Bandwidth?
Total memory For pages?

Anonymous said...

Hi, very cool project ! is it possible to get the code of the microcontroler ?
thanks in advance

olivier ( belgium)

Anonymous said...

Hi, very cool project ! is it possible to get the code of the microcontroler ?
thanks in advance

olivier ( belgium)