[ Information Environments Equipment Listing and Support ]


EZIO Setup Instructions and Code Samples

EZIO Kits

EZIO kits can be signed out from Di's Office. Each kit should contain:
  • 1 x EZIO board
  • 1 x 12V DC Power Supply (with connector cut off)
  • 1 x DB9 Male to Female Serial Cable
  • 1 x Slotted Screwdriver
  • 1 x Wirecutters
  • Selection of LED's for testing
Please note that you will liable for replacing missing equipment if you lose it. If any equipment is damaged/not working when you recieve it, please let Di know straight away.

Setting up the Code

In order to be able to compile EZIO code, you will need the following packages:
  • Java's comm package which allows you to talk to the serial port that the EZIO is connected to [javax.comm]
  • The Ambient Interaction Framework which allows you to put/get values from the EZIO [AIF Package]
Once you have these packages, copy the javax.comm.properties file to [JAVA_HOME]/jre/lib directory and the win32com.dll file to the [JAVA_HOME]/jre/bin directory (where JAVA_HOME is the path of the JDK installed). In order to compile, ensure that both the comm.jar and ambient.jar are in your IDE's classpath.

EZIO Tips and Tricks

Before attaching sensors - ensure the EZIO is turned off at the power. This is to protect it against short circuits that may occur during sensor hookups.

If you are not getting a reading from the EZIO, check that:
On the board itself...

  • the power is on to the EZIO.
  • the sensor has been connected correctly. [Refer either to sensor connection instructions or the image below]
In your code...
  • that you are polling the right input line. [Eg. you will not get a reading if your sensor is connected to A/D line 1 and your code looks like AnalogSensor as = new AnalogSensor(EZIO, 3, 50)]
  • that javax.comm is set up correctly. [Refer to setup instructions for the EZIO code]


Sensor Hookup Diagram

Ezio diagram

Code Samples

Before attempting these - ensure that you have the javax.comm property files and the comm and ambient jar files set up correctly as outlined previously.

Checking Ports Available

The following piece of code finds the ports - serial and parallel that are available on your machine and prints out a list of their names. This comes in handy when specifying a port for the EZIO.
import javax.comm.CommPortIdentifier;
import java.util.Enumeration;

public class FindPorts {
public static void main(String[] args) {
/**
* An enumeration is similar to an array
* in that it holds a number of elements
* In this case, it is populated with any
* available ports that CommPortIdentifier can find
*/
Enumeration e = CommPortIdentifier.getPortIdentifiers(); System.out.println("Ports available:\n"); while(e.hasMoreElements()){ CommPortIdentifier cpi = (CommPortIdentifier)e.nextElement(); System.out.println("Port name: " + cpi.getName() + "\t Description: " + cpi.toString()); } } }

Analogue Input

There are 2 ways to gain sensor readings using the Ambient Interaction Framework (AIF), the first using the AnalogSensor class provided and the second by accessing the EZIO class directly. The following piece of code will loop continually on a single input line using the AnalogSensor, the best way to see this working is to connect a touch sensor and see what values are given for varying amounts of pressure on the sensor. In order for these examples to work, you will need to connect the EZIO board to COM port 1 (serial), and connect an analogue sensor to line 1 of the A/D inputs.
import edu.dstc.ambient.EZIO;
import edu.dstc.ambient.AnalogSensor;
import edu.dstc.ambient.DataValue;
import java.io.IOException;

public class AnalogIn{
public static void main(String [] args){
EZIO e;
AnalogSensor as; /* instantiate EZIO * COM1 is the serial port that you have the EZIO connected to. */ e = new EZIO("COM1"); /* instantiate AnalogSensor - e is the EZIO you have the sensor connected to * 1 is the A/D line you have the sensor connected to * 50 is how often the sensor is to be read (in milliseconds) */ try { as = new AnalogSensor(e, 1, 50); } catch (IOException e1) { as = null; System.err.println("Unable to instantiate AnalogSensor:"); e1.printStackTrace(); } while(true){ if (as != null) { /* All Sensor values are returned as DataValues */ DataValue dv = as.getValue(); /* DataValue can then be changed to: * int/long/float etc using DataValue methods */ int dvint = dv.toInt(); /* Can do a System.out here to print value, * but this is done in the as.getValue() */ } } } }

The next piece of code does the same thing, only this time accessing the EZIO directly.
import edu.dstc.ambient.EZIO;
import java.io.IOException;

public class AnalogInFromEZIO{
public static void main(String [] args){
EZIO e; /* instantiate EZIO * COM1 is the serial port that you have the EZIO connected to. */ e = new EZIO("COM1"); while(true){ try { int value = e.a2d(1); } catch (IOException e1) { System.err.println("Unable to read from line."); e1.printStackTrace(); } } } }

