////////////////////////////////////////////////////////////////////////////////// // Analog signal graph writer // plots 6 analog signals, received at 9600Bps // every value comma separated on a new line // // The screen can be paused using the spacebar // pressing the space again resumes running // 'c' clears the screen // 'r' starts recording the values in a file // 's' stops recording. // everytime 'r' has been pressed a new // file 'values1.txt' with consequetive number will be made // _______________________________________________________________________________ // E.Dertien - sensors for Creative Technology - (cc) 2016 ////////////////////////////////////////////////////////////////////////////////// import processing.serial.*; int channels[] = {0, 1}; // select the channels [0..5] to print, any number, max 6 int PORTNUMBER = 1; // select the correct portnumber from the printed list int gridlines = 1; // on/off for printing gridlines int scaling = 4; // default: [0..1023] is mapped to [0..255] Serial port; // port object for serial communication String buff = ""; // input buffer for serial data int NEWLINE = '\n'; // terminator of the serial commands char header[] = { 'A', 'B', 'C', 'X', 'Y', 'Z'}; // headers for the values int linecolor[] = {0, 40, 80, 120, 160, 200}; // colors for the lines (HSB) PFont fontA; // screen font int value[] = new int[6]; // array of current received values int diffValue[] = new int[6];// array of previously received values PrintWriter output; // use file output String outputBuff = ""; // buffer for file output int filenr; // current file (incremental while the sketch is running) int offset = 0; // default: no offset in graph float timescaling = 1.0; // default: (1.0) = 25 sec time/per window float amplitude = 1.0; // default: (1.0) = 0..5 V range per window String mode="RUN"; // mode can be RUN, PAUSE or RECORD float n=21; // reset cursor position to 21.. void setup() { size(533, 286); println("Available serial ports:"); for (int i = 0; i 0) { serialEvent(port.read()); // read data } outputBuff="" + millis(); stroke(255); // clear the space for the time fill(255); // clear the space for the time rect(300, 0, 230, 12); // clear the space for the time stroke(0); fill(0); text("time "+(millis()-500)/1000.0 +" s", 300, 12); // print actual time for (int i = 0; iwidth) { n=21; background(255); // clear screen drawscreen(); } for (int z=0; z<6; z++) { diffValue[z]=value[z]; // store previous values } } void drawscreen() { stroke(255, 0, 0); line(20, height-11, width, height-11); line(20, 13, width, 13); line(20, 0, 20, height); fill(255, 0, 0); text("0.0", 2, height-7-offset); text(nf(2.5/amplitude, 1, 1), 2, (height/2+7)-offset); text(nf(5.0/amplitude, 1, 1), 2, 23-offset); text("amplitude x "+nf(amplitude, 1, 1), 50, 12); text("time x "+nf(timescaling, 1, 1), 150, 12); text("offset "+offset+ " px", 220, 12); text("0 (s)", 21, height-1); for (int n=0; n<6; n++) { text(nf((5*n)/timescaling, 0, 0), 100*n+21, height-1); } if (gridlines>0) { stroke(200); // use grey lines for (float q=19; q<280; q+=25.5) { // draw grid line(21, 0+q-offset, width, 0+q-offset); // horizontal grid lines } for (int q=20; q<520; q+=20) { //vertical grid lines line(20+q, 14, 20+q, 274); } } } void serialEvent(int serial) { try { // try-catch because of transmission errors if (serial != NEWLINE) { buff += char(serial); } else { buff = buff.substring(0, buff.length()-1); // Parse the String into an integer int[] values = int(split(buff, ',')); for (int z=0; z<2; z++) { // always all 6 values value[z] = values[z]; } buff = ""; // Clear the value of "buff" } } catch(Exception e) { println("no valid data"); } } void keyPressed() { if (key==' ' && mode=="RUN") mode="PAUSE"; else if (key==' ' && mode=="PAUSE") mode="RUN"; if (key=='r' && mode!="RECORD") { mode="RECORD"; print("Start recording..."); filenr++; output = createWriter("values"+filenr+".txt"); } if (key=='s' && mode=="RECORD") { mode="STOP"; println("ready!"); output.flush(); // Write the remaining data output.close(); // Finish the file } if (key=='c') { n=21; background(255); } if (key=='1' && amplitude>0.11) amplitude -=0.1; if (key=='2') amplitude +=0.1; if (key=='3' && timescaling > 0.11) timescaling -=0.1; if (key=='4') timescaling +=0.1; if (key=='5') offset -=1; if (key=='6') offset +=1; background(255); // clear screen drawscreen(); // redraw axes } /* // Arduino Sketch transmitting six serial values at 20 Hz int pins[] = {0, 1, 2, 3, 4, 5}; // fill in the number of pins to send unsigned long looptime; void setup() { Serial.begin(9600); } void loop() { if (millis() > looptime + 49) { // more acurate than delay(50); looptime = millis(); for (int z = 0; z < 6; z++) { Serial.print(analogRead(pins[z])); if(z<5)Serial.print(','); } Serial.println(""); } } */