Arduino serial port to Processing CSV gibberish

Hi, I'm new to both Arduino and Processing. I have looked through the forum but have found no question or reply on this.

I am reading light sensor data through an Arduino.
Code:

#include <Wire.h>
#include <BH1750.h>
#include <DS3231.h> //RTC library

DS3231  rtc(SDA, SCL);
 
BH1750 lightMeter;
 
 
void setup(){
  Serial.begin(9600);
  lightMeter.begin();
  //Serial.println("Running...");
  rtc.begin(); // intialize clock
}
 
void loop() {
  uint16_t lux = lightMeter.readLightLevel();

  if (lux) {
   Serial.print( rtc.getDateStr());
   Serial.print(", ");
   Serial.print(rtc.getTimeStr());
   Serial.print(", ");
   Serial.println(lux); 

     delay(1000);
  }
}

Then I want Processing to record a CSV file with this data.
Code:

import processing.serial.*;
Serial mySerial;
PrintWriter output;
void setup() {
   mySerial = new Serial( this, Serial.list()[2], 9600 );
   output = createWriter( "30.07.2016 lux.csv" );
}
void draw() {
    if (mySerial.available() > 0 ) {
         String value = mySerial.readString();
         if ( value != null ) {
              output.println( value );
         }
    }
}

void keyPressed() {
    output.flush();  // Writes the remaining data to the file
    output.close();  // Finishes the file
    exit();  // Stops the program
}

It writes the file ok, but the actual data logged is messed up. It should record each value neatly on 3 columns, and on the next row for the next set of data, and so on. And it does, for the first few lines. Then it starts cutting data and skipping rows and cells.
I'm using an OpenOffice version of Excel (which displays asian characters on the CSV) but I have also tried to open the file in Google Docs, which is where I get the cut up results.
The same happens in I record a txt file. The first few lines are great, then it's all cut up.
Any suggestions or hints as to what it is that I am doing wrong? Any help greatly appreciated.
Thanks

try using readBytes() and write them verbatim to the file. readBytes() / Libraries / Processing.org

blimpyway:
try using readBytes() and write them verbatim to the file. readBytes() / Libraries / Processing.org

I have just tried that but it gives me the same result, on the Processing serial (println(myString)) and on the data.txt created. A few good lines, then its all cut up again.

This is an example of the results:
30.0.2016, 15:30:06, 920.00
936.00
30.07.2016, 15:30:03, 929.00
30.07.2016, 15:30:04, 920.00
30.07.2016, 15:30:05, 922.00
30.07.2016, 15:30:06, 920.00
936.00
30.07.2016, 15:30:03, 929.00
30.07.2016, 15:30:04, 920.00
30.07.2016, 15:30:05, 922.00
30.07.2016, 15:30:06, 920.00

30.07.2016,
15:30:08, 927.0
0

07.2016, 15:30:0
9, 953.00

30.07.2016, 15:
30:10, 954.00

30.07.2016
, 15:30:11,
931.00

30
.07.2016, 15:30:
13, 927.00

So, I've kept tweaking readBytes() but no result was ordered. Any idea where the problem might lie?
Thanks.

I don't know Processing but I think I saw a Reply elsewhere in which it was said that draw() is not suitable for receiving data and you should use serialEvent().

Google for other Processing Threads in the Forum.

...R

Robin2:
I don't know Processing but I think I saw a Reply elsewhere in which it was said that draw() is not suitable for receiving data and you should use serialEvent().

That means I was lucky to pick a serialEvent() example the first time I used Processing to read data from arduino. 40-50 lines/sec, 100-130 bytes each, data flow saved on file while displaying dozens of numbers - almost no problem except (occasionally) a line at the beginning of communication that is simply discarded.

PS But I think you could benefit more from using readStringUntil('\n') instead of readString() - which doesn't have any idea you want full strings between two new lines, - if you get a partial line, then you should not println it.
That was also in that first example I was lucky to read before any attempt to do it myself