Pages: [1]   Go Down
Author Topic: Help communicating DIY Muscle Sensor with Processing Program! [SOLVED]  (Read 1363 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


I have built a Muscle Sensor through this Instructable:

However,I am stuck in the Instructable (step 12) that shows how to Communicate the Arduino with the Computer to analyze the Data from the Sensor (which is this:

I have compiled and Uploaded the Sketch to my Arduino, I have downloaded the latest Processing, and opened the Processing Program with it.

I click on the run button but I get the following output:
Listening for transport dt_socket at address: 8819
Stable Library
Native lib Version = RXTX-2.1-7
Java lib Version   = RXTX-2.1-7
java.lang.RuntimeException: java.lang.ArrayIndexOutOfBoundsException: 1
at processing.core.PApplet.runSketch(
at processing.core.PApplet.main(
Caused by: java.lang.ArrayIndexOutOfBoundsException: 1
at AnalogVisualizationProcessing.<init>(
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(
at java.lang.reflect.Constructor.newInstance(
at java.lang.Class.newInstance0(
at java.lang.Class.newInstance(
at processing.core.PApplet.runSketch(
... 1 more

The code should at first print some variables so, since it doesn't here, it isn't an Error in communication with the Arduino or in the Arduino Program.

I am not familiar with Processing, so If anyone knows how to solve this issue, please post!

If needed, here is the Program Code: (links for the two programs in the Instructable also...)
*  By Hannah Perner-Wilson,
*  Modified 3/30/2012 By Brian E Kaminski,
*  Scroll down to set your serial port
*  Scroll down to set your thresholds

import processing.serial.*;

// definition of window size
// you can change the size of the window as you like
// the thresholdGraph will be scaled to fit
// the optimal size for the thresholdGraph is 1000 x 400
int xWidth = 1200;
int yHeight = 750;

// xPos input array, using prefix
int[] xPosArr= {0,0,0,0,0,0};

int[] messageArr= {0,0,0,0,0,0};
// Arrays for threshholding
int[] threshMax= {0,0,0,0,0,0};
int[] threshMin= {0,0,0,0,0,0};
// variables for serial connection. portname and baudrate are user specific
Serial port1;

//Set your serial port here (look at list printed when you run the application once)
String V3 = Serial.list()[1];
String portname1 = V3;
int baudrate = 9600;
int prefix = 10001;
boolean myCatch = false;
String serialIN = "";
String serialINPUT = "";
String buffer = "";
int value = 0;

// ThresholdGraph draws grid and poti states
ThresholdGraph in;

void setup(){
  // set size and framerate
  size(xWidth, yHeight);

  // establish serial port connection      
  port1 = new Serial(this, portname1, baudrate);
  port1.bufferUntil('\n') ;
  println(Serial.list());  // print serial list

  // create DisplayItems object
  in = new ThresholdGraph();
  // using the thresholdGraph you can determine the MIN and MAX values
  // of your sensors. Enter these here. They must lie between 0 and 1000.
    //MIN trashhold
    threshMin[0] = 20;   // one
    threshMin[1] = 20;   // two
    threshMin[2] = 20;   // three
    threshMin[3] = 20;   // four
    threshMin[4] = 20;   // five
    threshMin[5] = 20;   // six
    //MAX trashhold
    threshMax[0] = 600;   // one
    threshMax[1] = 600;   // two
    threshMax[2] = 600;   // three
    threshMax[3] = 600;   // four
    threshMax[4] = 600;   // five
    threshMax[5] = 600;   // six
}//end setup

// draw listens to serial port, draw
void draw(){
  // listen to serial port and trigger serial event  
  while(port1.available() > 0){
        serialIN = port1.readStringUntil('\n');
        if(serialIN != "")
          println("found empty");
  // threshold serial input  

  // draw serial input
}//end draw()

If anybody can help, I would appreciate it!
« Last Edit: September 17, 2013, 03:40:16 am by ioanna_pat » Logged

Seattle, WA USA
Offline Offline
Brattain Member
Karma: 636
Posts: 50279
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

String V3 = Serial.list()[1];
What is this going to do it there is only one item in the list? What is it going to do if the list is empty?

Here's a hint:
java.lang.RuntimeException: java.lang.ArrayIndexOutOfBoundsException: 1

Offline Offline
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I changed it to
String V3 = Serial.list()[0];

Now it works fine! Thank you very much!

Pages: [1]   Go Up
Jump to: