Ok then, having some problems trying to get serial values from my Arduino to Processing, and then to write it out to a text file (and if this is sounding familiar, that's because it is; the issue that katherz and I are similar, but I have a different set of problems than she does).
- //import serial library
- import processing.serial.*;
- //initialize PrintWriter object
- PrintWriter OUTPUT;
- //array object for processed sensor values
- int sensorVal[];
- //variable for raw sensor values
- float rawSensorVal = 0.0;
- //initialize serial port object
- Serial port;
- void setup(){
- size(100,100);
- background(0);
- //list all serial values
- println(Serial.list());
- //new serial object
- port = new Serial (this, Serial.list()[0], 9600);
- port.bufferUntil('\n');
- //initialize text file to write to
- OUTPUT = createWriter("environData.txt");
- }
- void draw(){
- //write serial values to text file
- convert();
- }
- void keyPressed(){
- //press "e" key to finish and export text file
- if(key == 'e'){
- exportText();
- }
- }
- void serialEvent(Serial port) {
- //println("Serial Event Begun");
- //read serial buffer until you hit a new line character
- String myString = port.readStringUntil('\n');
- //println("String Declared and port read");
- //check to make sure string is not = null
- if (myString != null) {
- //printing out the raw values incoming
- println(myString);
- //remove whitespace
- myString = trim(myString);
- /*sensorVal[] = int(split(myString, ',')); //split the string by commas and cast as ints into int array
- for (int i = 0; i < sensorVal.length; i++) { //print out the values with their sensor names
- print("SensorVal "+i+": "+sensorVal[i]+"\t");
- */
- //convert string to float value
- rawSensorVal = float(myString);
- }
- //println();
- }
- //cast raw serial values into an array
- void processRawSerial(){
- sensorVal[] = float(split(rawSensorVal, ',')); //split the string by commas and cast as ints into int array
- }
- //write values to text file
- void convert(){
- OUTPUT.println(sensorVal);
- OUTPUT.flush();
- //println("Starting write to text");
- }
- //finish writing to text file
- void exportText(){
- OUTPUT.close();
- super.stop();
- println("data exported");
- }
So is it just a syntax error, or did I forget to put something important?
1