0% found this document useful (0 votes)
116 views2 pages

Arduino and MPU-WPS Office

This document describes an Arduino sketch that uses an MPU6050 IMU sensor to measure the roll, pitch, and yaw of an object in 3D space. It uses the Serial library to receive orientation data from the sensor and displays a 3D visualization of the object rotating in Processing based on the measured angles. The sketch reads the sensor data, splits it by slashes, converts it to floats, and uses them to rotate a box graphic and display the orientation values.

Uploaded by

Wahid Nur Rohman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
116 views2 pages

Arduino and MPU-WPS Office

This document describes an Arduino sketch that uses an MPU6050 IMU sensor to measure the roll, pitch, and yaw of an object in 3D space. It uses the Serial library to receive orientation data from the sensor and displays a 3D visualization of the object rotating in Processing based on the measured angles. The sketch reads the sensor data, splits it by slashes, converts it to floats, and uses them to rotate a box graphic and display the orientation values.

Uploaded by

Wahid Nur Rohman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

/*

Arduino and MPU6050 IMU - 3D Visualization Example


by Dejan, https://howtomechatronics.com
*/

import processing.serial.*;
import java.awt.event.KeyEvent;
import java.io.IOException;

Serial myPort;

String data="";
float roll, pitch,yaw;

void setup() {
size (2560, 1440, P3D);
myPort = new Serial(this, "COM7", 19200); // starts the serial communication
myPort.bufferUntil('\n');
}

void draw() {
translate(width/2, height/2, 0);
background(233);
textSize(22);
text("Roll: " + int(roll) + " Pitch: " + int(pitch), -100, 265);

// Rotate the object


rotateX(radians(-pitch));
rotateZ(radians(roll));
rotateY(radians(yaw));

// 3D 0bject
textSize(30);
fill(0, 76, 153);
box (386, 40, 200); // Draw box
textSize(25);
fill(255, 255, 255);
text("www.HowToMechatronics.com", -183, 10, 101);

//delay(10);
//println("ypr:\t" + angleX + "\t" + angleY); // Print the values to check
whether we are getting proper values
}

// Read data from the Serial Port


void serialEvent (Serial myPort) {
// reads the data from the Serial Port up to the character '.' 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 "/"
String items[] = split(data, '/');
if (items.length > 1) {

//--- Roll,Pitch in degrees


roll = float(items[0]);
pitch = float(items[1]);
yaw = float(items[2]);
}
}
}

You might also like