Data Logging from Multiple Boards to HDD

i trying store sensor data multiple arduino bords 1 text file processing programming language v2.1.1.
1. can read , store data text file arduino board program shown below. works fine.
2. wanted read data multiple boards , record in 1 text file. saved program different name , made chnages. stopped working. compared line line working program , deleted chages, still did not work.
3. surprised see insignificant change makes program unworkable. if comment-out line, program not work more. explained below.
to_txt_no_dgtl.pde
====================================
/*
*** warning: file today's date overritten ****
* receive multiple fields binary file_p
*
* portindex must set port connected arduino
* based on receivemultiplefieldsbinary, version saves data file
* press key stop logging , save file
*/
import processing.serial.*;
printwriter output;
string filenm;
string prtnm;
serial myprt, myprt1; // create object serial class
short prtindx = 2; // select com port, 0 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 present
if (ttlprt <=2) // i.e. arduino connected or not
{
println("only " + ttlprt + " com ports present.");
println("may be, arduino not connected.");
}
else
{
// open whatever serial port connected arduino.
string prtnm = serial.list()[prtindx];
println(serial.list());
println(" connecting -> " + serial.list()[prtindx]);
myprt1 = new serial(this, prtnm, 9600);
}
}
void draw()
{
if (ttlprt <=2)
exit();
else
{ // after running, first time file 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 date changes existing file closed , new file created
{
output.flush(); // writes remaining data file
output.close(); // closes 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 entire message arrive
{
if( myprt1.read() == header) // header
{
// header found
println(hr + " " + mn + " " + s + " ");
output.print(hr + ", " + mn + ", " + s + ", ");
// --------- print 6 analog port values ---------
for(int i=0; < 6; ++)
{
val = 0;
val = readarduinoint1();
println("analog port " + + "= " + 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 remaining data file
}
}
}
void keypressed()
{
output.flush(); // writes remaining data file
output.close(); // finishes file
exit(); // stops program
}
// ------- function value reading com2 ----------
// return integer value bytes received on serial port
// (in low,high order)
int readarduinoint1()
{
int val; // data received serial port
val = myprt1.read(); // read least significant byte
val = myprt1.read() * 256 + val; // add significant byte
return val;
}
// (in low,high order)
========================================
4. "if-then" loop line 101 130 works fine.
5. but, if add "else" loop working loop stops working shown below:
++++++++++++++++++++++++++++++++++++++++
if ( myprt1.available() >= 15)
{
working codes
}
else
{
println("port not available");
}
++++++++++++++++++++++++++++++++++++++++
note: curly brackets not necessary, 1 line after "else".
the idea of program adopted arduino cookbook michael margolis.
quote
i trying store sensor data multiple arduino bords 1 text file processing programming language v2.1.1.
how have multiple boards connected 1 serial port on pc?
Arduino Forum > Using Arduino > Programming Questions > Data Logging from Multiple Boards to HDD
arduino
Comments
Post a Comment