Some Light Relief—The Java-Powered Toaster

First prize for the “most entertaining Java application of 2001” goes to Robin Southgate. For his final year project as an Industrial Design student at Brunel University in England, Robin designed and built a bread toaster. Not just any toaster though. Robin's toaster is powered by a Java program that dials a weather service, retrieves the forecast, and singes the outlook onto the toast. Examples of the toast are shown in Figure 11-3.

Figure 11-3. Java-powered toaster

image

Robin's design integrates a standard domestic toaster with the Tiny InterNet Interface (TINI) microcontroller from Dallas Semiconductor. The TINI is a $20 microcontroller chip set that supports an incredible software development platform. TINI contains a Java virtual machine, a web server, and a TCP/IP network stack running on top of a real time operating system, all in less than half a Mbyte of flash RAM. You program the chip and control the I/O to its peripherals completely in Java. The peripherals can include ethernet, a parallel port, a wireless network interface, as well as the usual RS232 serial port and I2C bus.

Robin modified the toaster so that it works automatically. When a piece of toast is put in, the microcontroller wakes up and dials out through a modem on the serial port to remotely access the weather information. The Java code then condenses the forecast into a choice between “sunny,” “overcast,” “rain,” or “snow,” and chooses the appropriate baffle to move in front of the toast heater element. The baffle is made of polytetrafluorethylene (more commonly known as “teflon” or PTFE) which is both food-safe and heat resistant at toaster temperatures. The baffle has a hole in the shape of the weather icon, exposing that area of the toast to more radiant heat than adjacent masked areas. The toast pops up in about 30 seconds with the weather icon burned onto it.

When he started on the project, Robin appealed to the TINI engineering mailing list for advice. About half the engineers made a lot of fat-headed suggestions, like using cocoa powder for toner to print on the bread. Another proposed using a CO2 laser to reduce cooking time into the 1-2 second range. They just didn't seem to be taking the project seriously. Other engineers could see the value of Java-powered toast, and gave Robin guidance on how he could refine his design.

The project involved sensing toaster operation, communicating with a remote site, decoding the data returned, moving the baffles, and controlling the toaster element. The prototype shown in Figure 11-4 needed special attention to switch the high current for the heating element safely. TINI is an excellent choice for this kind of embedded design. It has a built-in serial port that can trivially drive an external modem. There are readily available modules to monitor current, temperature, baffle position, and to switch loads. A key element with all projects is to build and debug the new design in stages rather than trying the whole thing at once. And of course, all the programming was done in Java.

Figure 11-4. Java-powered toaster

image

See www.dalsemi.com for more information on the amazingly capable Java products from Dallas Semiconductor. As one engineer on the mailing list concluded, “when it comes to domestic appliances for toast-related processing, Java has the biggest appetite.”

If, like me, you have often wondered what a Java program to control a weather-forecasting toaster looks like, here is the answer. It is just the regular “put bit patterns into ports” that comprises most embedded programming, but expressed in Java quite neatly.

//  The toaster main control program

import java.util.*;
import java.io.*;
import com.dalsemi.onewire.*;
import com.dalsemi.onewire.adapter.*;
import com.dalsemi.onewire.container.*;
import com.dalsemi.onewire.container.OneWireContainer.*;
import com.dalsemi.onewire.utils.*;
import com.dalsemi.onewire.utils.Address;

public class WeatherSwitch {

    public static void main(String args[]) {
         // details omitted...
         // contact server, get forecast
         // translate it into a command for the Switch.
    }

    public static void Switch2405(byte[] ID) {
       // "ID" is a byte array of size 8 with the address
       // of a part we have already found.
       // "access" is a DSPortAdapter
       DSPortAdapter access = new TINIExternalAdapter();
       int i=0;
       OneWireContainer05 ds2405 =
                    (OneWireContainer05) access.getDeviceContainer(ID);
       ds2405.setupContainer(access,ID);
       byte state[] = {}; // declare variable first, we'll assign it below

       try // catch exception {
         state = ds2405.readDevice();
       } catch (Exception e) {};

       // I know that the 2405 only has one channel (one switch)
       // and it doesn't support 'Smart On'
       boolean latch_state = ds2405.getLatchState(0,state);
       System.out.println("Current state of switch: "+latch_state);
       System.out.println("Current output level:" +
                                              ds2405.getLevel(0,state));
       if (!latch_state) {
           System.out.println("Toggling switch");
           ds2405.setLatchState(0,!latch_state,false,state);
           try {
               ds2405.writeDevice(state);
               state = ds2405.readDevice();
               latch_state = ds2405.getLatchState(0,state);
           } catch (Exception e) {};

           System.out.println("Current state of switch: "+latch_state);
           System.out.println("Current output level:"
                                             +ds2405.getLevel(0,state));

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.2.240