[SOLVED] Serial data from Arduino Mega, ADK, UNO, but not Arduino Esplora

Hello all,

I am currently working on an Arduino/Processing project. I want to use an Arduino Esplora as a controller, and the Ardunio Mega to control outputs based on the Esplora inputs.

The current code I have is just testing code, and I can't figure out why it is not working properly. As far as I can tell, the data from the Mega is coming into Processing just fine, but the data from the Esplora is not.

Processing 2.0.3 Code:

import processing.serial.*;

int[] esploraInput = new int[16];
int[] megaInput = new int[16];

Serial esploraPort;
Serial megaPort;

void setup()
{
  size(1366, 384);
  background(255,255,255);
  println(Serial.list());
  esploraPort = new Serial(this, Serial.list()[0], 9600);
  esploraPort.bufferUntil('\n');
  megaPort = new Serial(this, Serial.list()[1], 9600);
  megaPort.bufferUntil('\n');
  println(esploraPort);
  println(megaPort);
}

void draw()
{ 
  background(255,255,255);
  textSize(32);
  fill(0, 0, 0);
  
//Output the Serial input to the Processing screen
  text("Mega Data", 10, 50);
  text("Esplora Data", 10, 150);
  for(int x = 0 ; x < 16 ; x++)
  {
    text(megaInput[x], (10+(40*x)), 100);
    text(esploraInput[x], (10+(40*x)), 200);
  }
  delay(100);
}

void serialEvent(Serial thisPort)
{
  if(thisPort == esploraPort)
  {
    println("Esplora Port");
    readEsploraPort();
  }
  if(thisPort == megaPort)
  {
    println("Mega Port");
    readMegaPort();
  }
  else
    println("Unexpected Port!");
}

void readEsploraPort()
{  
  String inputString = esploraPort.readStringUntil('\n');
  if(inputString != null)
  {
    inputString = trim(inputString);
    int tempInput[] = int(split(inputString, ','));

    if(tempInput.length == 16)
    {
      for(int x = 0 ; x < 16 ; x++)
      {
        esploraInput[x] = tempInput[x];
      }
    }
  }
}

void readMegaPort()
{
  String inputString = megaPort.readStringUntil('\n');
  
  if(inputString != null)
  {
    inputString = trim(inputString);
    int tempInput[] = int(split(inputString, ','));

    if(tempInput.length == 16)
    {
      for(int x = 0 ; x < 16 ; x++)
      {
        megaInput[x] = tempInput[x];
      }
    }
  }
}

Arduino Mega Code

//Esplora COM4
//Mega COM5

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  Serial.println("0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15");
}

Arduino Esplora Code

#include <Esplora.h>
//Esplora COM4
//Mega COM5
void setup()
{
  while(!Serial)
    Serial.begin(9600);
}

void loop()
{
  Serial.println("-15,-14,-13,-12,-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0");
}

I've been scrounging around the Internet most of the day and cannot seem to find out what is going on that would make the (nearly) identical code for the two boards be received differently. Is this something with the Esplora that I just haven't stumbled across yet?

Both sets of Arduino code output to the Arduino serial monitor properly.

I appreciate your help.

I'm replying since I changed the original code, and I understand I'm not supposed to edit code because it messes something up in how the post appears.

Now I know I'm not crazy. On a whim after my computer crashed and I switched to another (Yes, in the last 24 hours. No, it's not been a good week for my electronics.) I added an Uno and a ADK to my current system. Both of these units worked as expected.

What is going on with the Esplora outputting serial data to Processing? It outputs just fine in the Arduino serial monitor, so I don't understand what is going on in Processing. I know that the Esplora CAN be seen as a mouse/keyboard - does this have something to do with it, and if so can it be coded around?

Code is slightly modified (COM ports changed on the new system) and I added comments to the Processing code in case it wasn't as straight forward as I thought. Still haven't commented the Arduino code, but it is literally doing nothing but println(SERIAL DATA) right now.

/***********************************************/
/***   ARDUINO SERIAL PORTS FOR MY LAPTOP:   ***/
/***   COM5: Arduino UNO                     ***/
/***   COM6: Arduino ADK                     ***/
/***   COM7: Arduino Mega                    ***/
/***   COM8: Arduino Esplora                 ***/
/***********************************************/
import processing.serial.*;  //Input the Serial library

//These arrays will store the data from the Arduinos
int[] unoInput = new int[16];
int[] adkInput = new int[16];
int[] megaInput = new int[16];
int[] esploraInput = new int[16];

//Create a Serial object for each Arduino
Serial unoPort;
Serial adkPort;
Serial megaPort;
Serial esploraPort;

