nl.tue.id.creapro
Class Arduino

java.lang.Object
  extended by nl.tue.id.creapro.Arduino

public class Arduino
extends java.lang.Object

Together with the IDuino firmware (an Arduino sketch uploaded to the Arduino board), this class allows you to control the Arduino board from Processing: reading from and writing to the digital pins and reading the analog inputs, reacting on the input data when available.


Nested Class Summary
 class Arduino.SerialProxy
          This class is not intended to be used elsewhere.
 
Field Summary
static int HIGH
          Constant to write a high value (+5 volts) to a pin (in a call to digitalWrite()).
static int INPUT
          Constant to set a pin to input mode (in a call to pinMode()).
static int LOW
          Constant to write a low value (0 volts) to a pin (in a call to digitalWrite()).
static int OUTPUT
          Constant to set a pin to output mode (in a call to pinMode()).
 
Constructor Summary
Arduino(processing.core.PApplet parent, java.lang.String name)
          Create a proxy to an Arduino board running the IDuino firmware.
Arduino(processing.core.PApplet parent, java.lang.String name, int rate)
          Create a proxy to an Arduino board running the IDuino firmware.
 
Method Summary
 int analogRead(int pin)
          Reads the last known value read from the analog pin: 0 (0 volts) to 1023 (5 volts).
 void analogWrite(int pin, int value)
          Writes an analog value (PWM wave) to a pin.
 int digitalRead(int pin)
          Returns the last known value read from the digital pin: HIGH or LOW.
 void digitalWrite(int pin, int value)
          Write to a digital pin (the pin must have been put into output mode with pinMode()).
 void disableAnalogInput(int pin)
          Disables a particular analog input pin.
 void disableDigitalInput(int pin)
          Disables a particular digital input pin.
 void dispose()
          Disposes the serial proxy.
 void enableAnalogInput(int pin)
          Enables a particular analog input pin, otherwise no input from this pin will be reported to the host computer.
 void enableDigitalInput(int pin)
          Enables a particular digital input pin, otherwise no input from this pin will be reported to the host computer.
