Data Logging from Multiple Boards to HDD

:cold_sweat:
I was trying to store sensor data from multiple Arduino bords to one text file with Processing Programming Language V2.1.1.

  1. I can read and store the data as a text file from a Arduino board with the program shown below. It works fine.

  2. I wanted to read data from multiple boards and record in one text file. I saved this program with a different name and made some chnages. It stopped working. I compared line by line with the working program and deleted the chages, still it did not work.

  3. I was surprised to see that even an insignificant change makes the program unworkable. Even if I comment-out the line, the program does not work any more. It is explained below.

To_Txt_No_Dgtl.pde

/*

*** WARNING: ANY FILE WITH TODAY’S DATE WILL BE OVERRITTEN ****

  • Receive Multiple Fields Binary To File_P
  • portIndex must be set to the port connected to the Arduino
  • based on ReceiveMultipleFieldsBinary, this version saves data to file
  • Press any key to stop logging and save file
    */

import processing.serial.*;

PrintWriter output;
String fileNm;
String prtNm;
Serial myPrt, myPrt1; // Create object from Serial class
short prtIndx = 2; // select the com port, 0 is the first port
char HEADER = β€˜H’;
int TtlPrt = 0;
int strtng, dy = 0;
int val;
String y, m, d;
String hr;
String mn;
String s;
String t;

void setup()
{
size(200, 200);
dy = day();
TtlPrt = Serial.list().length; // Counts how many com ports are present

if (TtlPrt <=2) // i.e. Arduino is connected or not
{
println(β€œOnly " + TtlPrt + " COM ports are present.”);
println(β€œMay be, Arduino is not connected.”);
}
else
{
// Open whatever serial port is connected to Arduino.
String prtNm = Serial.list()[prtIndx];
println(Serial.list());
println(" Connecting to β†’ " + Serial.list()[prtIndx]);
myPrt1 = new Serial(this, prtNm, 9600);
}
}

void draw()
{
if (TtlPrt <=2)
exit();
else
{ // After running, for the first time a file is created
if (strtng == 0 || dy != day())
{
y = str(year());
m = str(month());
d = str(day());
if (month() < 10)
m = β€œ0” + m;
if (day() < 10)
d = β€œ0” + d;

if (dy != day()) // When continuosly running, if the date changes the existing file is closed and a new file is created
{
output.flush(); // Writes the remaining data to the file
output.close(); // Closes the file
}
fileNm = (y + m + d);
output = createWriter(fileNm + β€œ.txt”);
output.println(" , " + " , " + " , " + "Room, " + " Roof, " + "S.Wall, " + "S.Wall, " + " Roof, " + "E.Wall ");
output.println("Hr, " + "Mn, " + "Sec, " + "Centre, " + " under, " + "inside, " + "otside, " + " top, " + "outside " + β€œ\n”);
strtng = 1;
dy = day();
}

hr = str(hour());
mn = str(minute());
s = str(second());
if (hour() < 10)
hr = β€œ0” + hr;
if (minute() < 10)
mn = β€œ0” + mn;
if (second() < 10)
s = β€œ0” + s;

if ( myPrt1.available() >= 15) // wait for the entire message to arrive
{
if( myPrt1.read() == HEADER) // is this the header
{
// header found
println(hr + " " + mn + " " + s + " ");
output.print(hr + ", " + mn + ", " + s + ", ");

// --------- print the six analog port values ---------

for(int i=0; i < 6; i ++)
{
val = 0;
val = readArduinoInt1();
println("analog port " + i + β€œ= " + val);
if (val <= 9)
output.print(” " + val + ", β€œ);
if (val > 9 && val < 100)
output.print(” " + val + ", β€œ);
if (val > 99 && val < 1000)
output.print(” " + val + β€œ, β€œ);
if (val > 999 && val < 10000)
output.print(” " + val + β€œ, β€œ);
if (val > 9999 && val < 100000)
output.print(” " + val + β€œ, β€œ);
}
println(”----”);
output.println(”\n”);
}
}
k = k+1;
if (k > 10)
{
k=0;
output.flush(); // Writes the remaining data to the file
}
}
}
void keyPressed()
{
output.flush(); // Writes the remaining data to the file
output.close(); // Finishes the file
exit(); // Stops the program
}

// ------- Function for value reading from COM2 ----------

// return the integer value from bytes received on the serial port
// (in low,high order)
int readArduinoInt1()
{
int val; // Data received from the serial port
val = myPrt1.read(); // read the least significant byte
val = myPrt1.read() * 256 + val; // add the most significant byte
return val;
}
// (in low,high order)

========================================

  1. The β€œif-then” loop from line 101 to 130 works fine.

  2. But, if I add an β€œelse” loop the working loop stops working as shown below:

++++++++++++++++++++++++++++++++++++++++

if ( myPrt1.available() >= 15)
{
Working codes
}
else
{
println(β€œPort is not available”);
}
++++++++++++++++++++++++++++++++++++++++

Note: The curly brackets are not necessary, as it is only one line after β€œelse”.

The idea of this program was adopted from Arduino Cookbook by Michael Margolis.

I was trying to store sensor data from multiple Arduino bords to one text file with Processing Programming Language V2.1.1.

How do you have multiple boards connected to one serial port on the PC?