-
Notifications
You must be signed in to change notification settings - Fork 84
/
sketch_processing.pde
91 lines (76 loc) · 2.22 KB
/
sketch_processing.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
hoverboard-sidebboard-hack MPU6050 IMU - 3D Visualization Example. Use with VARIANT_DEBUG.
Copyright (C) 2020-2021 Emanuel FERU
*/
import processing.serial.*;
import java.awt.event.KeyEvent;
import java.io.IOException;
Serial myPort;
float roll, pitch,yaw;
int idx = 0;
String data="";
String check="";
void setup() {
size (1400, 800, P3D);
printArray(Serial.list()); // List all the available serial ports
myPort = new Serial(this, "COM5", 38400); // starts the serial communication
myPort.bufferUntil('\n');
}
void draw() {
// If no data is received, send 'e' command to read the Euler angles
if(idx != -1 && myPort.available() == 0) {
idx++;
if(idx > 20) {
myPort.write('e');
idx = -1;
}
} else {
idx = -1;
}
// Display text
translate(width/2, height/2, 0); //<>//
background(51);
textSize(22);
text("Roll: " + roll + " Pitch: " + pitch + " Yaw: " + yaw, -200, 300);
// Rotate the object
rotateZ(radians(roll));
rotateX(radians(pitch));
rotateY(radians(yaw));
// 3D 0bject
// Draw box with text
fill(35, 133, 54); // Make board GREEN
box (426, 30, 220);
textSize(25);
fill(255, 255, 255);
text("MPU-6050 DMP DEMO", -150, 10, 111);
// Add other boxes
translate(-70, -18, -30);
fill(100, 100, 100);
box (20, 5, 20); // MPU-6050
translate(70, 0, 0);
box (40, 5, 40); // GD32
translate(0, 0, -70);
fill(255, 255, 255);
box (50, 40, 15); // USART Main
translate(0, 0, 200);
box (50, 40, 15); // Color Led connector
translate(-60, 0, 0);
box (40, 40, 15); // Blue Led connector
}
// Read data from the Serial Port
void serialEvent (Serial myPort) {
// reads the data from the Serial Port up to the character '\n' and puts it into the String variable "data".
data = myPort.readStringUntil('\n');
// if you got any bytes other than the linefeed:
if (data != null) {
data = trim(data);
// split the string at " " (character space)
String items[] = split(data, ' ');
if (items.length > 5) {
//--- Roll,Pitch in degrees
roll = float(items[2]) / 100;
pitch = float(items[4]) / 100;
yaw = float(items[6]) / 100;
}
}
}