You appear to be printing to both an lcd and then sending the data to your Processing app. I presume that the lcd output is correct and that you have checked your output in SerialMonitor. As far as serial communication goes, personally I would forget the text labels "Angle: " and "h_dot: ". Furthermore, I can’t see that you ever sent the "h_dot: " label on the Arduino side by Serial, so you can’t expect to see it on the Processing side. I would send data like this:
Serial.print(firstNumber);
Serial.print(“,”); // creates comma separated values
Serial.println(secondNumber); // Note the line feed terminator.
Processing will then recreate the data string by first dividing it when it sees the linefeed. You can then split this string at the comma and reconstruct the data which you can then plot in the Processing app.
Temporarily forget about your demo and run the following to see if you can use the technique described above. If you can get this simple demo working then perhaps you can apply it to your project. Two random floats are sent by Arduino and then parsed in Processing:
Processing source code:
import processing.serial.*;
Serial myPort; // The serial port
String inStr; // Input string from serial port
int lf = 10; // ASCII linefeed
float x, y;
void setup() {
surface.setVisible(false); // Output is in console at bottom of editor
// List all the available serial ports:
printArray(Serial.list());
// Enter device number for your system
myPort = new Serial(this, Serial.list()[3], 9600);
myPort.bufferUntil(lf);
}
void draw() {
}
void serialEvent( Serial myPort) {
//'\n' (line feed) is delimiter indicating end of packet
inStr = myPort.readStringUntil('\n');
//make sure our data isn't empty before continuing
if (inStr != null) {
//trim whitespace and formatting characters (like carriage return and/or line feed)
inStr = trim(inStr); //Data is sent as a string
println("inStr = ", inStr);
String[] myData = split(inStr, ','); // String is split into array at comma
// printArray(myData);
x = Float.valueOf(myData[0]); // Array elements are converted back to floats
println("x = ", x);
y = Float.valueOf(myData[1]);
println("y = ", y);
}
}
Arduino code:
void setup() {
Serial.begin(9600);
}
void loop() {
// print a random number from 0 to 99
Serial.print(random(100));
Serial.print(','); // Comma separated values
// print a random number from 0 to 9
Serial.println(random(10)); // line feed terminated
delay(50);
}