# vim:sw=8:ts=8:si:et

This is the software for the tuxgraphics.org
ethernet remote device with an attached sensirion sht11 sensor.
This is a calibrated sensor for both humidity and temperature.
No additional external components are needed (not even a resistor). 
See http://tuxgraphics.org/electronics/

Copyright of most software and all diagrams: Guido Socher

License for the webserver software: GPL V2
See http://www.gnu.org/licenses/gpl.html
---------------------------------------------------------------------------
Sensor connection

Edit main.c and change MAX_SENSORS at the beginning of the file.
Set it according to the amount of sensors which you plan to connect.

First sensor:
Sensor GND --- GND  (available on the digital IO port of the web-server board)
Sensor Vcc --- 3.3V (available on the analog port of the web-server board)
Sensor SCK  --- PB0 (available on the digital IO port of the web-server board)
Sensor Data --- PD0 (available on the digital IO port of the web-server board)

Second sensor (optional):
GND, Vcc and SCK: same as first sensor
Sensor Data --- PD1 (available on the digital IO port of the web-server board)

Third sensor (optional):
GND, Vcc and SCK: same as first sensor
Sensor Data --- PD4 (available on the digital IO port of the web-server board)

The length of the cable bewteen sht11 sensor and ethernet board should be
0.5m. If you add a 100nF capacitory at each sensor between Vcc and GND
then you can extend the cable lenght to max 3m.

To cover a larger area one would use several ethernet board.
---------------------------------------------------------------------------

 All parts needed to build this AVR ethernet solution can be ordered from 
 http://shop.tuxgraphics.org/

!! READ THIS FIRST !!
---------------------
! Edit the file main.c and change the 2 lines:
! static uint8_t mymac[6] = {0x54,0x55,0x58,0x10,0x00,0x26};
! static uint8_t myip[4] = {10,0,0,26};


For the first device you build you will not need to change the mymac line.
But you will probably need to change the IP address (myip). It must be a
free address from the address range in your home network.

There is a range of private addresses (not routed on the public internet)
which you can use:
Netmask          Network Addresses
255.0.0.0         10.0.0.0 - 10.255.255.255
255.255.0.0       172.16.0.0 - 172.31.255.255
255.255.255.0     192.168.0.0 - 192.168.255.255

Example: you wlan router might have 192.168.1.1, your PC might have
192.168.1.2. This means you could e.g use 192.168.1.10 and leave some
room for more PCs. If you use DHCP then make sure that the address it not
double allocated (exclude it from the DHCP range).

Edit the beginning of the make file. And adjust those lines according to the
CPU you use (atmega168 or atmega328p):

MCU=atmega168
DUDECPUTYPE=m168
or
MCU=atmega328p
DUDECPUTYPE=m328

To compile the final software use the command:
make

Note: windows users may use and modify the supplied win_cmp.bat to setup the
environment correctly.

The above command will compile the following hex file:
eth_rem_dev_tcp.hex 

The command
make load

The last command will run something like: 
   avrdude -p m168 -c avrusb500 -e -U flash:w:eth_rem_dev_tcp.hex

! Note your programmer might interfer with the enc28j60! For the avrusb500
! with 30cm cable you can normally leave the cable on. For all other programmers
! it is however saver to remove the programmer cable and power down/up the device.
! This is because the SPI interface is used for loading of the software and 
! communication to the enc28j60.

To see a list of all possible build targets run the command:
make help

Selecting the right clock source
--------------------------------
Tuxgraphics hardware sold as of march 2007 is prepared to use the clock
signal from the enc28j60. To use this you need to change the 
low fuse byte once from 0x62 to 0x60:

avrdude -p m168 -c stk500v2 -u -v -U lfuse:w:0x60:m
or
avrdude -p m328 -c stk500v2 -u -v -U lfuse:w:0x60:m

or just type in your Linux shell:
make fuse

After programming the fuse settings of an atmega168 should be:
 low fuse:  0x60
 high fuse: 0xdf
 ext. fuse: 0x01

For the atmega328p the hfuse and efuse bytes look slightly different.
The idea is however the same. Just change the lfuse from factory default
to 0x60. The fuse settings of the atmega328 are after programming:
 lfuse reads as 0x60
 hfuse reads as 0xD9
 efuse reads as 0x07


Compilation on non-Unix systems
-------------------------------
Please use the provided Makefile  !!!

It will also work under Windows except for the loading
of the software. That is: compiling will work but not 
"make load". Use then whatever tools and commands to download
the resuting .hex file into the micrcontroller
Do not forget to adjust the fuese (see above).

Take also a look at the supplied win_cmp.bat file. This bat script
might be needed to set the environment correctly.

Using the board to measure temperature and humidity
---------------------------------------------------
Point your web browser to
http://10.0.0.26   (or what ever IP address you have given your hardware)

You should get a web page like this:

Sensors @26

s0 temperature: 25.9'C [78.6'F]
s0 humidity   : 40%
s0 dew point  : 10.4'C [50'F]

s1 temperature: 25.4'C [77.7'F]
s1 humidity   : 42%
s1 dew point  : 11.1'C [51'F]

refresh page
---------------------------------
version 3.3

The page reloads itself automatically every 5 min.

Revision history
----------------
2007-09-11: version 3.0 -- first public version. Based on eth_rem_dev_tcp-2.8.tar.gz
2008-12-21: version 3.1 -- update of Makefile for atmega168, auto-refresh the page every 5min
2009-02-06: version 3.2 -- more enc silicon B4 errata fixes
                           support for atmega328p

2009-09-06: version 3.3 -- updated to support more than one sensor.