I would like to make what I hope is a simple alteration to this example, I would like to save the acquired data to a file in addition to plotting it. I have altered the Processing file as follows (my additions are in red):
I have tried to declare the variable associated with the output file as type 'String' which does not work with 'createOutput' but is the correct variable type for 'saveStream'. Variable type 'Object' seems to work with 'createOutput' but does not work with 'saveStream'.
Any assistance will be greatly appreciated,
- Matt
// Graphing sketch
// This program takes ASCII-encoded strings
// from the serial port at 115200 baud and graphs them. It expects values in the
// range 0 to 1023, followed by a newline, or newline and carriage return
// Created 20 Apr 2005
// Updated 18 Jan 2008
// by Tom Igoe
// This example code is in the public domain.
import processing.serial.*;
Serial myPort; // The serial port
int xPos = 1; // horizontal position of the graph
String out1;
String out2;
void setup () {
// set the window size:
size(400, 300);
// List all the available serial ports
println(Serial.list());
// I know that the first port in the serial list on my mac
// is always my Arduino, so I open Serial.list()[0].
// Open whatever port is the one you're using.
myPort = new Serial(this, Serial.list()[0], 115200);
// don't generate a serialEvent() unless you get a newline character:
myPort.bufferUntil('\n');
// set inital background:
background(0);
// create outputs
out1=createOutput("xPosFile");
out2=createOutput("inByteFile");
}
void draw () {
// everything happens in the serialEvent()
}
void serialEvent (Serial myPort) {
// get the ASCII string:
String inString = myPort.readStringUntil('\n');
if (inString != null) {
// trim off any whitespace:
inString = trim(inString);
// convert to an int and map to the screen height:
float inByte = float(inString);
inByte = map(inByte, 0, 1023, 0, height);
// save data to a file
saveStream(out1,xPos);
saveStream(out2,inByte);
// draw the line:
stroke(127,34,255);
line(xPos, height, xPos, height - inByte);
// at the edge of the screen, go back to the beginning: