Link |Read data from the multiple Serial Ports

I am looking for how to get data from both analog0 and analog1. I found information as below at But so far it’s not working well.

import processing.serial.*;

Serial[] myPorts = new Serial[2];  // Create a list of objects from Serial class
int[] dataIn = new int[2];         // a list to hold data from the serial ports

void setup()  {
  size(400, 300);
  // print a list of the serial ports:

// get the ports' names:
  String portOne = Serial.list()[0];
  String portTwo = Serial.list()[1];
  // open the ports:
  myPorts[0] = new Serial(this, portOne, 9600);
  myPorts[1] = new Serial(this, portTwo, 9600);

void draw() {
  // clear the screen:
  // use the latest byte from port 0 for the first circle
  ellipse(width/3, height/2, 40, 40);
    // use the latest byte from port 1 for the second circle
  ellipse(2*width/3, height/2, 40, 40);

void serialEvent(Serial thisPort) {
  // variable to hold the number of the port:
  int portNumber = -1;

  // iterate over the list of ports opened, and match the
  // one that generated this event:
  for (int p = 0; p < myPorts.length; p++) {
    if (thisPort == myPorts[p]) {
      portNumber = p;
  // read a byte from the port:
  int inByte =;
  // put it in the list that holds the latest data from each port:
  dataIn[portNumber] = inByte;
  // tell us who sent what:
  println("Got " + inByte + " from serial port " + portNumber);


Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s