Silicon ChipPICAXE Net Server, Pt.3 - November 2006 SILICON CHIP
  1. Outer Front Cover
  2. Contents
  3. Publisher's Letter: Do people really want a high-performance valve amplifier?
  4. Review: Sony Alpha A100 Digital SLR Camera by Barrie Smith
  5. Review: JVC KD-AVX2 Car Entertainment System by Julian Edgar
  6. Project: Build A Radar Speed Gun, Pt.1 by Jim Rowe
  7. Project: Build Your Own Compact Bass Reflex Loudspeakers by Aaron Waplington
  8. Project: Programmable Christmas Star by David Meiklejohn
  9. Review: Bitscope BS310 Mixed Signal Oscilloscope by Peter Smith
  10. Salvage It: Using the convex lenses from car headlights (bike light) by Julian Edgar
  11. Project: DC Relay Switch For High-Current Loads by John Clarke
  12. Project: LED Tachometer With Dual Displays, Pt.2 by John Clarke
  13. Project: PICAXE Net Server, Pt.3 by Clive Seager
  14. Vintage Radio: Radio Corporation’s WS108 military transceiver by Rodney Champness
  15. Book Store
  16. Advertising Index
  17. Outer Back Cover

This is only a preview of the November 2006 issue of Silicon Chip.

You can view 37 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 "Build A Radar Speed Gun, Pt.1":
  • PCB patterns for the Radar Speed Gun (PDF download) [DOPPLR1A/DOPPLR1B] (Free)
  • Radar Speed Gun front panel artwork (PDF download) (Free)
Articles in this series:
  • Build A Radar Speed Gun, Pt.1 (November 2006)
  • Build A Radar Speed Gun, Pt.1 (November 2006)
  • Build A Radar Speed Gun, Pt.2 (December 2006)
  • Build A Radar Speed Gun, Pt.2 (December 2006)
Items relevant to "DC Relay Switch For High-Current Loads":
  • PCB pattern for the DC Relay Switch (PDF download) [05211061] (Free)
Items relevant to "LED Tachometer With Dual Displays, Pt.2":
  • LED Tachometer Control PCB [05111061] (AUD $10.00)
  • LED Tachometer Display PCB [05111062] (AUD $5.00)
  • PIC16F88-I/P programmed for the LED Tachometer [ledtacho.hex] (Programmed Microcontroller, AUD $15.00)
  • PIC16F88 firmware and source code for the LED Tachometer [ledtacho.hex] (Software, Free)
  • PCB patterns for the LED Tachometer (PDF download) [05111061/2] (Free)
  • LED Tachometer display mask (PDF download) (Panel Artwork, Free)
Articles in this series:
  • LED Tachometer With Dual Displays, Pt.1 (October 2006)
  • LED Tachometer With Dual Displays, Pt.1 (October 2006)
  • LED Tachometer With Dual Displays, Pt.2 (November 2006)
  • LED Tachometer With Dual Displays, Pt.2 (November 2006)
Items relevant to "PICAXE Net Server, Pt.3":
  • PICAXE-28X BASIC source code for the PICAXE Net Server (Software, Free)
Articles in this series:
  • PICAXE Net Server, Pt.1 (September 2006)
  • PICAXE Net Server, Pt.1 (September 2006)
  • PICAXE Net Server, Pt.2 (October 2006)
  • PICAXE Net Server, Pt.2 (October 2006)
  • PICAXE Net Server, Pt.3 (November 2006)
  • PICAXE Net Server, Pt.3 (November 2006)
  • PICAXE Net Server, Pt.4 (December 2006)
  • PICAXE Net Server, Pt.4 (December 2006)

Purchase a printed copy of this issue for $10.00.