static java.lang.String[] list()
          Get a list of the available Arduino boards; currently all serial devices (i.e.
 void pinMode(int pin, int mode)
          Set a digital pin to input or output mode.
 void setAnalogPullInterval(int interval)
          Sets the analog pull interval (ms).
 void setAnalogStep(int step)
          Sets the setup of the analog input value.
 void setSerialPullInterval(int interval)
          Sets the serial pull interval (ms).
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INPUT

public static final int INPUT
Constant to set a pin to input mode (in a call to pinMode()).

See Also:
Constant Field Values

OUTPUT

public static final int OUTPUT
Constant to set a pin to output mode (in a call to pinMode()).

See Also:
Constant Field Values

LOW

public static final int LOW
Constant to write a low value (0 volts) to a pin (in a call to digitalWrite()).

See Also:
Constant Field Values

HIGH

public static final int HIGH
Constant to write a high value (+5 volts) to a pin (in a call to digitalWrite()).

See Also:
Constant Field Values
Constructor Detail

Arduino

public Arduino(processing.core.PApplet parent,
               java.lang.String name,
               int rate)
Create a proxy to an Arduino board running the IDuino firmware.

Parameters:
parent - the Processing sketch creating this Arduino board (i.e. "this").
name - the name of the serial device associated with the Arduino board (e.g. one the elements of the array returned by Arduino.list())
rate - the baud rate to use to communicate with the Arduino board.

Arduino

public Arduino(processing.core.PApplet parent,
               java.lang.String name)
Create a proxy to an Arduino board running the IDuino firmware. it uses a default baud rate 57600 to communicate with the Arduino board.

Parameters:
parent - the Processing sketch creating this Arduino board (i.e. "this").
name - the name of the serial device associated with the Arduino board (e.g. one the elements of the array returned by Arduino.list())
Method Detail

list

public static java.lang.String[] list()
Get a list of the available Arduino boards; currently all serial devices (i.e. the same as Serial.list()).

Returns:
the string[]

pinMode

public void pinMode(int pin,
                    int mode)
Set a digital pin to input or output mode.

Parameters:
pin - the pin whose mode to set (from 2 to 13)
mode - either Arduino.INPUT or Arduino.OUTPUT

digitalRead

public int digitalRead(int pin)
Returns the last known value read from the digital pin: HIGH or LOW.

Parameters:
pin - the digital pin whose value should be returned (from 2 to 13, since pins 0 and 1 are used for serial communication)
Returns:
the last known value read from the digital pin: HIGH or LOW

digitalWrite

public void digitalWrite(int pin,
                         int value)
Write to a digital pin (the pin must have been put into output mode with pinMode()).

Parameters:
pin - the pin to write to (from 2 to 13)
value - the value to write: Arduino.LOW (0 volts) or Arduino.HIGH (5 volts)

enableAnalogInput

public void enableAnalogInput(int pin)
Enables a particular analog input pin, otherwise no input from this pin will be reported to the host computer.

Parameters:
pin - the analog pin to be enabled (from 0 to 5)

disableAnalogInput

public void disableAnalogInput(int pin)
Disables a particular analog input pin. No input from this pin will be reported to the host computer after this message is received by the Arduino board.

Parameters:
pin - the analog pin to be disabled (from 0 to 5)

enableDigitalInput

public void enableDigitalInput(int pin)
Enables a particular digital input pin, otherwise no input from this pin will be reported to the host computer. When a digital pin is set to INPUT mode (Arduino.INPUT, using function pinMode(pin, mode)), it is automatically enabled.

Parameters:
pin - the digital pin to be enabled (from 2 to 13)

disableDigitalInput

public void disableDigitalInput(int pin)
Disables a particular digital input pin. No input from this pin will be reported to the host computer after this message is received by the Arduino board.

Parameters:
pin - the digital pin to be disabled (from 2 to 13)

analogRead

public int analogRead(int pin)
Reads the last known value read from the analog pin: 0 (0 volts) to 1023 (5 volts).

Parameters:
pin - the analog pin whose value should be returned (from 0 to 5)
Returns:
returns the last known value read from the analog pin.

analogWrite

public void analogWrite(int pin,
                        int value)
Writes an analog value (PWM wave) to a pin. Can be used to light a LED at varying brightnesses or drive a motor at various speeds. After a call to analogWrite, the pin will generate a steady square wave of the specified duty cycle until the next call to analogWrite (or a call to digitalRead or digitalWrite on the same pin). The frequency of the PWM signal is approximately 490 Hz. On newer Arduino boards (including the Mini and BT) with the ATmega168 chip, this function works on pins 3, 5, 6, 9, 10, and 11. Older USB and serial Arduino boards with an ATmega8 only support analogWrite() on pins 9, 10, and 11.

Parameters:
pin - the pin to write to
value - the duty cycle: between 0 (always off) and 255 (always on).

setSerialPullInterval

public void setSerialPullInterval(int interval)
Sets the serial pull interval (ms). IDuino firmware tries to check the values from the serial port every 20 ms (by default). This interval can be changed by setting a different pull interval, especially when it is not necessary to check the communication as often as every 20ms. Any value that is lower than 20ms is not recommended.

Parameters:
interval - the new serial pull interval in milliseconds (0-1023).

setAnalogPullInterval

public void setAnalogPullInterval(int interval)
Sets the analog pull interval (ms). IDuino firmware tries to check the values from the analog input pins every 20 ms (by default). This interval can be changed by setting a different pull interval, especially when it is necessary to lower the communication load to the host computer. Any value that is lower than 20ms is not recommended.

Parameters:
interval - the new analog pull interval in milliseconds (0-1023).

setAnalogStep

public void setAnalogStep(int step)
Sets the setup of the analog input value. The values from the analog pins varies from 0 to 1023, and any slight changes will be communicated to the host computer. It may result in high communication load when the analog input constantly changes. The communication load can be lowered by reducing the sensibility -- only the changes that are bigger than a given step will be reported.

Parameters:
step - the new analog step (0-1023)

dispose

public void dispose()
Disposes the serial proxy. Only to be used internally so that the serial port can be disposed properly.