Processing to Arduino to I/O to RAPID

This is the workflow for using a processing sketch to arduino to a RAPID program (Thanks to Mike for this!), to create live control with the IRB140.

Here is an example processing script which sends byte commands to anĀ Arduino Duemilanove 328. The Arduino is located inside our controller and is connected to pins di5 through di16 on the I/O Board. Pins 2 – 13 map to di5 to di16.

// Processing code for Connecting to I/O Board
// This example allows you to turn on di5 and di6 using the 'a' and 'd' keys
 import processing.serial.*;
 Serial port;
 void setup() {
 size(256, 150);
 println("Available serial ports:");
 // Uses the first port in this list (number 0).  Change this to
 // select the port corresponding to your Arduino board.  The last
 // parameter (e.g. 9600) is the speed of the communication.  It
 // has to correspond to the value passed to Serial.begin() in your
 // Arduino sketch.
 //port = new Serial(this, Serial.list()[0], 9600);  
 port = new Serial(this, "COM17", 9600);  
 // If you know the name of the port used by the Arduino board, you
 // can specify it directly like this.
 //port = new Serial(this, "COM1", 9600);
 void draw() {
  //Nothing needs to happer here
 // write the current X-position of the mouse to the serial port as
 // a single byte
 void keyPressed(){
   if (key == 'a'){
   if (key == 'd'){
 void keyReleased(){

The following is an example arduino sketch which will translate the byte information sent from arduino to trigger I/O pins di5 and di6.

This example receives a byte from processing and turns the digital ins on and off
byte x = 0;
const int xPosPin = 2;      // maps to di5
const int xNegPin = 3;      // maps to di6
void setup()
  // initialize the serial communication:
  // initialize the ledPin as an output:
  pinMode(xPosPin, OUTPUT);
  pinMode(xNegPin, OUTPUT);
  digitalWrite(xNegPin, HIGH);
  digitalWrite(xPosPin, HIGH);
void loop() {
  // check if data has been sent from the computer:
  if (int(x) == 1) {
    digitalWrite(xPosPin, LOW);
    digitalWrite(xNegPin, HIGH);
  else if (int(x) == 2) {
    digitalWrite(xPosPin, HIGH);
    digitalWrite(xNegPin, LOW);
  else {
    digitalWrite(xPosPin, HIGH);
    digitalWrite(xNegPin, HIGH);
void serialEvent() {
  while (Serial.available()) {
    x =;

The following is a RAPID program which takes the pin inputs and moves the robot in the x-direction (Thanks Mike!)

MODULE Module1
	PERS tooldata MyTool:=[TRUE,[[0.0000000000,0.0000000000,127.0000000000],[1.0000000000,0.0000000000,0.0000000000,0.0000000000]],[1,[0,0,1],[1,0,0,0],0,0,0]];
	CONST robtarget Target_Home:=[[616.276853239657,1.29490244455989E-12,615.999957933775],[0.499999890452526,0,0.866025467031693,0],[0,0,0,0],[9E9,9E9,9E9,9E9,9E9,9E9]];
 	VAR robtarget Target_X;
	VAR pos Loc :=[616.276853239657,1.29490244455989E-12,615.999957933775];
PROC MoveX()
		IF Loc.x < 655 THEN
		Loc.x := Loc.x + 1;
		Target_X := [[Loc.x, Loc.y, Loc.z], [0.499999890452526,0,0.866025467031693,0], [0,0,0,0], [9E9,9E9,9E9,9E9,9E9,9E9]];
		MoveJ Target_X,v1000,z100,MyTool\WObj:=wobj0;
 PROC MoveXneg()
		IF Loc.x > 500 THEN
		Loc.x := Loc.x - 1;
		Target_X := [[Loc.x, Loc.y, Loc.z], [0.499999890452526,0,0.866025467031693,0], [0,0,0,0], [9E9,9E9,9E9,9E9,9E9,9E9]];
		MoveJ Target_X,v1000,z100,MyTool\WObj:=wobj0;
PROC main()
	MoveJ Target_Home,v1000,z100,MyTool\WObj:=wobj0;
	! Endless loop
		! Check the state of digital input 1
		IF di5 = 1 THEN
		! Else check digital input 2
		ELSEIF di6 = 1 THEN