Digital Input

Currently the only way to access digital inputs lines is directly from the EZIO class. The following is an example of accessing a digital input. In order for this example to work you will need to connect the EZIO board to COM port 1 (serial) on your machine and connect a digital sensor (eg. a pressure mat) to Line 1 of the DIGITAL IN.
import edu.dstc.ambient.EZIO;
import java.io.IOException;

public class DigitalIN {
public static void main(String[] args) {
EZIO e = new EZIO("COM1");
while(true){
try { /* could put an explicit System.out here but readLine() does it for you * this will return a 0 if sensor activated and a 1 if not activated */ e.readLine(1); } catch (IOException e1) { System.err.println("Unable to read line."); e1.printStackTrace(); } } } }

Digital Output

As with analogue input there are two ways you can do this, through the DigitalOutput class or directly from the EZIO class. Keeping your digital sensor connected from the previous example, connect a red LED to Line 1 of the DIGITAL OUT and a green LED to Line 2. The code that follows will turn on the red LED when the sensor is deactivated and the green when activated. This code can be easily adapted to respond to analogue input.
import edu.dstc.ambient.EZIO;
import edu.dstc.ambient.DigitalOutput;
import java.io.IOException;

public class DigitalOut {
    int SENSOR_ON = 0;
    int SENSOR_OFF = 1;

    EZIO e;
    DigitalOutput RED_LED;
    DigitalOutput GREEN_LED;

    public DigitalOut(){
        e = new EZIO("COM1");
        RED_LED = new DigitalOutput(e, 1);
        GREEN_LED = new DigitalOutput(e, 2); 
        /* start with both LED's off */
        RED_LED.turnOff();
        GREEN_LED.turnOff();
    }

    public static void main(String[] args) {
          DigitalOut dop = new DigitalOut();
          dop.run();
    }

    private void run() {
        while(true){
            try {
                int valueOfSensor = e.readLine(1);
                if(valueOfSensor == SENSOR_ON){
                   /* turn red LED off and 
                    * green LED on if sensor has been activated
                    */
                    RED_LED.turnOff();
                    GREEN_LED.turnOn();
                }else if(valueOfSensor == SENSOR_OFF){
                   /* turn red LED on and 
                    * green LED off if sensor has been deactivated
                    */
                    RED_LED.turnOn();
                    GREEN_LED.turnOff();
                }else{
                    System.err.println("Sensor returning invalid value.");
                }
                /* delay loop so that you can see the LED's turning on and off. */
                delay(1000);
            } catch (IOException e1) {
                System.err.println("Error reading EZIO.");
                e1.printStackTrace();
            }
        }
    }

   /**
    * sleeps the program for a set time
    */
    private void delay(int sleep) {
        try {
            Thread.sleep(sleep);
        } catch (InterruptedException e1) {
            System.err.println("Unable to sleep thread.");
            e1.printStackTrace();
        }
    }
}
            

The following piece of code accesses the EZIO class directly.
import edu.dstc.ambient.EZIO;
import java.io.IOException;

public class DigitalOutFromEZIO {
int RED = 1;
int GREEN = 2;

int LED_ON = 1;
int LED_OFF = 0;

int SENSOR_ON = 0;
int SENSOR_OFF = 1;

EZIO e;

public static void main(String[] args) {
DigitalOutFromEZIO dofe = new DigitalOutFromEZIO();
dofe.run();
}

public DigitalOutFromEZIO(){
e = new EZIO("COM1");
try { /* start with both LED's off */ e.writeLine(RED, LED_OFF); e.writeLine(GREEN, LED_OFF); } catch (IOException e1) { System.err.println("Error writing to EZIO"); e1.printStackTrace(); } } private void run() { while(true){ try { int valueOfSensor = e.readLine(1); if(valueOfSensor == SENSOR_ON){ /* turn red LED on and * green LED off if sensor has been deactivated */ e.writeLine(RED, LED_OFF); e.writeLine(GREEN, LED_ON); }else if(valueOfSensor == SENSOR_OFF){ /* turn red LED on and * green LED off if sensor has been deactivated */ e.writeLine(RED, LED_ON); e.writeLine(GREEN, LED_OFF); }else{ System.err.println("Sensor returning invalid value."); } /* delay loop so that you can see the LED's turning on and off. */ delay(1000); } catch (IOException e1) { System.err.println("Error accessing EZIO."); e1.printStackTrace(); } } } /** * sleeps the program for a set time */ private void delay(int sleep) { try { Thread.sleep(sleep); } catch (InterruptedException e1) { System.err.println("Unable to sleep thread."); e1.printStackTrace(); } } }
© Lorna Macdonald 2003
Feel free to contact me at s4008068@student.uq.edu.au