/* Peltier element reader & Grapher & Logger Language: Processing name: Data_logger_v6 */ import processing.serial.*; int graphPosition = 0; // the horizontal position of the latest // line to be drawn on the graph int linefeed = 10; // linefeed in ASCII Serial myPort; // The serial port int sensorValue = 0; // the value from the sensor void setup() { size(400,400); background(51); // 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 (the output // of Serial.list() can help; the are listed in order // starting with the one that corresponds to [0]). myPort = new Serial(this, Serial.list()[1], 9600); // read bytes into a buffer until you get a linefeed (ASCII 10): myPort.bufferUntil(linefeed); } void draw() { // twiddle your thumbs } // =========================================================================== // serialEvent method is run automatically by the Processing applet // whenever the buffer reaches the byte value set in the bufferUntil() // method in the setup(): void serialEvent(Serial myPort) { String filename= "logged.txt"; // Name of the file - which must exist in sketch folder // read the serial buffer: String myString = myPort.readStringUntil(linefeed); // if you got any bytes other than the linefeed: if (myString != null) { //trim off the carriage return and convert the string to an integer: sensorValue = int(trim(myString)); // print it: // println(sensorValue); drawGraph(); // save the read value to a file // fileAppend( filename, str(sensorValue)); // The call // find and print the date string String args ="123"; String tt = get_mmddyyhhmise( args ); String outstring = tt+" "+str(sensorValue); fileAppend( filename,outstring ); // The call println(outstring); delay(1000); } } // =========================================================================== void drawGraph() { // adjust this formula so that lineHeight is always less than // the height of the window: float lineHeight = map(sensorValue,0,772,0,height); // draw the line: stroke(0,255,0); line(graphPosition, height, graphPosition, height - lineHeight); // at the edge of the screen, go back to the beginning: if (graphPosition >= width) { graphPosition = 0; background(0); } else { graphPosition++; } } // =========================================================================== void fileAppend(String filename,String words) { /* Processing routine to split 'words' into a list, and add them on seperate lines at the end of the file 'filename'. */ // Split input words into a list String[] list = split(words, '&'); // read from (necessarily existing) file String[] filestuff = loadStrings(filename); // String[] newlist = new String[list.length+filestuff.length]; // add old stuff to new list for(int i=0; i < filestuff.length; i++) { newlist[i] = filestuff[i]; } // Add new stuff to new list for(int i=0; i < list.length; i++) { newlist[i+filestuff.length] = list[i]; } // then write complete array to file saveStrings(filename, newlist); } // =========================================================================== String get_mmddyyhhmise( String timestring ) { // will generate and return a space-delimited string // showing the date and time in format mm dd yy hr mi se // Must be called like this: // // String args ="123"; // String tt = get_mmddyyhhmise( args ); // println( tt ); // timestring=str(month())+" "+str(day())+" "+str(year())+" "+str(hour())+" "+str(minute())+" "+str(second()); return timestring; } // ===========================================================================