# previously, the 3D display was working by reading the information from the sensor, but now the 3D display screen opens, but the figure does not appear.

**URL:** https://discourse.processing.org/t/previously-the-3d-display-was-working-by-reading-the-information-from-the-sensor-but-now-the-3d-display-screen-opens-but-the-figure-does-not-appear/43132
**Category:** Electronics (Arduino, etc.)
**Created:** [November 3, 2023, 11:34am UTC](https://discourse.processing.org/t/previously-the-3d-display-was-working-by-reading-the-information-from-the-sensor-but-now-the-3d-display-screen-opens-but-the-figure-does-not-appear/43132 "2023-11-03T11:34:03Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![S1ERRA](https://avatars.discourse-cdn.com/v4/letter/s/ecb155/32.png) [@S1ERRA](https://discourse.processing.org/u/S1ERRA)
#### Post date: [November 3, 2023, 11:34am UTC](https://discourse.processing.org/t/previously-the-3d-display-was-working-by-reading-the-information-from-the-sensor-but-now-the-3d-display-screen-opens-but-the-figure-does-not-appear/43132/1 "2023-11-03T11:34:04Z")

</div>

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

Serial myPort;

String data=“”;  
float roll, pitch;

void setup() {  
size (960, 640, P3D);  
myPort = new Serial(this, “COM255”, 9600); // starts the serial communication  
myPort.bufferUntil(‘\n’);  
}

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

// Rotate the object  
rotateX(radians(roll));  
rotateZ(radians(-pitch));

// 3D 0bject  
textSize(30);  
fill(0, 76, 153);  
box (386, 40, 200); // Draw box  
textSize(25);  
fill(255, 255, 255);  
text(" Yeditepe Otomotiv Kulübü", -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]);
}

```

}  
}

---

<div class="post-metadata">

### Author: ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)
#### Post date: [November 3, 2023, 1:36pm UTC](https://discourse.processing.org/t/previously-the-3d-display-was-working-by-reading-the-information-from-the-sensor-but-now-the-3d-display-screen-opens-but-the-figure-does-not-appear/43132/2 "2023-11-03T13:36:07Z")

</div>

Please format your source code. Use the preformatted text button on the menu bar or include your code between two sets of three graeve characters like this:

```

// your code here

```

1. For openers shouldn’t items be defined like this:

> String items = split(data, ‘/’);

1. The following source code works on my system (macOS). Note that I set the baud rate to 115,200 instead of 9600.

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

Serial myPort;

String data = "";
float roll, pitch;
float angleX, angleY;

void setup() {
  size (960, 640, P3D);
  printArray(Serial.list());
  // Open the port you are using at the rate you want:
  myPort = new Serial(this, Serial.list()[4], 115200);
  myPort.bufferUntil('\n');
}

void draw() {
  translate(width/2, height/2, 0);
  background(33);
  textSize(22);
  text("Roll: " + parseInt(roll) + " Pitch: " + parseInt(pitch), -100, 265);
  // Rotate the object
  rotateX(radians(roll));
  rotateZ(radians(-pitch));
  // 3D 0bject
  textSize(30);
  fill(0, 76, 153);
  box (386, 40, 200); // Draw box
  textSize(25);
  fill(255, 255, 255);
  text(" Yeditepe Otomotiv Kulübü", -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);
    println(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]);
    }
    
  }
}

```

**Arduino code for testing:**

```auto
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <Wire.h>

Adafruit_MPU6050 mpu;

void setup(void) {
  Serial.begin(115200);

  // Try to initialize!
  if (!mpu.begin()) {
    Serial.println("Failed to find MPU6050 chip");
    while (1) {
      delay(10);
    }
  }
  Serial.println("MPU6050 Found!");
  // set gyro range to +- 500 deg/s
  mpu.setGyroRange(MPU6050_RANGE_500_DEG);
  // set filter bandwidth to 21 Hz
  mpu.setFilterBandwidth(MPU6050_BAND_21_HZ);
  delay(100);
}

void loop() {
  /* Get new sensor events with the readings */
  sensors_event_t a,g,t;
  mpu.getEvent(&a,&g, &t);
  /* Print out the values */
  Serial.print(g.gyro.x);
  Serial.print('/');
  Serial.print(g.gyro.y);
  Serial.print('/');
  Serial.print(g.gyro.z);
  Serial.println("");
  delay(500);
}

```

**Console output:**

 ![gyro](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/b/5/b59c68d3441920e98a566ef7d4b39d86a99d5ebd.png)

The bar also rotated depending on the values.
