Differences between revisions 11 and 35 (spanning 24 versions)
Revision 11 as of 2008-10-09 20:54:10
Size: 6585
Editor: 195-241-238-88
Comment:
Revision 35 as of 2014-02-19 22:44:19
Size: 613
Editor: JunHu
Comment:
Deletions are marked like this. Additions are marked like this.
Line 2: Line 2:
<<TableOfContents>>
Line 4: Line 3:
See also CreaproJavadoc for a more formal documentation. The creapro java package ([[attachment:SoftwareDownloads/creapro.jar|creapro.jar]]) offers the library of classes and interfaces for controlling the AdMoVeo robot or the Arduino board within Processing. Read the following for more details:
Line 6: Line 5:
== Arduino in Processing ==
Together with the [[IDuino]] firmware (an Arduino sketch uploaded to the [[http://www.arduino.cc|Arduino]]board), an object of the Arduino class acts as a proxy to the [[http://www.arduino.cc|Arduino]] board, allows 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.
 * [[AdMoVeoInProcessing|AdMoVeo in Processing]]
 * [[ArduinoInProcessing|Arduino in Processing]]
 * Or you may read [[http://wiki.id.tue.nl/farm/documents/creapro/doc|the javadoc]] for a more formal documentation.
Line 9: Line 9:
Note that the core elements of the Arduino class is a Java copy or simulation of their counterparts in the [[http://arduino.cc/en/Reference/HomePage|Arduino language]]. The other elements are designed for communication and configuration purposes.

=== Static constants ===
 INPUT:: Constant to set a pin to input mode (in a call to pinMode()).
 OUTPUT:: Constant to set a pin to output mode (in a call to pinMode()).
 LOW:: Constant to write a low value (0 volts) to a pin (in a call to digitalWrite()).
 HIGH:: Constant to write a high value (+5 volts) to a pin (in a call to digitalWrite()).

=== Functions ===
==== Constructors ====
 Arduino(parent, 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.
  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())

 Arduino(parent, name, rate):: Create a proxy to an Arduino board running the IDuino firmware.
  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.

==== Configurations ====
 String [ ] Arduino.list():: Get a list of the available Arduino boards; currently all serial devices (i.e. the same as Serial.list()).
 
 enableAnalogInput(int pin):: Enables a particular analog input pin, otherwise no input from this pin will be reported to the host computer.
  pin:: the analog pin whose value should be returned (from 0 to 5).

 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.
  interval:: the new analog pull interval in milliseconds.

 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.
  step:: the new analog step.

 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.
  interval:: the new serial pull interval in milliseconds.

 pinMode(int pin, int mode):: set a digital pin to input or output mode (Arduino.INPUT or Arduino.OUTPUT).
  pin:: the pin whose mode to set (from 2 to 13).
  mode:: either Arduino.INPUT or Arduino.OUTPUT.

==== Read and Write operations ====

 int digitalRead(int pin):: returns the value of a digital pin, either Arduino.LOW or Arduino.HIGH (the pin must be set as an input).
  pin:: the digital pin whose value should be returned (from 2 to 13, since pins 0 and 1 are used for serial communication).


 digitalWrite(int pin, int value):: writes Arduino.LOW or Arduino.HIGH to a digital pin.
  pin:: the pin to write to (from 2 to 13)
  value:: either Arduino.LOW or Arduino.HIGH
  
 int analogRead(int pin):: Reads the last known value read from the analog pin: 0 (0 volts) to 1023 (5 volts).
  pin:: the analog pin whose value should be returned (from 0 to 5).
  
 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.
  pin:: the pin to write to.
  value:: the duty cycle: between 0 (always off) and 255 (always on).

=== Example ===
{{{
#!java

import processing.serial.*;
import nl.tue.id.creapro.*;

Arduino arduino;
int ledPin = 13;

void setup()
{
  println(Arduino.list());
  arduino = new Arduino(this, "COM3"); // v2
  //arduino = new Arduino(this, Arduino.list()[0], 57600); // v1
  delay(2000);
  arduino.pinMode(ledPin, Arduino.OUTPUT);
  delay(50);
  arduino.pinMode(11, Arduino.INPUT);
  delay(50);
  arduino.analogEnable(0);
  delay(50);
  arduino.setAnalogStep(4);
  delay(50);
  arduino.setAnalogPullRate(500);
  delay(50);
  println("Starting...");
// arduino.clearCommandCount();
 (new Repeat()).start();
 delay(100);

  noLoop();
}

void draw()
{
}

void digitalAvailable11(int o, int n){
  println(n);
}

void analogAvailable0(int o, int n){
  println(n);
}

class Repeat extends Thread{
  public void run(){
    arduino.clearCommandCount();
      for (int i=0; i<8; i++){
  arduino.digitalWrite(ledPin, Arduino.HIGH);
  try{sleep(400);}catch(Exception e){}
  arduino.digitalWrite(ledPin, Arduino.LOW);
  try{sleep(400);}catch(Exception e){} }
  try{sleep(2000);}catch(Exception e){}
    arduino.reportCommandCount();
    arduino.reportCommandCount();
    arduino.reportCommandCount();
    arduino.reportCommandCount();
  }

}
}}}
Following [[SoftwareEnvironment#creapro|this link]], you can find the instructions for installing the creapro package.

The creapro java package (creapro.jar) offers the library of classes and interfaces for controlling the AdMoVeo robot or the Arduino board within Processing. Read the following for more details:

Following this link, you can find the instructions for installing the creapro package.

CreaPro: CreaproProcessingLibrary (last edited 2014-02-19 22:44:19 by JunHu)