This is the software for
article 369: "Part 2 -- A digital thermometer or talk I2C to your atmel microcontroller"

I2C communication and temperature measurement with the Atmega8 microcontroller
with local LCD display and readout possibility from Linux via rs232 port

Copyright of all software and diagrams: Guido Socher
License: GPL
---------------------------------------------------------------------------

 All parts needed to build this litte thermometer can be ordered from 
 http://shop.tuxgraphics.org/                                          
 They have also other electronics and components for a very good price!

To compile the software and download it to the Atmega8 use the command:

make load
or (if you have avrdude):
make loadavrdude

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

Note about hardware change compared to 365
------------------------------------------
Some LCD displays have a higher capacitive load and lower resistance 
on their input lines than others. This probably because they have a 
better ESD protection.
This can cause problem when the LCD display is connected to the SCK and 
and MOSI pins.
The LCD RS and D7 pins are there for now connected to PD7 and PD6.


Building the I2C communication software
---------------------------------------
The shop.tuxgraphics.org  AVR programming CD does not have a regular 
gcc installation as you will anyhow not be able to install things on a
read-only CD. The primary purpose of this CD is to programm the 
microcontroller. However you may want to test the I2C communication 
after you have loaded software to the microcontroller. For this purpose
two programs are included in the "bin" subdirectory:

bin/i2c_rs232_pintest
bin/i2ctemp_linux

In addition there also
bin/2ctalk_linux   -- a generic program to send any command over I2C
bin/i2ctempgui     -- a little gui wrapper for i2ctemp_linux (uses i2ctemp_linux)

With bin/i2c_rs232_pintest you can test (using a voltmeter) that the DTR and
RTS lines of your rs232 port are working.

With bin/i2ctemp_linux you can read temperature valuses form the thermometer.

On the computer to which you intend to connect this termometer you should build
the i2ctemp_linux program and install it (this may or may not be the same computer
where you program the microcontroller):
make i2ctemp_linux
cp i2ctemp_linux /usr/bin

The i2ctemp_linux assumes by default that your thermometer is connected to
COM1 (/dev/ttyS0). You can change this with the option -p. Example:

> i2ctemp_linux -p /dev/ttyUSB0
In :i=19.8
Out:o=19.3

Using a USB to rs232 converter
------------------------------
For laptops which do these days not have a rs232 interface you can simply use
USB to rs232 adapter. I use e.g a no-name adapter which contains a Prolific 2303 chip.
It looks like this in the /proc/bus/usb/devices file:
Vendor=067b ProdID=2303 Rev= 2.02

The kernel module for this chip is called pl2303.

Makeing data available over the web
-----------------------------------
Never run i2ctemp_linux directly from the webserver. Instead add a contab entry
which runs a script to generate an appropriate webpage e.g every 15 minutes:

The script:
#!/bin/sh
webpagefile=/home/httpd/html/temp.html
echo "<h2>Local temperatures</h2><pre>" > $webpagefile
i2ctemp_linux | sed -e 's/i=/inside  /;s/o=/outside /' >> $webpagefile
echo "</pre>" >> $webpagefile

Run the above script e.g from a crontab entry which looks like this
(load a file containing this line with the command crontab):
1,15,30,45 * * * * /the/above/listed/scriptfile

Calibrating the thermometer
---------------------------
First of all you should note that this thermometer is already in
unclibrate state more accurate than most household thermometers. 
If you get the right parts (e.g from shop.tuxgraphics.org) then you will
already have an accuracy of +/- 0.5'C without any calibration.

If you want to calibrate it then edit the file ntc.h
Instructions on what to do are included.

The recommended oprating range is: -30'C to + 45'C for the outdoor sensor
and +10 to +45'C  for the indoor sensor. The indoor sensor is  more
accurate than the outdoor because the ADC uses a smaller reference voltage.
This limits the 0..1023 digital values of the ADC to a smaller range and
gives thus higher accuracy (the disdvantage is that the indoor sensor can
then not measure below 9'C, but it should not be soooo cold in your house ;-)

Revision history
----------------
2005-02-26: version 0.4 (first public version)
2005-02-27: version 0.5 -- updated circuit diagram

