IO-web server as "remote switch" aka ETH-web-switch
AVR I/O-web server with additional output pins via a 74hc595 port expander


For more documentation on AVR web servers see http://tuxgraphics.org/electronics/

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

The digial output pins on the microcontroller that can be switched on/off over the web are: PD4, PD5, PD6 and PD7

8 additional output lines are available if you connect a 74hc595 as follows:
74hc595 SER pin 14 = atmega PORTC5
74hc595 RCLK pin 12 = atmega PORTC4
74hc595 SRCLK pin 11 = atmega PORTC3

You need to uncomment the USE_74595 in the file main.c

// uncomment to use the port expander via 74hc595
#define USE_74595 1

License

Copyright of the software and all diagrams: Guido Socher, tuxgraphics.org

License for everything: GPL V2
See http://www.gnu.org/licenses/gpl.html
Other licenses are available on request.




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

// uncomment to use the port expander via 74hc595
#define USE_74595 1

Check the file "Makefile" and make sure the MCU is set correctly.
This software supports 4 different CPUs:

 MCU=atmega88
 DUDECPUTYPE=m88
 or
 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

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). myip must be a
free address from the address range in your home network.

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).

You need an avr-gcc development environment in order to compile this.
See http://tuxgraphics.org/electronics/200901/avr-gcc-linux.shtml

To compile the software use the command:
make

Note: windows users may use and modify the supplied winmake.bat script.

The command
make load

Note: windows users may use and modify the supplied winload.bat script.

will execute the avrdude command to load the main.hex software (remote relay
switch on/off software, compiled from main.c).
E.g something like: 
   avrdude -p m88 -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 after programming should be as below (the efuse has some unused 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 and winload.bat file. The bat script 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 Hardware -------- The this software runs on any tuxgraphics ethernet board and you can switch the output pins PD4, PD5, PD6 and PD7 using a web browser. If you want to drive a relay in order to switch higher loads then you would need a relay driver stage as described in the diagram in the hardware sub-directory 8 additional output lines are available if you connect a 74hc595 as follows: 74hc595 SER pin 14 = atmega PORTC5 74hc595 RCLK pin 12 = atmega PORTC4 74hc595 SRCLK pin 11 = atmega PORTC3 Using it from a shell script ---------------------------- #!/bin/sh stateofsw2=`lynx -dump http://10.0.0.29/secret/sw2=x` echo "switch 2 is $stateofsw2" Revision history ---------------- 2010-08-22: version 1.0 -- first version. The code is based on eth_tcp_client_server-4.3
vim:sw=8:ts=8:si:et