Pages: [1]   Go Down
Author Topic: multiple arduinos, separate Processing scripts  (Read 1511 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 2
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Howdy folks,
I have several Arduinos sending serial streams that I want to log in separate Processing scripts on the same PC (using PrintWriter objects).

I've tried to set the serial COM ports on each Processing script to log serialEvent data from the different Arduinos/COM ports, which works when each Processing script is activated independently (i.e. one logs data from one Arduino and the other logs data from the other board).

However when one is running previously, the second starts intercepting serial data from the first after it is run.

Not good... ("Don't cross the streams!" I keep hearing...)

Anyone have any hints or alternative approaches?
Thanks!

eR
« Last Edit: January 19, 2011, 08:55:56 pm by BillyChildish » Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 331
Posts: 16470
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Not good... ("Don't cross the streams!" I keep hearing...)

Good one.  ;D

I don't speak Processing, but I'm pretty sure some processing ghost buster may show up to help. Offer them a cookie.

Lefty
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 547
Posts: 45997
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

When Processing starts, it gets a list of serial ports that it can listen to. How are you making the Processing application choose which serial port to listen to? (Incorrectly, I'm guessing, or you wouldn't be posting here.)

Post your code.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 2
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@PaulS
Thanks for your reply!

Hmmm... I probably did make some mistake, but I thought I took care of port assignment when initializing the serial port in the setup with "myPort = new Serial(this, Serial.list()[3], 9600);"
And for the other Arduino board/Processing script I specify the serial port corresponding to the other Arduino.
Anyway, here's the basic code.

Code:
////////////////START///////////////////////////
import processing.serial.*;    // import the Processing serial library
PrintWriter output;    // initialize the PrintWriter Java object

Serial myPort;    // the serial port

long time=0;    // initialize variable for the current time since program started
String trigTime;  // initialize variable for serial data from Arduino

void setup()
{
  // Create a new file in the sketch directory
  output = createWriter("testText.txt");
  println(Serial.list());
  myPort = new Serial(this, Serial.list()[3], 9600);
  myPort.bufferUntil('\n');
}

void draw() {      //draw() can be empty, everything's in SerialEvent
}

void serialEvent(Serial myPort) {  // use serialEvent() because of intermittent Arduino data
  time = millis();    // see how long it's been since program started

  if (time < 1200000)   // conditional for length of trial
  {
    if (myPort.available() > 0) {  // when serial data is sent from Arduino

      // read serial data of trigger times (since start of this script) from Arduino
      trigTime = myPort.readStringUntil('\n');  // use readStringUntil() to make sure we get entire serial package

      // Write the Arduino data to a file
      output.print(trigTime);  // write the output to .txt file as string (will just be number in text)
      print(trigTime);  // print trigger times to this display
    }
  }
 
  else {
  output.flush(); // Write the remaining data
  output.close(); // Finish the file
  println("END TRIAL");
  exit(); // Stop the program
  }
}
////////END//////////////

As stated above, the other Processing script is setup with a serial stream from the port corresponding to the other Arduino, and when each script is run alone, it reads from the correct Arduino. It is only when they are run together that the second one starts capturing the serial stream from both ports.

I've also tried naming the ports ("myPort1 vs myPort4") differently in the two scripts but this doesn't seem to help. Otherwise, all calls for information from serial in each script seems to refer back to the serial stream I defined in setup, so therefore I don't think I have to subsequently specify this (but maybe that's why this isn't working).

Thanks for your help!
eR
Logged

Pages: [1]   Go Up
Jump to: