Code.DataloggerMulti History

Hide minor edits - Show changes to output

Changed lines 13-14 from:
(;source lang="arduino" tabwidth=4:)
to:
(:source lang="processing" tabwidth=4:)
Changed line 13 from:
[@
to:
(;source lang="arduino" tabwidth=4:)
Changed line 15 from:
Datalogger multi
to:
Grapher multi
Changed lines 127-128 from:
@]
to:
(:sourceend:)
Changed lines 1-2 from:
By [[[[~tigoe]]|Tom Igoe]]
to:
By [[~tigoe|Tom Igoe]]
Added lines 1-2:
By [[[[~tigoe]]|Tom Igoe]]
Changed lines 3-4 from:
See also Jen Kirchherr's variation on this, which graphs all three values simultaneously.
to:
See also [[Code.Multi|Jen Kirchherr's variation]] on this code, which graphs all three values simultaneously.
Added lines 3-4:
See also Jen Kirchherr's variation on this, which graphs all three values simultaneously.
Added lines 9-10:
Deleted line 0:
Added lines 5-6:
Added lines 1-3:

This Processing example reads three sensors and graphs one of them, but allows the user to choose which one by typing the appropriate sensor label.
Changed lines 1-2 from:
Back to [[Reports.MMA7260Q 3-Axis Accelerometer Report]]
to:
Back to [[Reports.MMA7260Q |3-Axis Accelerometer Report]]
Added lines 1-2:
Back to [[Reports.MMA7260Q 3-Axis Accelerometer Report]]
Added lines 1-116:
[@
/*
Datalogger multi
by Tom Igoe

This program takes a string of three bytes from the serial port at 9600 baud
and graphs one of them.
Typing "x" causes the program to graph the first byte in the string
Typing "y" causes the program to graph the second byte in the string
Typing "z" causes the program to graph the third byte in the string

The program sends out a single byte, value 65 ("A") to get the remote device
to send a string.

Created 20 April 2005
Updated 28 August 2005
*/

import processing.serial.*;

Serial myPort; // The serial port
int[] serialInArray = new int[3]; // Where we'll put what we receive
int serialCount = 0; // A count of how many bytes we receive

// initial variables:
int i = 1; // counter
int inByte = -1; // data from serial port

int xpos, ypos, zpos = 0;

boolean firstContact = false;

void setup () {
size(400, 300); // window size

// List all the available serial ports
println(Serial.list());
// I know that the third port in the serial list on my mac
// is always my Keyspan adaptor, so I open Serial.list()[0].
// Open whatever port is the one you're using.
myPort = new Serial(this, Serial.list()[0], 9600);

// set inital background:
background(0);

// send initial byte:
myPort.write(65); // Send a capital A to start the microcontroller sending

}
void draw () {
while (myPort.available() > 0) {
processByte(myPort.read());
// Note that we heard from the microntroller:
firstContact = true;
}
// If there's no serial data, send again until we get some.
// (in case you tend to start Processing before you start your
// external device):
if (firstContact == false) {
delay(300);
myPort.write(65);
}


}

void drawGraph () {
int valueToGraph = 0;
// decide which value to graph:
if (keyCode == 88) { //x
valueToGraph = xpos;
stroke(255,0,0);
}
if (keyCode == 89) { //y
valueToGraph = ypos;
stroke(0,255,0);
}
if (keyCode == 90) { //z
valueToGraph = zpos;
stroke(0,0,255);
}
// draw the line:

line(i, height, i, height - valueToGraph);

// at the edge of the screen, go back to the beginning:
if (i >= width-2) {
i = 0;
background(0);
}
else {
i++;
}

}

void processByte( int inByte) {
// Add the latest byte from the serial port to array:
serialInArray[serialCount] = inByte;
serialCount++;
// If we have 3 bytes:
if (serialCount > 2 ) {
xpos = serialInArray[0];
ypos = serialInArray[1];
zpos = serialInArray[2];
// println(xpos + "\t" + ypos + "\t" + zpos);
drawGraph();
// Send a capital A to request new sensor readings:
myPort.write(65);
// Reset serialCount:
serialCount = 0;
}
}


@]