This is only a preview of the November 2009 issue of Silicon Chip. You can view 34 of the 112 pages in the full issue, including the advertisments. For full access, purchase the issue for $10.00 or subscribe for access to the latest issues. Items relevant to "WIB: Web Server In A Box, Pt.1":
Items relevant to "Twin-Engine Speed Match Indicator For Boats":
Items relevant to "High-Quality Stereo Digital-To-Analog Converter, Pt.3":
Items relevant to "GPS Synchronisation For Clocks With Sweep Hands":
Articles in this series:
Purchase a printed copy of this issue for $10.00. |
Monitor & log up to four analog inputs & control four digital
outputs from a remote location using a web browser
Web
We’re very excited about this project. It will let you house your own
website with possibly hundreds or even thousands of pages, all in a little
box connected to the internet via your modem/router. You don’t need a
computer to operate and house a website – this little box does it for you
and it can be accessed from anywhere around the world, at any time, even
from a mobile phone which has a web browser. In fact, it is a complete
web server in a box – so we’ve called it WIB (Web server In a Box).
E
VERYONE KNOWS THAT web
servers normally involve big,
expensive, powerful computers with
large memory, large hard disks and
exotic software, don’t they? Well, that
is the normal approach but now it
doesn’t have to be. In fact, you don’t
24 Silicon Chip
even need a computer!
WIB can do it all. Even better, it does
not have a hard disk, uses practically
no power and costs not much at all.
WIB is just a small PC board (singlesided, no less) with a microcontroller,
an SD/MMC card reader and not much
else. In fact, it involves a total of just
three ICs and a 3-terminal regulator.
Why have a memory card? This is
the “Eureka!” feature: SD/MMC cards
are used in the majority of digital cameras and they can pack a huge amount
of memory for very little cash; we’ve
siliconchip.com.au
Pt.1: By MAURO GRASSI
WI B
Server I n a Box
seen them for as little as $8 for four
gigs and going down all the time! So
for not a lot more money WIB can use
an SD/MMC memory card which can
be 16 or even 32 gigabytes and that
means it can store many thousands
of pages of data, pictures or whatever
and all of these can be accessed as a
website via the internet.
Want to change the content? Well
you could upload new data remotely
via the internet or you could simply
whip out the SD card, plug it into your
computer and away you go. Or you
could have several such SD cards, all
with different web formats, presentations or whatever.
Maybe you would like to have a
large picture library or whatever, accessible via the internet. Of course,
siliconchip.com.au
you could take the conventional web
server approach, as outlined above. Or
you could do it with our WIB.
In fact, the applications are unlimited. Think of an application involving
a website and WIB can probably do
it. For example, do you have a small
business, perhaps selling goods via
the Internet? Maybe WIB could house
your website. We’re sure there a lots of
applications that have just been waiting for this simple hardware solution.
It only requires a modem or a modem/router to connect it to the internet. And while it and the modem will
need to be hooked up permanently,
its energy use rates as flea power
compared to a desktop computer or
even a laptop when permanently
powered up.
Furthermore, WIB can monitor the
temperature or any other parameter
(just connect a suitable sensor) and it
can also be used to control four digital
outputs and an RS232 serial port.
Down to earth
OK, we’ll come clean. While we
are very excited about this project, it
didn’t start out with such ambitious
targets. The original intention was to
produce a simple project which could
monitor temperature or any other
parameter in a home or remote location and display the resultant data on
a website. At the same time it could
control a few outputs – perhaps switch
on a heater or air-conditioner or a few
other prosaic functions.
But then we had the idea of using
November 2009 25
Fig.1: WIB’s home page lets you configure the various functions, including the
network, logging, email and FTP settings. It also allows you to read the analog
inputs (it’s showing a temperature reading of 27.45°C here) and toggle the digital
outputs. You can also send data strings to the serial port.
an SD/MMC memory card to store the
data and website. And it just grew from
there. Having thought of the memory
card as the bulk memory for the project
and realising just how cheap it was,
the potential uses seemed to grow
enormously. We are sure readers will
come up with a host of different uses.
Let’s also be realistic. We need to
describe how this WIB project works,
how it connects to the internet and
all the necessary know-how that this
requires. There is a lot of jargon to be
digested and understood but when
we have finished describing WIB in
considerable detail, we are sure that
you will see the potential.
WIB presents a great learning opportunity for anyone interested in
creating a personal website – it will be
great for schools, too. For example, it
could possibly be teamed up with our
popular Seismograph project (SILICON
CHIP, September 2005) or a weather
station. Students would be able to access it at any time via a mobile phone
with a web browser.
WIB is not the complete server
solution – it lacks some features like
server side scripting and encryption,
for example, althought for most applications, this won’t be a problem.
Its main advantage is that it is considerably simpler, cheaper and easier
26 Silicon Chip
to set-up than a more powerful web
server. In fact, if you have already gone
through the set-up procedure for connecting a broadband modem to your
computer, this project should not be
any more challenging.
Remote monitoring
In most basic applications, WIB lets
you monitor up to four analog inputs
and control up to four digital outputs,
as well as an RS-232 serial port.
WIB not only features an inbuilt web
server but includes inbuilt FTP and an
email (SMTP) client as well. We will
explain these terms as we go through.
The email client is used by the WIB
to send emails to a nominated email
address via an email server. Most ISPs
(Internet Service Providers) provide
an outgoing email server that the WIB
can connect to, in order to send email.
The FTP (file transfer protocol) serv
er allows you to store and retrieve files
from a remote location and also allows
you to manage your website remotely.
In addition, you can use it to back-up
files off-site or transfer files (both text
and images) to a remote location (eg,
from the office to home).
The memory card can actually be an
MMC, SD or SDHC card (up to 32GB).
The website can include dynamic
content that’s constantly updated with
data from the four analog inputs and
WIB can perform data logging of the
inputs (as in a weather station) and
save this information to a file. The
logged data can then be accessed either
via the inbuilt FTP (file transfer protocol) server or it can be automatically
emailed to you at regular intervals. Just
think – you will get emails from WIB –
mind-boggling! The emails will be sent
from the SMTP ( Simple Mail Transfer
Protocol) client within the WIB.
In practice, you can set the logging
period (ie, how frequently the values
are logged) and how many entries to
keep in the log file. When this number
is exceeded, the log file is automatically emailed to you and then cleared,
ready for the next cycle. In this way,
you could have daily reports of fluctuations in temperature or whatever
emailed to your inbox.
The WIB also allows a limit to be
set on a variable being monitored
and can notify you via email when
the variable exceeds this limit. For
example, you can set it to email you
if the temperature rises above a preset
level, so that you immediately know
there is a problem.
Digital outputs
As stated earlier, you can also control four digital outputs and the serial
RS-232 port using your browser (eg,
Internet Explorer, Mozilla Firefox, Opera, Safari, Google Chrome, etc). These
outputs can then be used to control
external devices, either directly or via
an interface board.
It’s just a matter of toggling the digital outputs high or low by clicking on
the “Toggle” buttons – see Fig.1.
Network time
Another feature of WIB is an SNTP
(Simple Network Time Protocol) client, which allows the correct time to
be gathered automatically from the
Internet. This time is used for logging
purposes and can also be displayed in
a dynamic web page.
A dynamic DNS (Domain Name System) client is also included. Domain
Name refers to any website name (such
as siliconchip.com.au). DNS enables
the unit to keep track of its public IP
(Internet Protocol) address and notify
a DDNS (Dynamic Domain Name System) service if this address changes. By
using this service, you can log into the
web server using a domain name rather
than its IP address (an IP address is
siliconchip.com.au
numerical and all devices connected
to the internet, such as your modem,
have an IP address).
This is necessary as the public IP
address can change if your modem is
turned off for some time, so you might
not always know what it is.
•
Highly customisable. Most settings including IP address, port numbers and
servers can be arbitrarily set.
•
MMC/SD/SDHC memory card for storage of web pages and other files (FAT/
FAT32 file system).
Earlier design
•
HTTP (web) server with changeable file permissions, dynamic pages, modified
CGI commands and HTTP basic authentication.
•
•
•
•
•
SMTP (email) client for automatic email notifications with dynamic content.
•
•
Four digital outputs for controlling devices over the Internet.
•
•
A serial port output that’s controllable via the Internet.
This is not the first web server project to be published in SILICON CHIP.
An earlier project, the PICAXE Net
Server, was published in the October
2006 issue and was based on a common Realtek ethernet controller chip
and a PIC microcontroller. It came as
a pre-built module and stored its web
pages in an onboard EEPROM chip.
Because the data was stored in an
EEPROM, the website was limited
to 64 kilobytes. Even so, it did allow
you to monitor several analog inputs
remotely using dynamic web pages
and had configurable I/O pins, including a PWM (pulse width modulation)
output.
By contrast, our new design can
store much more complex web pages.
Another advantage of the new design is that it implements simple file
permissions through HTTP (Hypertext
Transfer Protocol) authentication. This
means that you can set a user name and
password to access the whole website
or just certain pages. You can also restrict access to certain files, based on
the file extensions. The earlier design
lacked a method of restricting access
to its web pages and so its onboard
website was completely open to the
public.
Finally, the WIB is highly configurable and can be set up to work with
almost any ethernet network. Did we
mention ethernet? This refers to the
ethernet cable and connectors on the
back of your modem. Ethernet is a
standard which is used to transmit
data over a local network (eg, in an
office) or to the internet via a modem.
We will also be providing the source
code for a website so that you can easily modify the web server’s settings if
necessary, to suit your requirements.
Circuit details
Refer now to Fig.2 for the complete
circuit details of the WIB. It’s based on
a dsPIC33FJ64GP802 microcontroller
(IC1) and an ENC28J60 ethernet controller (IC2), both from Microchip.
The ethernet controller (IC2) provides the ethernet link, including
siliconchip.com.au
Main Features
FTP (file transfer protocol) server for uploading web site.
Dynamic DNS client (DDNS) to allow server to be contacted using a hostname.
Network time (SNTP) client to gather Internet time for logging, etc.
Four analog inputs. These can be: (a) monitored remotely using a web
browser; (b) logged with periodic log files automatically emailed to a chosen
email address; (c) assigned set limits, with automatic email notification when
limits are exceeded.
12 user defined file extensions, file permissions and file content for the HTTP
server.
System logging of special events.
MAC (Media Access Control) and the
10BaseT PHY (this means it runs at
10Mbits/second). It has 8KB transmit
and receive dual port RAM buffers,
hardware assisted CRC (Cyclic Redundancy Check – for error checking),
automatic retransmit on collision (in
case messages “collide”) and programmable packet (blocks of data) filtering.
Although Microchip makes microcontrollers with in-built ethernet
controllers, these are only available
as surface-mount devices (SMDs). We
wanted to avoid SMDs as far as possible so we have specified an external
controller (IC2) which comes in a
conventional DIL package, as does the
specified PIC microcontroller (IC1).
The only SMD chip used in the
whole project is the 8-pin MAC address chip (IC3) which comes in an
SOIC package. And while IC2 does
include Media Access Control (MAC),
we still need IC3 for providing the
unique MAC address; more on this
below.
In operation, the microcontroller
(IC1) communicates with the ethernet
controller via an SPI (Serial Peripheral
Interface) bus. This SPI bus is also
shared with the MAC address chip
(IC3) and the memory card, which is
accessed in SPI mode.
SPI communication requires four
lines and these are: CS-bar (chip select
– active low), SO (serial data output),
SI (serial data input) and SCK (serial
clock). You can share the bus among
multiple devices by having multiple
CS-bar lines and ensuring that only
one of these lines is active at any one
time.
In this case, we use three CS-bar
lines: one for the ethernet controller
(RB8 of IC1), one for the memory card
(RB2 of IC1) and one for the MAC address chip (RB6 of IC1). These are all
controlled by the SPI master (IC1).
MAC address chip
The 25AA02E48 MAC address chip
is a 256-byte EEPROM with an SPI interface. It’s main feature is that its last
six bytes (bytes with addresses 0xFA
to 0xFF) contain a unique, licensed
MAC (Media Access Control) address.
An ethernet device must have a
unique MAC address in order to communicate in a network. By using this
chip, we are ensuring that the MAC
address for the web server is globally
unique. These chips are intended for
use in designs with small production
runs and save on the cost of licensing
a range of MAC addresses from the
relevant authority (IEEE).
Note that it is quite possible to
overwrite the pre-programmed MAC
November 2009 27
Reading & Writing Data To
The Memory Card
T
O TRANSFER files from a PC to
the memory card, you may need a
low-cost SD/SDHC/MMC-card reader.
The one shown at left is available from
Jaycar for less than $10 (Cat No: XC4756), while the unit at right reads all
sorts of memory cards and is also
address (it is an EEPROM chip after
all). However, the chip has a write
protect feature that can be enabled
on a 64-byte block basis and the last
such block, which contains the MAC
address, is protected by default.
In any case, the current version of
the firmware does not write to the
EEPROM and only reads from it. Pin
3 (WP-bar) is the write protect pin and
this prevents writing to the EEPROM
when low. In our case, however, it has
been tied high to allow it to be written
to if there is a future firmware upgrade.
Pin 7 (HLD-bar) is the hold pin and
this pauses the SPI interface logic
inside IC3 if it is low. This feature is
used in SPI bus sharing situations but
has been disabled here by tying pin 7
high. Instead, we rely on the firmware
in IC1 to provide proper arbitration
between the three SPI devices.
Ethernet controller
The ethernet controller chip (IC2)
provides the physical and data link
layer of the network. As already mentioned, it is a 10BaseT PHY (physical
layer) running at 10Mbits/s and the
data is transmitted on twisted-pair
copper cables terminated in an RJ45
connector (the ethernet socket).
PIC microcontroller IC1 writes to the
ethernet controller’s registers via the
SPI bus which runs at 8MHz. Ethernet
transmissions occur by Manchester
encoding on the T+ (pin 17) and T- (pin
16) pins of IC2 via two 51Ω resistors.
28 Silicon Chip
available from Jaycar (Cat. XC-4849).
They are simply connected to a PC
via a USB port.
Suitable memory card readers are
also available from Altronics.
The resistor values are chosen to be
close enough to match the characteristic impedance of the 10BaseT (ethernet) cable, which is 100Ω. Similarly,
reception occurs on the R+ (pin 13)
and R- (pin 12) pins of IC2.
The ethernet controller (IC2) requires some passive components to
complete the physical ethernet link (ie,
to transmit and receive data), including two transformers. These transformers plus, four 75Ω resistors and a 1nF
capacitor, are all part of RJ45 connector
CON2 and provide electrical isolation
from the network. In addition, the RJ45
connector contains two LEDs, one
green and the other yellow.
According to the datasheet for the
ENC28J60 (IC2), a 2.32kΩ resistor from
pin 14 (RBIAS) to ground is required to
set the signal amplitude on the transmitting pair. This is made up using
series 2kΩ and 330Ω resistors to give
2.33kΩ, which is near enough. IC2 also
requires a 25MHz crystal to operate
correctly and this, together with its two
33pF loading capacitors, is connected
to pins 23 & 24.
Outputs LEDA and LEDB of IC2
drive the two LEDs in the RJ45 connector. These outputs can be configured
(using the registers in IC2) to light the
connector LEDs under various conditions. In this case, we have chosen
to drive the LEDs to conform to the
usual convention, with the green LED
indicating a valid ethernet link and the
yellow LED indicating data activity.
The remaining line to IC2 is the RSTbar line (pin 10). This is the reset line
and is driven by the RB7 (pin 16) output of the microcontroller. It simply
resets the internal logic of the ethernet
controller (IC2) when required.
Note that there are two other lines
on IC2 which are unused: CKO
and INT-bar.
CKO (pin 3) is a clock out line
and this delivers a square-wave
whose frequency is related to
IC2’s system clock (in turn derived from the 25MHz crystal). This
frequency can be configured via IC2’s
registers (it can be used to provide the
clock for a microcontroller for example) but is not used here as IC1 has
its own crystal (X1). This was done to
allow the microcontroller to run at its
highest rated clock frequency.
The other unused line (pin 4) is the
interrupt line. This can be used to
interrupt the microcontroller under
certain circumstances but again is not
used here.
Memory card
As mentioned above, the memory
card is accessed in SPI mode and this
is done via the SD card socket (CON4).
This allows microcontroller IC1 to
read from and write to the memory
card.
MMC/SD/SDHC cards can be accessed either in native mode or in SPI
mode. The advantage of the SPI mode
is that any off-the-shelf microcontroller that has an SPI peripheral can
be used, making the hardware layer
easy to implement. The interface with
SPI is also simpler but the penalty is
slower transfer speeds. However, SPI
speeds are quite adequate for serving
web pages.
Inputs & outputs
Connector CON3 provides access
to the analog inputs and the digital
outputs. The four analog inputs are
AN0-AN3 of IC1 (pins 2-5) and
these inputs are all protected using
10kΩ current-limiting resistors. An
AD22103 temperature sensor IC (IC4)
is shown connected to AN0 on Fig.2
but other types of sensors with a linear
0-3.3V output (or less) can also be used
on the analog inputs.
The digital outputs are at RB12RB15 (pins 23-26) of IC1 and toggle
between 0V and 3.3V.
CON5 allows optional access to the
serial (UART) port of IC1. Note that
siliconchip.com.au
siliconchip.com.au
November 2009 29
A
SC
2009
CON5
13
Tx
Rx
Vr
R1:
110Ω
GND
33pF
4 x 10k
Vdd (+3.3V)
110Ω
R3:0Ω
R2:
180Ω
OUT
ADJ
+V
IN
REG1 LM317T
33pF
X1 8MHz
10 µF
1
10
9
11
28
8
19
Vss
Vss
AVss
27
RB2
RB6
OSC2
OSC1
RB4
RB5
330Ω
+3.3V
6
15
12
RA4
7
RB3
16
RB7
17
RB8
22
RB11
21
RB10
18
RB9
IC1
dsPIC33
FJ64GP
802
Vcap
2
AN0
3
AN1
4
AN2
5
AN3
14
13
MCLR Vdd AVdd
RB12
24
RB13
25
RB14
26
RB15
23
20
470 µF
1k
WIB: WEB SERVER IN A BOX
TEMPERATURE
SENSOR
(OPTIONAL)
3
GND
1
CON3
33 µF
K
D1 1N4004
IC4
2
Vo
AD22103
1
Vs
CON1
+6-9V DC
INPUT
K
K
λ LED2
A
330Ω 10 µF
2.0k
λ LED1
A
330Ω
OSC1
SO
8
Vcc
1
CS
SI
Vss
4
23
24
27
26
HLD
3
A
K
1N4004
WP
7
+3.3V
Vss
2,11,18 21,22
Vcap
IC3
25AA02
6
SCK E48
5
2
1
13
T+ 17
16
T–
R– 12
CKO
4
INT
5
NC
10
R+
RST
9
IC2
CS
6
ENC28J60
SO
7
SI
LEDB
8
SCK
LEDA
14
Rbias
OSC2
3
Vdd
15,19,20, 25,28
100nF
33pF
X2 25MHz
7
9
51Ω
8
10
4
6
5
3
1
K
λ
RJL2
A
K
λ RJL1
A
Vo
Vs
AD22103
K
A
(RJ45)
1nF
4x75Ω
3
4
5
6
7
8
1
2
LEDS
ADJ
OUT
LM317T
IN
6
3
1
5
2
7
4
OUT
CON4
Vss2
Vss1
CS
CK
DI
DO
Vdd
SD CARD
SOCKET
(AMPHENOL RJMG163218101NR)
RECEIVE
LED1: DISK ACCESS
LED2: BLINKING = NORMAL OPERATION
100nF
51Ω
51Ω
GND
33pF
2 x 330Ω
100nF
51Ω
2
CON2: RJmag CONNECTOR MODULE
TRANSMIT
Fig.2: the circuit is based on a PIC microcontroller (IC1), an ENC28J60 ethernet controller (IC2), a 25AA02E40 MAC address chip (IC3) and an external memory
card. The PIC microcontroller interfaces to the memory card, reads the analog inputs and controls the digital outputs at RB12-RB15. It also drives the ethernet
controller (IC2) which in turn interfaces to the external network via an RJ45 connector. IC4 is an optional temperature sensor (AD22103) and is connected to
one of the analog inputs (AN0 in this case). Power comes from a 6-12V DC regulated plugpack supply.
–
+
All The Jargon Explained
DNS (Domain Name System): a system whereby domain names can be resolved to IP
addresses.
DDNS (Dynamic Domain Name System): a system whereby a fixed domain name can be
associated with a dynamic IP address.
DHCP (Dynamic Host Configuration Protocol): a protocol that allows a DHCP server to
assign an IP address to a DHCP client requesting it. The IP address is handed out on a
limited time lease.
EEPROM (Electrically Erasable Programmable Read-Only Memory): a solid-state nonvolatile memory chip that can be written to and erased.
Ethernet: a network standard for the physical and data link layer that determines how data
is transmitted and received from a common medium.
FTP (File Transfer Protocol): a protocol used to transfer files across a network.
Gateway: a network node to which data traffic is directed. It relays this traffic in a way so as
to reach its destination (using routing information).
HTTP (Hypertext Transfer Protocol): a protocol commonly used to transfer web pages and
content from a web server to a browser.
ICMP (Internet Control Message Protocol): a protocol used to send status and error
messages across the Internet. It is typically used for Ping (Packet Internet Groper).
IP (Internet Protocol): a protocol used for transmitting data packets across a network,
primarily used in the Internet.
IP Address: each device sending or receiving IP packets must have a unique IP address,
typically written as four decimal numbers in the range 0-255 (8-bit) and separated by dots. An
example IP address is 192.168.0.34.
MAC (Media Access Control): a protocol that implements the data link layer on an ethernet
network where nodes share a common medium.
MAC Address: each device sending or receiving ethernet packets must have a unique MAC
address. This is is a 6-byte address which is often written as six hexadecimal bytes joined by
colons, for example: 00:04:A3:21:09:6C.
Manchester encoding: a self-clocking method of encoding binary data that relies on edge
transistions.
Multi-tasking: the ability of a processor to run multiple tasks.
NAT (Network Address Translation): a technique whereby a router can modify address and
port information in packets to translate from one address space to another. Typically used in
routers to share a single connection from your ISP among many devices in a home network.
Port Forwarding: a technique used by routers to redirect traffic on a particular TCP or UDP
port to a private IP address.
Protocol: a set of rules to allow network devices to communicate with each other.
SMTP (Simple Mail Transfer Protocol): a protocol used for sending email.
SNTP (Simple Network Time Protocol): a protocol used to receive time information from a
remote time server. The time is returned as a number that represents the number of seconds
that have elapsed since the epoch time which is set at 00:00 1 January 1970.
Static DHCP: a technique whereby a DHCP server can be made to assign a static IP address
to a particular network device (by associating a static IP address with a MAC address).
Subnet Mask: this is in the style of an IP address and is used as a bitwise AND mask to
determine whether an IP address is in the same network subnet.
TCP (Transmission Control Protocol): a protocol for transmission of data that is connection
oriented.
TCP/IP (Transmission Control Protocol/Internet Protocol): a family of protocols that allow
network devices to communicate.
UART (Universal Asynchronous Receiver/Transmitter): a circuit used for serial commun
ication between devices.
UDP (User Datagram Protocol): a protocol for transmission of data that is packet oriented.
30 Silicon Chip
the levels are not true RS232 levels
but simply 3.3V CMOS levels.
LED indicators
Outputs RA4 and RB3 from IC1
are used to drive indicator LEDs1 &
2. LED1 (green) lights when ever the
memory card is accessed (ie, for both
reads and writes), while LED2 (orange)
is on during boot up until all initialis
ations have been completed. Once
the web server has initialised, LED2
blinks on and off to indicate normal
operation.
When LED2 is blinking, it shows
that the cooperative multitasking
main loop is executing, ie, no process
is blocking operation or taking up
inordinate processor time. At no time
should the orange LED stop blinking
during normal operation, otherwise
data packets will be dropped.
Clock signals
Clock signals for the microcontroller
are derived from an 8MHz crystal (X1).
This is connected between pins 9 &
10 (OSC1 & OSC2), together with two
33pF capacitors which provide the
correct loading. Note that IC1 runs
at its maximum of 40MIPS (millions
instructions per second) – an internal
PLL (phase lock loop) stage is used to
derive the system clock.
Power for the CPU inside IC1 is derived from the main 3.3V rail using an
internal 2.5V regulator. This requires
a 10µF tantalum bypass capacitor on
pin 20. Similarly, a 10µF bypass capacitor is fitted to pin 1 of the ethernet
controller (IC2).
Note that IC1’s reset pin (MCLR-bar,
pin 1) is pulled permanently high by
a 1kΩ resistor and so is not used here.
Instead, IC1 is reset by its internal
power-on reset logic.
Power supply
Power for the circuit is derived
from a 6-9V DC plugpack and this is
applied via reverse polarity protection
diode D1. The resulting DC rail is then
filtered using a 33µF capacitor and fed
to an LM317T adjustable 3-terminal
regulator (REG1) to derive a +3.3V rail.
This +3.3V rail then powers ICs1-3 and
the memory card.
REG1’s output voltage is set by the
divider network on its OUT & ADJ
terminals according to the following
formula:
VOUT = 1.25V x (1 + (R2/R1))
By using a 110Ω resistor for R1 and a
siliconchip.com.au
180Ω resistor for R2, we get an output
voltage that’s very close to 3.3V.
In practice though, the 1.25V reference in the regulator can vary anywhere between 1.2V and 1.3V, due to
manufacturing tolerances. For this
reason, provision is made on the PC
board for an additional resistor (R3) in
series with R2 so that you can adjust
the output voltage if necessary. In most
cases, you won’t need to do this and a
wire link is used for R3 instead (more
on this later).
The supply rail at the output of
diode D1 is also fed to a terminal on
CON1, so that it can be used to power
external devices if necessary. In addition, the +3.3V rail is fed to two other
terminals on CON3, in one case via
a 110Ω current-limiting resistor. The
current-limited +3.3V rail (Vr) is used
to power the AD22103 temperature
sensor (IC4).
The 110Ω current-limiting resistor
is necessary because the temperature
sensor is connected to the circuit via
a stereo jack socket. In operation, it
prevents the supply rail from being
shorted to ground each time the stereo jack is plugged into its socket (the
jack’s tip touches the socket’s ring as
it is inserted). The 110Ω resistor protects against short circuits and doesn’t
interfere with the operation of the
temperature sensor itself, as the latter’s
current draw is negligible.
Ethernet Web Server Parts List
1 PC board, code 07111091,
123 x 74mm
2 28-pin 0.3-inch IC sockets
1 3-way pin socket, 2.54mm pitch
8 M3 x 6mm machine screws
4 M3 x 15mm tapped Nylon
spacers
1 250mm-length of 0.7mm
tinned copper for links
1 2.5mm PC-mount male DC
power connector (Jaycar PS0520, Altronics P-0621A)
1 TO-220 mini heatsink (Jaycar
HH-8502, Altronics H-0630)
1 8MHz crystal (X1)
1 25MHz crystal (X2)
1 plastic instrument case, 95 x
158 x 47mm (Jaycar HB-5922)
1 SD surface-mount memory
card socket (Altronics P5722)
1 ethernet RJ45 Connector
with Magnetics, Amphenol
RJMG163218101NR (Farnell
135-7435)
3 3-way screw terminal blocks
(5.04mm pitch)
2 2-way screw terminal blocks
(5.04mm pitch)
1 6-9V DC 300mA plugpack
(Jaycar MP-3145 or Altronics
M-9208 plus M-9191 connector)
1 3.5mm stereo jack (optional)
1 3.5mm stereo socket, chassis
mount (optional)
Semiconductors
1 dsPIC33FJ64GP802-I/SP programmed with 0711109A.hex
(IC1)
1 ENC28J60 ethernet controller
(IC2)
1 25AA02E48 serial EEPROM
with MAC address (IC3)
1 AD22103 temperature sensor
(IC4) (optional) (Farnell 1438415)
1 1N4004 silicon diode (D1)
1 LM317T adjustable 3-terminal
regulator (REG1)
1 3mm green LED (LED1)
1 3mm orange LED (LED2)
Capacitors
1 470µF 16V electrolytic
1 33µF 16V electrolytic
2 10µF tantalum
3 100nF monolithic
4 33pF ceramic
Resistors (0.25W, 1%)
4 10kΩ
1 180Ω
1 2kΩ
2 110Ω
1 1kΩ
4 51Ω
5 330Ω
Firmware overview
OK, so that’s the hardware side of
things and it’s all fairly straightforward. Most of the features are implemented in the firmware, so let’s now
take a closer look at this.
The firmware uses the freely available TCP/IP stack from Microchip.
We’ve customised it and also implemented some missing features in the
minimal stack.
The stack is based on a cooperative
multi-tasking model (ie, a lot of tasks
run concurrently) and this has been
retained. The main program is an infinite loop, with finite state machines
used to keep track of stack processes
that need attention.
The other major addition is the
memory card driver and the FAT/
FAT32 file system that resides on top
of that. The WIB recognises the FAT/
FAT32 file system which means that
you should be able to read the memory
card using any Windows, Mac or Linux
box (and a card reader).
siliconchip.com.au
The modules used in the TCP/IP
stack include HTTP, FTP, ICMP, SNTP,
SMTP, DNS and Dynamic DNS. Only
the limited amount of program memory on the microcontroller prevented us
from including further modules such
as a DHCP client to automatically pick
up an IP address.
Because there’s no DHCP client,
the web server is assigned a static IP
address and this is also necessary for
port forwarding. However, a DHCP
client working in conjunction with
static DHCP could have been useful
for incorporating the web server into
an automatically configured network.
In any case, the DHCP server in your
router must be configured to reserve
a static IP address for the WIB. We’ll
tell you how to do that next month.
MMC/SD/SDHC memory cards
Either an MMC, SD or SDHC
memory card can be used in the web
server. MMC (MultiMedia Card) and
SD (Secure Digital) cards use FLASH
memory technology and are available
in capacities up to 2GB. SDHC cards
are essentially high-capacity SD cards
and are available in sizes ranging from
4GB to 32GB.
All three types of card can be used
in this project. Note that while all three
types look alike, MMC cards have only
seven metal contacts whereas SD cards
have nine.
MiniSD and MicroSD cards can
also be used. These are essentially SD
cards but are smaller. You will need
an external adaptor in order to plug
them into the SD card socket used in
the web server.
Construction
Building the WIB is easy with all
parts mounted on a single-sided PC
board coded 07111091. This board
measures 123 x 74mm and is housed
inside a plastic utility case.
The only slightly tricky bit is the surNovember 2009 31
Fig.3: install the parts on the PC
board as shown on this layout
diagram. Make sure all polarised
parts are correctly oriented and
leave IC1 & IC2 out until after the
power supply has been checked
– see text.
CON2
CON1
RJMG1632
18101NR
1 2 3 4 5 6
33F
180
0
D1
7
REG1
LM317T
8
10
9
+
110
330
470F
+
R19
GND
100nF
100nF
X2
100nF
Fig.4 (below): this diagram and the accompanying photos
show how IC3 and the SD memory card socket are installed
on the track side of the PC board. Note the orientation of the
IC and don’t forget to solder the two tabs of the memory card
socket adjacent to the edge of the board.
2.0k
+
IC3
(UNDER)
10F
10F
+
IC3
IC1 dsPIC 33FJ64GP802
X1
10k
10k
33pF
CON5
LED1
33pF
NOTE: IF PC BOARD HAS NO SOLDER
MASK LAYER, PLACE A 23 x 16mm
PIECE OF INSULATING SHEET UNDER
CON4 TO PREVENT ITS SHIELD PLATE
SHORTING COPPER TRACKS.
10k
10118 7
1011
10k
CON4
LED2
330
ANALOG INPUTS
Vss
(GND)
Vdd
(3.3V)
51
IC2 ENC28J60
1k
DIGITAL I/O
+3.3V
51
51
330
CON3
51
330
+DC
IN
330
33pF 33pF
6
5
4
3
2
1
9
CON4
07111091
MMC/SD/SDHC
ETH
WEB SERVER
CARD
SOCKET
MG 07/09
29011170CARD
MMC/SD/SDHC
REVRES(UNDER)
BEW HTE
SOCKET
90/70 GM
UNDERSIDE VIEW SHOWING SMD COMPONENTS
face-mount IC (IC3) which is mounted on the copper side of the PC board.
However, this SOIC device has only
eight pins and the pin spacing is
around 1.27mm, so it’s not difficult
to hand solder.
Figs.3 & 4 show the parts layout on
the PC board. However, before beginning the assembly, it’s a good idea to
carefully inspect the board for etching
defects (eg, shorted tracks and hairline
cracks). Such faults are rare but checking now can save a lot a hassle later on.
Check also that corner cutouts have
been made at the CON1 & CON2 end
of the board, so that it will later clear
the mounting posts inside the case. If
not, you will have to make the cutouts
yourself using a fine-toothed hacksaw
and a small, flat file.
Having done that, the first job is to
install the 11 wire links – see Fig.3.
These can be cut from a length of
0.7mm tinned copper wire. If necessary, you can first straighten the link
wire by clamping one end in a vise and
32 Silicon Chip
then stretching it slightly by pulling
on the other end using a pair of pliers.
Once the links are in, the next step
is to install the resistors. These can go
in either way and some are mounted
end-on to save board space. Table 1
shows the resistor colour codes but
you should also check each one with
a DMM before installing it.
You can either use a zero-ohm resistor for R3 or you can install a wire link.
Diode D1 and crystals X1 & X2 are
next on the list. Note the orientation
of D1 and don’t get the two crystals
mixed up. The 8MHz crystal is used
for X1, while the 25MHz crystal is X2.
Now for the LM317T regulator
(REG1). This mounts horizontally on
the board and is fitted with a mini heatsink for cooling. It’s installed by first
bending its leads down by 90° about
5mm from its body. It’s then secured
in place, along with its heatsink, using an M3 x 6mm machine screw, flat
washer and nut and its leads soldered.
Note: do not solder REG1’s leads
before bolting it down. If you do, the
PC tracks could crack as the assembly
is tightened down.
The two 28-pin machine IC sockets
can now be installed. Be sure to orientate these with their notched ends
as shown on Fig.3. If you are unable
to obtain 28-pin 0.3-inch sockets, you
can use pin header strips instead.
Alternatively you can cut 28-pin 0.6inch sockets in half or you can use two
14-pin sockets mounted end-to-end.
Do not install the two ICs in their
sockets yet. That step comes later.
Follow these parts with the capacitors, starting with the 33pF ceramic
and 100nF monolithic types. The two
10µF tantalum capacitors can then be
installed, followed by the 33µF and
470µF electrolytics. Note that the
tantalum and electrolytic capacitors
are all polarised, so make sure they
go in the right way around – see Fig.3.
Connectors
The DC socket (CON1), the RJ45
siliconchip.com.au
make sure they are oriented correctly.
A 25mm-high cardboard spacer can
be used to set their height. Just slide
this spacer between each LED’s
leads and push the LED down onto
it before soldering it in place.
Initial tests
You will need a 6-9V DC 300mA
(or greater) regulated plugpack fitted
with a 2.5mm connector to power this
project. Suitable plugpacks include
the Jaycar MP-3145 and the Altronics M-9208. Note, however, that the
latter requires swapping the supplied
2.1mm connector for a 2.5mm connector (Altronics M-9191).
With the three ICs out of the circuit, apply power and use a DMM to
measure the voltage between the OUT
terminal of REG1 and GND. It should
measure close to 3.3V and this same
voltage should also appear at the Vdd
(3.3V) terminal of CON3.
If you don’t get the correct reading,
switch off immediately and check for
wiring errors. In particular, check the
resistor values on the OUT and ADJ
terminals of REG1 if the reading is high
or low. Alternatively, if you don’t get
any voltage at all, check the supply
polarity and D1’s orientation.
This view shows the completed PC board. Note that there are a few differences
between this prototype board and the final version shown in Fig.3, especially
around CON1, CON2 and REG1.
connector (CON2) and the 3-way pin
socket (CON5) can now go in. Make
sure that these parts are sitting flush
against the PC board before soldering
their pins. In addition, take care when
soldering the RJ45 connector as some
of its pins are quite close together and
it’s easy to get solder shorts. Don’t
forget to solder the two pins near the
edge of the PC board, as these help
secure the socket in position.
The 13-way screw terminal block
(CON3) is made up using three 3-way
Trimming the 3.3V rail
The accuracy of the +3.3V rail is
important because some MMC/SD/
SDHC cards operate over quite a
narrow voltage range. The firmware
checks that the inserted card operates
at 3.3V and so it is crucial that REG1’s
output be close to +3.3V.
If the 3.3V rail is more than 3.4V or
less than 3.2V, you will need to change
one or both of the values for R2 and R3.
For example, if the voltage is around
+3.17V, you will need to install a 10Ω
resistor for R3 and this should increase
the rail so that it is close to +3.3V.
Alternatively, if the output voltage is
+3.41V, you should change the value
blocks and two 2-way blocks. These
should all be dovetailed together and
mounted as a single unit, with the access holes facing the edge of the board.
The board assembly (minus the
three ICs and the SD card socket) can
now be completed by soldering in
the two LEDs. These should both be
mounted at full lead length, with their
bodies 25mm above the board so that
they will later protrude through the
lid of the case. Use the green LED for
LED1 and the orange LED for LED2 and
Table 1: Resistor Colour Codes
o
o
o
o
o
o
o
siliconchip.com.au
No.
4
1
4
1
2
4
Value
10kΩ
1kΩ
330Ω
180Ω
110Ω
51Ω
4-Band Code (1%)
brown black orange brown
brown black red brown
orange orange brown brown
brown grey brown brown
brown brown brown brown
green brown black brown
5-Band Code (1%)
brown black black red brown
brown black black brown brown
orange orange black black brown
brown grey black black brown
brown brown black black brown
green brown black gold brown
November 2009 33
69
(TOP OF CASE)
A
A
5
45
95
108
26
158
15.75
A
A
(BOTTOM OF CASE)
32
HOLES 'A'
ARE 3mm
DIAMETER
63.5
103.5
22.5
A
A
ALL DIMENSIONS
IN MILLIMETRES
15.75
Fig.5: here are the drilling details for the top and bottom case sections. All the holes are drilled to 3mm diameter.
of R2 to 160Ω and R3 to 10Ω (giving a
total value for R2 + R3 = 170Ω), or you
could use 150Ω for R2 and 22Ω for R3.
Again, this should bring the voltage
from REG1 pretty close to +3.3V.
Once the supply voltage is correct,
switch off and install IC1 & IC2 into
34 Silicon Chip
their sockets. Make sure they are oriented correctly (see Fig.3) and don’t
get them mixed up.
Installing the SMD parts
The SMD parts (ie, IC3 and SD card
socket CON4) mount on the copper
side of the board as shown in Fig.4.
You will need a fine-tipped soldering
iron, some fine solder, some solder
wick and (preferably) a magnifying
lamp.
Begin by carefully aligning the IC
with it solder pads, making sure that
siliconchip.com.au
The PC board fits neatly inside a standard plastic utility case (note: the final board is longer than the version shown
here). The memory card can be removed or installed by sliding the adjacent end panel out of its slot.
it is oriented as shown (ie, pin 1 at
upper right, as indicated by the dot in
its body). If you like, you can hold it
in position using self-closing tweezers.
That done, lightly tack solder pin
1, then remove the tweezers and inspect the IC under a magnifying glass
to make sure it is in the correct position. The remaining pins can then be
soldered, starting with the diagonally
opposite pin (pin 5). Don’t forget to add
a little more solder to pin 1 if necessary
to complete the job.
Do this job quickly, so as not to overheat and damage the tracks on the PC
board. Once you have finished, inspect
the job under a magnifying glass again.
If any of the pins are shorted by solder
(other than pins 7 & 8), then you can
remove the excess solder using the
solder wick.
Memory card socket
While you are on the copper side
of the PC board, you can solder in the
memory card socket as well. It is an
SMD socket so you must place it over
its pads and solder in one of the pins
first to anchor it in position. Once
that is done, check that it is correctly
aligned before soldering the remaining pins.
Note that there are two mounting
siliconchip.com.au
RJ45
CUTOUT
11
16
41
16
DC INPUT
CUTOUT
14
12
10
18
17.5
(RIGHTHAND END PANEL)
88
Fig.6: here’s how to make the cutouts in the righthand end panel for the
RJ45 socket and the DC power socket.
M3 x 6mm SCREWS
PC BOARD
M3 x 15mm NYLON SPACERS
BOTTOM OF CASE
M3 x 6mm SCREWS
Fig.7: the PC board is mounted in the case on four M3 x 15mm tapped
Nylon spacers and secured using M3 x 6mm screws.
pads towards the front of the socket
that also have to be soldered.
Final assembly
The prototype was housed in a
plastic instrument case measuring 95
x 158 x 47mm (Jaycar HB-5922). This
is marked out and drilled as shown
in Figs.5 & 6. As shown, you need to
drill two 3mm holes in the lid for the
LEDs and four 3mm mounting holes in
the base (Fig.5). In addition, you have
November 2009 35
Installing The
Temperature Sensor
The optional AD22103 ratiometric temperature sensor (IC4)
is installed by mounting it inside a 3.5mm stereo plug – see
Fig.8. Its +Vs lead is connected to the ring terminal of the
stereo plug, its Vo lead to the sleeve and its GND lead to the
tip.
This then plugs into a matching stereo jack socket mounted
on the end of the case and this is wired back to CON3 on
the PC board.
As shown in Fig.8, the +Vs supply lead connects to the
+Vr terminal (terminal 2) of CON3, the GND lead connects to
terminal 7 of CON3, and the Vo (sensor voltage output) lead
connects to one of the four analog inputs of CON3 (either
terminal 9, 10, 11 or 12).
The temperature sensor is mounted outside the case to
ensure that it is unaffected by the heat generated by other
The AD22103 temperature sensor is
mounted inside a 3.5mm stereo jack –
see Fig.8.
to make two square cut-outs in one of
the end panels for the DC socket and
RJ45 connector (Fig.6).
Each of these cut-outs can be made
by drilling a series of small holes
GND TO PIN 7 OR
13 OF CON3
+Vs TO PIN 2 OF CON3
Vo TO PIN 9, 10, 11
OR 12 OF CON3
HIS SERVER relies on a username
and password for security. This
username and password combination
must be used to access the FTP
server (to modify the file system) and
to access private web pages through
HTTP (ie, using a web browser).
This is the main security mechanism
to prevent unauthorised access from a
remote location over the Internet. All
settings should also be protected by
the username/password combination
and this is the approach taken in the
sample website we are providing
for download from the SILICON CHIP
website.
36 Silicon Chip
RING
SLEEVE
3.5mm
STEREO
PLUG
END OF CASE
+Vs TO
RING
TEMP SENSOR
PLUGS IN
HERE
AD22103
TEMP SENSOR
(FLAT
SIDE)
GND
TO TIP
Vo CONNECTED
TO SLEEVE
PLUG COVER
Fig.8: connect the AD22103 temperature sensor to the
3.5mm stereo plug as shown here. You can use a DMM
to identify the tip and ring terminals.
parts. This heat comes mainly from the LM317T voltage
regulator but the ICs also contribute. Mounting the sensor
outside the case ensures an accurate measurement of the
room temperature.
around the inside perimeter, then
knocking out the centre piece and
cleaning up the edges with a flat file.
If you are installing the specified
temperature sensor, then you will also
need to drill a 6mm hole in the second
end panel (see Fig.8 and photos).
Deburr all holes using an oversize
drill, then secure four M3 x 15mm
Nylon spacers to the base using M3 x
6mm screws. The PC board can then
be dropped into place along with the
righthand end panel and secured using another four M3 x 6mm screws as
shown in Fig.7.
Installing the memory card
You will need a suitable MMC, SD
or SDHC memory card to use with the
Security Disclaimer
T
3.5mm STEREO
JACK SOCKET
TIP
Note, however, that given the
correct username and password
combination, a user could log into
the server and change all the settings
by accessing the file system on the
memory card through an FTP client.
In addition, they could change the
password and username combination
to lock others out of the system.
If that ever happens, the remedy is
to write to the card using a PC and a
memory card reader and define a new
username/password pair. Of course,
this assumes you have physical
access to the memory card.
This web server cannot be
WIB. This should be formatted with
a FAT/FAT32 file system before plugging it into the memory card socket
(see photo). With the ICs installed and
power applied, the orange LED should
blink on and off approximately twice
a second.
That completes the construction of
the WIB. However, before using the
device, you need to copy the necessary
files to the memory card and interface
the server to your network. This will
involve entering a few settings like
the Gateway address, IP Address and
Subnet mask, turning on port forwarding in your router and activating a
dynamic DNS (DDNS) service.
We’ll explain how that’s all done in
SC
Pt.2 in next month’s issue.
considered highly secure because
it is prone to DoS (denial of service)
attacks, as are most web servers. On
a positive note, HTTP authentication
occurs server side and therefore no
transmission of a coded version of
the username and password occurs
(although it is possible to intercept the
HTTP headers that contain the correct
username and password – they are
not encrypted but encoded using
base64).
There are also a limited number
of commands, no server side script
execution and the microcontroller uses
a (modified) Harvard architecture,
making the server somewhat more
secure than most.
siliconchip.com.au
|