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