PICAXE Net Server – Pt.3 By CLIVE SEAGER Con t r o l y ou r n ex t el ec t r on i c s p r ojec t f r om v i r t u a l l y a n y w h er e on t h e p l a n e t ! Over the last couple of months, we described how to built a demo board for the PICAXE Net Server (PNS) and then configured a home network to make it accessible over the Internet. This month, we look at building the first of two Internet-enabled demonstration projects. T HE PICAXE NET SERVER is an extremely versatile device. In theory, any application suited to electronic control could be adapted for use with the PNS, suggesting a huge range of applications. On the home front, the PNS might be used to add remote monitoring and control capabilities to a security system, control an airconditioning unit, or feed the pets, for example. 88  Silicon Chip Each new application for the PNS starts with some project design decisions. The first decision is whether you just need simple “on-off” control of output devices or you need to control an automated process. On-off control, as in the case of a pet feeder, would be direct control of a device over the Internet (eg, a relay to activate a motor to open the cat-food tray). To control the output devices (or monitor input values), you would need to build a simple interface circuit that connects directly to the input/output (I/O) pins on the PNS. An example of an automated process would be one used to control the environment in a greenhouse. In this application, temperature, light and humidity levels must be monitored continuously and heaters, fans, lights and sprinklers activated when necessary. The nature of this application demands a dedicated control system, perhaps based on a PICAXE micro. However, the PNS could still be used to monitor and remotely override the controller’s parameters (eg, adjust the temperature threshold). Depending on system’s complexity, the PNS might need to share data (such as temperature and humidity readings) with the greenhouse controller. As we’ll see later, this can be achieved siliconchip.com.au by memory sharing. Notice that in the pet feeder example, the PNS is central to the entire design, whereas in the greenhouse example, it is just one element of an overall system. Let’s study these two interfacing methods as they apply to two simple project examples, including how to generate basic web pages for the PNS to match the hardware setup. First, let’s look at the simpler interfacing method, where the PNS directly controls a motor in a cat feeder application. While you might not want to build your own cat feeder, this simple example clearly demonstrates how to use on-off control and requires only a few additional components. Remote cat feeder A basic feeder might consist of a container with a sliding lid, which is connected to a motor via a lead screw arrangement. When the lid is in position, the pet has no access to the food but when the motor is activated, the lid slides backwards (or rotates) to expose the contents. By placing a microswitch in an appropriate location, it would also be possible to verify that the lid has opened and the animal given access to the food. Jaycar Electronics stock a ready-made automatic feeder (Cat. GH-1190) with a rotating lid – perhaps it could be adapted for remote control! The circuit in Fig.1 shows how output 2 (P2) of the PNS I/O port can be used to drive the motor via a transistor and relay, while the microswitch and a 10kW pull-down resistor are connected to input 3 (P3). We’ve not produced a PC board for this simple design and it could easily be built on a prototyping board if desired. For demonstration purposes, you could also use the demo board from last month to simulate the feeder system. The green LED on the board represents the motor, while the pushbutton switch represents the microswitch. PNS web pages Having built the circuit, we’re ready to create an html web page for the PNS to serve. Fig.2 shows all that’s required: two “buttons” to start and stop the motor and a “LED” to indicate whether the switch is on or off. We’ve kept the page design (and therefore the underlying code) simple, so as siliconchip.com.au Fig.1: this simple circuit enables the PNS to control a motor-driven cat feeder device. Output 2 (P2) of the PNS I/O port is used to drive a transistor (Q1), which in turn actuates a relay to power the motor. The status of the food tray door is detected by a micro-switch, which is wired to the PNS on input 3 (P3). Variations of this circuit could be used in other applications that require basic on/off control. Fig.2: this basic web page enables us to switch the feeder motor on and off, as well as view the status of the microswitch. not to intimidate those new to html programming! This design is actually two separate sections of code which are jointed together in a frame to form one complete web page. Let’s examine the code for the left side of the frame first – see Listing 1: catout.cgi. It uses html forms to display two buttons and perform certain actions, depending on which button is clicked. In more detail, the name= property in the line <input type=hidden name=01 value=2> gives the first form its action, namely to process command “01”. Put simply, this command means “switch an output on”. The output to be switched is determined by the value= property, in this case output 2. November 2006  89 A host of other name= commands are supported by the PNS, facilitating tasks such as speaking a phase using the optional speech synthesiser or updating the message on the LCD screen. You’ll find a comprehensive command summary on page 35 of the PNS manual. Dynamic variables The code for the right half of the page (Listing 2: catin. cgi) is used to display the logic state of input 3, which is connected to the microswitch. The state of this input is retrieved and displayed via a process known as “dynamic variable substitution”. Dynamic variables are numbered from 00-99 and begin with a question mark. Variable “67” in our code equates to input 3, so “?67” will be automatically replaced with the current value of input 3 (“0” or a “1”) every time the PNS serves the web page. This means that the line will appear in your web browser as either “The value of switch 3 is 0” or “The value of switch 3 is 1”. Check out the “Dynamic HTML Generation” section of the PNS manual to find out what the other 99 variables represent! Also of note here is the line <meta http-equiv=”refresh” content=”3”>. This forces your web browser to automatically refresh the web page every three seconds, so you’ll know when the switch is pressed! Fig.3: before connecting new hardware to the PNS, it’s imperative that the I/O configuration is set correctly – otherwise, the PNS could be damaged. Here are the settings for the cat feeder. Note that only bit 2 has been changed from the original defaults. Displaying a LED graphic We’ve also added a “LED” graphic to the page. A green LED (LED0.gif) is displayed when the switch is open and a red LED (LED1.gif) when it’s closed. This is achieved with the <img src=LED?67.gif> line in the code. Again using dynamic variables, this line automatically expands to <img src=LED0.gif> when input 3 is low and <img src=LED1.gif> when input 3 is high – a simple trick for improving the visual appeal of your PNS web pages! Putting it together Fig.4: all of the files for the custom web page(s) must reside in a single folder, where the “Website” wizard will compress them prior to download to the PNS. Don’t be tempted to store other files in this folder, as they will consume unnecessary space in EEPROM. The next line generates the button for this action: <input type=submit value=”Switch motor off”>. The second html form operates similarly but uses name=00 and value=2 properties instead. Deciphered, this means “switch output 2 off”. 90  Silicon Chip All that now remains is to arrange our two sections of code so that they’ll be displayed side-by-side in a browser as one page. This is performed by a third section of code (Listing 3 – index.htm), which uses frames to achieve the task. Note that this code must reside in a file named index.htm, so named because it is the default website page. The frame border can be a useful visual aid when developing web pages but for a more professional look, you may wish to change the border value to 0 so that it is not displayed. So why use frames and two separate sections of code in the first place? Simply because we only want the input (switch) variable to be refreshed every three seconds – not the buttons! Configuring the PNS With the web page built, the next step is to configure the PNS so that the default input/output configuration suits the cat feeder hardware. To do this, run the Programming Editor and select “Setup” from the PICAXE -> Wizards -> PICAXE NetServer menu. From the default options, change input/output 2 to “Out” (3 is already an input – see Fig.3). Also, make sure siliconchip.com.au Listing 1: catout.cgi <html> <head> <title>Cat Feeder Motor</title> </head> <body> <center> Click the button to switch the motor on: <form method=get> <input type=hidden name=01 value=2> <input type=submit value="Switch motor on"> </form> Click the button to switch the motor off: <form method=get> <input type=hidden name=00 value=2> <input type=submit value="Switch motor off"> </form> </body> </html> Listing 2: catin.cgi <html> <meta http-equiv="refresh" content="3"> <head> <title>Cat Feeder Switch</title> </head> <body> <center> The value of switch 3 is ?67 <br> <img src=LED?67.gif> </body> </html> Fig.5: after compression, the new website is downloaded to the PNS via FTP. The “IP Address”, “LogonName” and “Pass­word” fields must all match those shown in the PNS Setup dialog (see Fig. 3). plete, power off and disconnect the serial cable. Downloading the web pages Listing 3: index.htm <html> <head> <title>Cat Feeder </title> </head> <frameset cols="50%,50%" frameborder=1> <frame name="left" src="catout.cgi" marginheight=2 marginwidth=2 frameborder=1> <frame name="right" src="catin.cgi" marginheight=2 marginwidth=2 frameborder=1> </frameset> </html> Listing 4: RC servo driver main: servo 4,75 loop: if input2 = 0 then loop servo 4,225 stop 'closed position 'loop waiting for input 'open position 'stop the program that the IP address settings are correct, as explained in part 1 of this series (see SILICON CHIP, September 2006). Any changes made must be downsiliconchip.com.au loaded to the PNS before they will take effect. Connect the serial cable, power up, click on “Download” and follow the on-screen instructions. Once com- We now need to update the PNS with the newly created web page. First, create a new folder on your computer and make sure that it contains the required files, which are: index. htm, catin.cgi, catout.cgi, led0.gif and led1.gif. These can be downloaded in a single zip file from the SILICON CHIP website. That done, connect the PNS to your network and power up. Again in the Programming Editor, select “Website Image” from the PICAXE -> Wizards -> PICAXE NetServer menu and navigate to the new folder just created (Fig.4). Now click on the “Compress” button to generate the PNS memory (EEPROM) image. Next, click on the “Download via FTP” button and the “FTP Transfer” window appears (Fig.5). Change the IP address to match your PNS and then click the “Connect” button. If the PNS is found, you can then click the November 2006  91 Fig.6: as well as directly driving external devices such as transistors and LEDs, the PNS I/O lines can be used as signals to trigger “smart” devices, such as a PICAXE microcontroller. Again using our cat feeder as an example, a PICAXE08M drives an RC servo to open or close the feeder door when output 2 of the PNS changes state. “Transfer” button to transfer the actual compressed image to the PNS. Moment of truth Now move back to your web browser software and type in the PNS address (in the examples given, this is 192.168.1.10). If all is well, your new web page should look like Fig.2! Verify that by clicking on the buttons, you can switch output 2 on and off, and by operating the switch, 92  Silicon Chip the logic value toggles and the LED graphic alternates between green and red. Remember, though, that the page is refreshed only every three seconds! trigger to initiate servo operation. Fig.6 shows a suitable circuit, while a matching program for the PICAXE-08M appears in Listing 4. Alternative mechanism Coming next month An alternative method of opening the feeder lid would be to use an RC-style servo controlled by a PICAXE-08M chip. In this case, the output from the PNS would be connected to an input of the PICAXE-08M and act as a Congratulations, you have now designed and developed your first PNS project! Next time around, we will build a more complex project that shares data in real-time with a PICAXE SC microcontroller! siliconchip.com.au