Remote flower watering and monitoring with the tuxgraphics avr ethernet board
See subdirectory hardware for
more details on how to connect the relay, the precision rectifer and the sensors.
All parts needed to build this AVR ethernet solution can be ordered from
http://shop.tuxgraphics.org/
The above software uses 95% of the space on an atmega168, about 50% of an atmega328p and about 25% of an atmega644. You can not enable debug function on the atmega168.
Pinout for atmega644/atmega644a based ethernet boards:
- DS18S20 data pin = atmega pin PD6
- Capacitive humidity sensor, tone output pin = OC0A = atmega pin PB3
- Capacitive humidity sensor, precision rectifier output signal = ADC0 = atmega pin PA0
- Manual watering button = atmega pin PB0
- Dry soil LED (blinking) = between atmega pin PB1 and GND
- Pump control (to relay driver) = PD7
Pinout for atmega168/atmega328p based ethernet boards:
- DS18S20 data pin = atmega pin PD6
- Capacitive humidity sensor, tone output pin = OC0B = atmega pin PD5
- Capacitive humidity sensor, precision rectifier output signal = ADC0 = atmega pin PC0
- Manual watering button = atmega pin PB0
- Dry soil LED (blinking) = between atmega pin PB1 and GND
- Pump control (to relay driver) = PD7
!! READ THIS FIRST !!
---------------------
The mac address has to be unique within your own network.
If you connect more than one board to the same LAN
you will need to change the mac address to something else.
Edit the file main.c and change the last digit in this line:
static uint8_t mymac[6] = {0x54,0x55,0x58,0x10,0x00,0x29};
It does not matter to what value you change it as long as
there is no other ethernet board with the same value on your
lan. Your neighbor could re-use the same address.
Check the file "Makefile" and configure the programmer options
correctly:
For windows, Linux and Mac with a tuxgraphics avrusb500 programmer
you will need to configure the virtual com-port to which the avrusb500
is attached:
# windows
#LOADCMD=avrdude -P COM4
Check the file "Makefile" and make sure the MCU is set correctly:
MCU=atmega168
DUDECPUTYPE=m168
or
MCU=atmega328p
DUDECPUTYPE=m328p
or
MCU=atmega644
DUDECPUTYPE=m644
More information about Makefiles can be found at:
http://tuxgraphics.org/electronics/200912/makefiles.shtml
This software has a fixed IP address which is set at compile time in
file main.c:
static uint8_t myip[4] = {10,0,0,29};
myip must be a free address from the address range in your network.
Example: you DSL 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).
You need an avr-gcc development environment in order to compile this.
Setting a password
The password is defined in main.c on this line:
static char password[]="secret";
To compile the software use the command:
make
Note: windows users may use and modify the supplied winmake.bat to setup the
environment correctly.
The command
make load
will execute the avrdude command to load the software.
E.g something like:
avrdude -p m328p -c stk500v2 -e -U flash:w:main.hex
! Note: your programmer might interfere 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 m88 -c stk500v2 -u -v -U lfuse:w:0x60:m
or
avrdude -p m168 -c stk500v2 -u -v -U lfuse:w:0x60:m
or
avrdude -p m328p -c stk500v2 -u -v -U lfuse:w:0x60:m
or
avrdude -p m644 -c stk500v2 -u -v -U lfuse:w:0x60:m
The above command can as well be executed by using the make
file. In a Linux shell you can just type:
make fuse
Note: windows users may use and modify the supplied winsetfuse.bat script.
After programming the fuse settings of atmega168 and atmega88 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 atmega328p are after programming
should be as below (default factory settings for atmega328p, the
efuse has some not used bits and is dependent on the chip revision):
lfuse reads as 0x60
hfuse reads as 0xD9
efuse reads as 0x07
Fuses of the atmega644/atmega644a after programming:
Device signature = 0x1e9609
lfuse reads as 60
hfuse reads as 99
efuse reads as FF
details of the lfuse bits:
CKDIV8 = 0
CKOUT = 1
SUT1 = 1
SUT0 = 0
CKSEL3 = 0
CKSEL2 = 0
CKSEL1 = 0
CKSEL0 = 0
If you are unsure what the current fuse setting are on the atmega
then you can read the fuse settings with a command like:
avrdude -p m168 -c stk500v2 -v -q
The below list of fuses shows for reference purpose the settings
of a new and never programmed chip.
The result should be this (default factory settings for atmega168):
lfuse reads as 62
hfuse reads as DF
efuse reads as 1
The result should be this (default factory settings for atmega328p):
lfuse reads as 62
hfuse reads as D9
efuse reads as 7
The result should be this (default factory settings for atmega644/atmega644a):
Device signature = 0x1e9609
lfuse reads as 62
hfuse reads as 99
efuse reads as FF
Compiling on non-Unix systems
-----------------------------
Please use the provided Makefile !!!
It will also work under Windows.
Take a look at the supplied winmake.bat, winload.bat and winsetfuse.bat files.
The bat scripts might be needed to set the environment correctly in order to
use the Makefile under windows.
Edit the Makefile to make the needed adjustments at the top
of the file.
More information about Makefiles can be found at:
http://tuxgraphics.org/electronics/200912/makefiles.shtml
Using the web server
--------------------
Point your web browser to
http://10.0.0.29 (or what ever IP address you have given your hardware)
You should see a page like this:
------------------------------------------
[water] [graph] [config] [timer] [refresh]
Sensors
Temperature:26.9'C [80'F]
Humi level: 115 [normal]
------------------------------------------
(C) tuxgraphics
The temperature and humidity history graphs use javascript. You need a
javascript capable web browser to see them. Even web browsers inside
mobile phone are these days javascript capable. It should not be a
problem. The javascript code is well written and tested.
Authors/Copyright
-----------------
Most of the software was written by Guido Socher.
The ds18x20 and onewire code is taken from
http://www.siwawi.arubi.uni-kl.de/avr_projects/tempsensor/index.html
It was written by Martin Thomas and based on code of Peter Dannegger,
Colin O'Flynn and others.
Guido Socher modified the ds18x20 and one-wire code to fit to this
application.
The enc28j60 driver is based on code from Pascal Stang and updated
by Guido Socher.
All code is copyright GPL V2.
Revision history
----------------
2009-08-25: version 0.6 -- first public version
2009-09-02: version 0.7 -- minor fault in pump control code fixed
2009-09-07: version 0.8 -- clean-up buf pointer
2009-09-17: version 0.9 -- minimum graph width
2009-12-30: version 1.0 -- improved makefile
2010-02-28: version 1.1 -- new stack files, timeout if there is no sensor attached
2010-03-03: version 2.0 -- button (PB0) to locally water the plant or stop
watering
2010-06-20: version 3.0 -- add a timer function
-- clean-up code for enc28j60 B4 errata point 13
-- version 3.0 should be used with an atmega328p.
The code just fits into an atmega168 but there
is not much space left or modifications.
2010-07-01: version 3.1 -- More precise clocking and time compensation
-- Better interference resistance on manual watering
button.
2010-07-13: version 3.2 -- Show absolute time of next timer controlled watering
-- Support for atmega644
vim:sw=8:ts=8:si:et