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.