void setup()
{
  //Set up the screen
  size(1366, 500);
  background(255,255,255);
  
  //Print the available serial ports to the console
  println(Serial.list());
  
  //Initialize each Arduino Serial object
  unoPort = new Serial(this, Serial.list()[0], 9600);  
  adkPort = new Serial(this, Serial.list()[1], 9600);  
  megaPort = new Serial(this, Serial.list()[2], 9600);  
  esploraPort = new Serial(this, Serial.list()[3], 9600);
  
  //All the Serial data ends with a new line, so buffer until it is found
  unoPort.bufferUntil('\n');
  adkPort.bufferUntil('\n');  
  megaPort.bufferUntil('\n');  
  esploraPort.bufferUntil('\n');
  
}

void draw()
{ 
  //Blank the screen
  background(255,255,255);
  textSize(32);
  fill(0, 0, 0);
  
  //Output the Serial input to the Processing screen
  text("Uno Data", 10, 50);
  text("ADK Data", 10, 150);
  text("Mega Data", 10, 250);
  text("Esplora Data", 10, 350);
  
  for(int x = 0 ; x < 16 ; x++)
  {
    text(unoInput[x], (10+(40*x)), 100);
    text(adkInput[x], (10+(40*x)), 200);
    text(megaInput[x], (10+(40*x)), 300);
    text(esploraInput[x], (10+(40*x)), 400);
  }
  
  //I know this is bad, it will be coded out later
  delay(100);

void serialEvent(Serial thisPort)
{
  //thisPort is the port that triggered the serialEvent
  if(thisPort == unoPort)
    readUnoPort();
  if(thisPort == adkPort)
    readADKPort();
  if(thisPort == megaPort)
    readMegaPort();
  if(thisPort == esploraPort)
    readEsploraPort();
  else
    println("Unexpected Port!");
}

void readUnoPort()
{
  println("UNO Port");  
  
  //Create a string until the '\n' is found
  String inputString = unoPort.readStringUntil('\n');
  if(inputString != null)  //If the string actually is something
  {
    inputString = trim(inputString);  //Removes the '\n' and other characters
    int tempInput[] = int(split(inputString, ','));  //Split the string into the array by CSV

    if(tempInput.length == 16)  //Store the temporary array into the input array
    {
      for(int x = 0 ; x < 16 ; x++)
      {
        unoInput[x] = tempInput[x];
      }
    }
  }
}

//You can PROBABLY stop reading here, each of the following functions is the same as UNO but reading from the correct port
void readADKPort()
{ 
  println("ADK Port"); 
  
  String inputString = adkPort.readStringUntil('\n');
  if(inputString != null)
  {
    inputString = trim(inputString);
    int tempInput[] = int(split(inputString, ','));

    if(tempInput.length == 16)
    {
      for(int x = 0 ; x < 16 ; x++)
      {
        adkInput[x] = tempInput[x];
      }
    }
  }
}

void readMegaPort()
{
  println("Mega Port");
  
  String inputString = megaPort.readStringUntil('\n');
  
  if(inputString != null)
  {
    inputString = trim(inputString);
    int tempInput[] = int(split(inputString, ','));

    if(tempInput.length == 16)
    {
      for(int x = 0 ; x < 16 ; x++)
      {
        megaInput[x] = tempInput[x];
      }
    }
  }
}

void readEsploraPort()
{  
  println("Esplora Port");
  
  String inputString = esploraPort.readStringUntil('\n');
  if(inputString != null)
  {
    inputString = trim(inputString);
    int tempInput[] = int(split(inputString, ','));

    if(tempInput.length == 16)
    {
      for(int x = 0 ; x < 16 ; x++)
      {
        esploraInput[x] = tempInput[x];
      }
    }
  }
}
}

The Ardunio code. Again, all Arduinos have virtually identical code.
The code for the troublesome Esplora

#include <Esplora.h>

void setup()
{
  while(!Serial)
    Serial.begin(9600);
}

void loop()
{
  Serial.println("-15,-14,-13,-12,-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0");
}

The cooperating UNO:

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  Serial.println("32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47");
}

The cooperating Mega:

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  Serial.println("0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15");
}

The cooperating ADK:

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  Serial.println("16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31");
}

The screen shot for the Processing results is attached; I know it's not pretty, just trying to get it to work right now.

Still hoping this is something simple I've overlooked or haven't found yet.

Thanks again!

Solved - I'm an idiot and was sending a 15 element string from the Esplora instead of a 16 element string and my error trap in Processing was just doing what it was supposed to.

I'm an idiot

Thanks for letting us know. 8)

Seriously, thanks for letting us know that you solved the problem.