Alright, so far I have been having issues with this
On processing I have:
import processing.serial.*;
float[] val = {};
Serial port;
int len = 1200; // set length
int wid = 700; // set width
float x, y;
float px = 600;
float py = 350;
void setup() {
size(1200,700);
port = new Serial (this, "COM12", 115200);
port.bufferUntil('\n');
}
void serialEvent(final Serial port) {
val = float(splitTokens(port.readString()));
redraw = true;
}
void draw(){
gyroline();
}
void gyroline() {
//...
x = val[0];
y = val[1];
line(px, py, x + px, y + py);
px = x;
py = y;
print(x); println(y); // for debugging
}
However this gives me “ArrayIndexOutOfBoundsException 0”
And for reference’s sake, here’s my Arduino (but only the loop() part):
//...
void loop() {
mpu.getMotion6(&rawaccx, &rawaccy, &rawaccz, &rawgyrx, &rawgyry, &rawgyrz);
getaccel(rawaccx, rawaccy, rawaccz);
Serial.print(realaccx); Serial.write("\t"); // TSV
Serial.print(realaccy); Serial.write("\t"); // TSV
Serial.println('\n'); // NEWLINE
delay(10);
}
Please reply soon
Thank you
EDIT: I’ve been trying to work on a solution while reading the links you sent and I have this. Now i am getting NullPointerException
import processing.serial.*;
String index;
float[] val;
Serial port;
int len = 1200; // set length
int wid = 700; // set width
float x, y;
float px = 600;
float py = 350;
void setup() {
noLoop();
final String[] port = Serial.list();
// port = new Serial (this, "COM12", 115200);
new Serial(this, "COM12", 115200).bufferUntil('\n');
// port.bufferUntil('\n');
}
void serialEvent(final Serial port) {
val = float(splitTokens(port.readString()));
redraw = true;
}
void draw() {
while (port.available() > 0) {
String input = port.readString();
val = float(splitTokens(input));
gyroline();
}
}
void gyroline() {
//...
x = val[0];
y = val[1];
line(px, py, x + px, y + py);
px = x;
py = y;
print(x);
println(y);
}