# MPU teapot not showing 3d model

**URL:** https://discourse.processing.org/t/mpu-teapot-not-showing-3d-model/28632
**Category:** Electronics (Arduino, etc.)
**Created:** [March 18, 2021, 5:02am UTC](https://discourse.processing.org/t/mpu-teapot-not-showing-3d-model/28632 "2021-03-18T05:02:33Z")
**Posts on this page:** 16
**Page:** 1

<div class="post-metadata">

### Author: ![ethankong](https://avatars.discourse-cdn.com/v4/letter/e/8491ac/32.png) [@ethankong](https://discourse.processing.org/u/ethankong)
#### Post date: [March 18, 2021, 5:02am UTC](https://discourse.processing.org/t/mpu-teapot-not-showing-3d-model/28632/1 "2021-03-18T05:02:34Z")

</div>

Hi, I have a teapot code that is able to receive and write out the ypr of the mpu 6050, but it is unable to make the 3d rendered modeled in processing, it just shows a new window with a white background. What am I missing, or is there something I have to change?

```auto
import processing.serial.;
import processing.opengl.;
import toxi.geom.;
import toxi.processing.;

ToxiclibsSupport gfx;

Serial port; // The serial port
char[] teapotPacket = new char[14]; // InvenSense Teapot packet
int serialCount = 0; // current packet byte position
int aligned = 0;
int interval = 0;

float[] q = new float[4];
Quaternion quat = new Quaternion(1, 0, 0, 0);

float[] gravity = new float[3];
float[] euler = new float[3];
float[] ypr = new float[3];

void setup() {
// 300px square viewport using OpenGL rendering
size(300, 300, P3D);
gfx = new ToxiclibsSupport(this);

// setup lights and antialiasing
lights();
smooth();

// display serial port list for debugging/clarity
println(Serial.list());

// get the first available port (use EITHER this OR the specific port code below)
String portName = "/dev/cu.usbmodem14101";

// get a specific serial port (use EITHER this OR the first-available code above)
//String portName = "COM4";

// open the serial port
port = new Serial(this, portName, 115200);

// send single character to trigger DMP init/start
// (expected by MPU6050_DMP6 example Arduino sketch)
port.write('r');
}

void draw() {
if (millis() - interval > 1000) {
// resend single character to trigger DMP init/start
// in case the MPU is halted/reset while applet is running
port.write(‘r’);
interval = millis();
}

// black background
background(0);

// translate everything to the middle of the viewport
pushMatrix();
translate(width / 2, height / 2);

// 3-step rotation from yaw/pitch/roll angles (gimbal lock!)
// ...and other weirdness I haven't figured out yet
//rotateY(-ypr[0]);
//rotateZ(-ypr[1]);
//rotateX(-ypr[2]);

// toxiclibs direct angle/axis rotation from quaternion (NO gimbal lock!)
// (axis order [1, 3, 2] and inversion [-1, +1, +1] is a consequence of
// different coordinate system orientation assumptions between Processing
// and InvenSense DMP)
float[] axis = quat.toAxisAngle();
rotate(axis[0], -axis[1], axis[3], axis[2]);

// draw main body in red
fill(255, 0, 0, 200);
box(10, 10, 200);

// draw front-facing tip in blue
fill(0, 0, 255, 200);
pushMatrix();
translate(0, 0, -120);
rotateX(PI/2);
drawCylinder(0, 20, 20, 8);
popMatrix();

// draw wings and tail fin in green
fill(0, 255, 0, 200);
beginShape(TRIANGLES);
vertex(-100, 2, 30); vertex(0, 2, -80); vertex(100, 2, 30); // wing top layer
vertex(-100, -2, 30); vertex(0, -2, -80); vertex(100, -2, 30); // wing bottom layer
vertex(-2, 0, 98); vertex(-2, -30, 98); vertex(-2, 0, 70); // tail left layer
vertex( 2, 0, 98); vertex( 2, -30, 98); vertex( 2, 0, 70); // tail right layer
endShape();
beginShape(QUADS);
vertex(-100, 2, 30); vertex(-100, -2, 30); vertex( 0, -2, -80); vertex( 0, 2, -80);
vertex( 100, 2, 30); vertex( 100, -2, 30); vertex( 0, -2, -80); vertex( 0, 2, -80);
vertex(-100, 2, 30); vertex(-100, -2, 30); vertex(100, -2, 30); vertex(100, 2, 30);
vertex(-2, 0, 98); vertex(2, 0, 98); vertex(2, -30, 98); vertex(-2, -30, 98);
vertex(-2, 0, 98); vertex(2, 0, 98); vertex(2, 0, 70); vertex(-2, 0, 70);
vertex(-2, -30, 98); vertex(2, -30, 98); vertex(2, 0, 70); vertex(-2, 0, 70);
endShape();

popMatrix();
}

void serialEvent(Serial port) {
interval = millis();
while (port.available() > 0) {
int ch = port.read();
print((char)ch);
if (ch == ‘') {serialCount = 0;} // this will help with alignment if (aligned < 4) { // make sure we are properly aligned on a 14-byte packet if (serialCount == 0) { if (ch == '’) aligned++; else aligned = 0;
} else if (serialCount == 1) {
if (ch == 2) aligned++; else aligned = 0;
} else if (serialCount == 12) {
if (ch == ‘\r’) aligned++; else aligned = 0;
} else if (serialCount == 13) {
if (ch == ‘\n’) aligned++; else aligned = 0;
}
//println(ch + " " + aligned + " " + serialCount);
serialCount++;
if (serialCount == 14) serialCount = 0;
} else {
if (serialCount > 0 || ch == ‘$’) {
teapotPacket[serialCount++] = (char)ch;
if (serialCount == 14) {
serialCount = 0; // restart packet byte position

                // get quaternion from data packet
                q[0] = ((teapotPacket[2] << 8) | teapotPacket[3]) / 16384.0f;
                q[1] = ((teapotPacket[4] << 8) | teapotPacket[5]) / 16384.0f;
                q[2] = ((teapotPacket[6] << 8) | teapotPacket[7]) / 16384.0f;
                q[3] = ((teapotPacket[8] << 8) | teapotPacket[9]) / 16384.0f;
                for (int i = 0; i < 4; i++) if (q[i] >= 2) q[i] = -4 + q[i];
                
                // set our toxilibs quaternion to new data
                quat.set(q[0], q[1], q[2], q[3]);

                /*
                // below calculations unnecessary for orientation only using toxilibs
                
                // calculate gravity vector
                gravity[0] = 2 * (q[1]*q[3] - q[0]*q[2]);
                gravity[1] = 2 * (q[0]*q[1] + q[2]*q[3]);
                gravity[2] = q[0]*q[0] - q[1]*q[1] - q[2]*q[2] + q[3]*q[3];
    
                // calculate Euler angles
                euler[0] = atan2(2*q[1]*q[2] - 2*q[0]*q[3], 2*q[0]*q[0] + 2*q[1]*q[1] - 1);
                euler[1] = -asin(2*q[1]*q[3] + 2*q[0]*q[2]);
                euler[2] = atan2(2*q[2]*q[3] - 2*q[0]*q[1], 2*q[0]*q[0] + 2*q[3]*q[3] - 1);
    
                // calculate yaw/pitch/roll angles
                ypr[0] = atan2(2*q[1]*q[2] - 2*q[0]*q[3], 2*q[0]*q[0] + 2*q[1]*q[1] - 1);
                ypr[1] = atan(gravity[0] / sqrt(gravity[1]*gravity[1] + gravity[2]*gravity[2]));
                ypr[2] = atan(gravity[1] / sqrt(gravity[0]*gravity[0] + gravity[2]*gravity[2]));
    
                // output various components for debugging
                //println("q:\t" + round(q[0]*100.0f)/100.0f + "\t" + round(q[1]*100.0f)/100.0f + "\t" + round(q[2]*100.0f)/100.0f + "\t" + round(q[3]*100.0f)/100.0f);
                //println("euler:\t" + euler[0]*180.0f/PI + "\t" + euler[1]*180.0f/PI + "\t" + euler[2]*180.0f/PI);
                //println("ypr:\t" + ypr[0]*180.0f/PI + "\t" + ypr[1]*180.0f/PI + "\t" + ypr[2]*180.0f/PI);
                */
            }
        }
    }
}
}

void drawCylinder(float topRadius, float bottomRadius, float tall, int sides) {
float angle = 0;
float angleIncrement = TWO_PI / sides;
beginShape(QUAD_STRIP);
for (int i = 0; i < sides + 1; ++i) {
vertex(topRadiuscos(angle), 0, topRadiussin(angle));
vertex(bottomRadiuscos(angle), tall, bottomRadiussin(angle));
angle += angleIncrement;
}
endShape();

// If it is not a cone, draw the circular top cap
if (topRadius != 0) {
    angle = 0;
    beginShape(TRIANGLE_FAN);
    
    // Center point
    vertex(0, 0, 0);
    for (int i = 0; i < sides + 1; i++) {
        vertex(topRadius * cos(angle), 0, topRadius * sin(angle));
        angle += angleIncrement;
    }
    endShape();
}

// If it is not a cone, draw the circular bottom cap
if (bottomRadius != 0) {
    angle = 0;
    beginShape(TRIANGLE_FAN);

    // Center point
    vertex(0, tall, 0);
    for (int i = 0; i < sides + 1; i++) {
        vertex(bottomRadius * cos(angle), tall, bottomRadius * sin(angle));
        angle += angleIncrement;
    }
    endShape();
}
}

```

---

<div class="post-metadata">

### Author: ![micuat](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/micuat/32/19407_2.png) [@micuat](https://discourse.processing.org/u/micuat)
#### Post date: [March 18, 2021, 10:19am UTC](https://discourse.processing.org/t/mpu-teapot-not-showing-3d-model/28632/2 "2021-03-18T10:19:58Z")

</div>

Hi! First of all can you format the code with `</>` ?

I advise you to take a look at the guideline. I want to know, if the problem is specific to serial + toxiclibs or its separable. At the moment it’s difficult to debug for others because we don’t have the same hardware.

---

<div class="post-metadata">

### Author: ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)
#### Post date: [March 18, 2021, 11:25am UTC](https://discourse.processing.org/t/mpu-teapot-not-showing-3d-model/28632/3 "2021-03-18T11:25:52Z")

</div>

> [@ethankong](#):
>
> it is unable to make the 3d rendered modeled in processing

Hello,

Please format your code as per:  
[https://discourse.processing.org/faq#format-your-code](https://discourse.processing.org/faq#format-your-code)  
I can’t look at it as is.

This appears to be a variation of code by Jeff Rowberg:  
_[i2cdevlib/Arduino/MPU6050/examples/MPU6050\_DMP6\_using\_DMP\_V6.12/MPUplane/MPUplane.pde at master · jrowberg/i2cdevlib · GitHub](https://github.com/jrowberg/i2cdevlib/blob/master/Arduino/MPU6050/examples/MPU6050_DMP6_using_DMP_V6.12/MPUplane/MPUplane.pde)_

You should _always_ credit the original author of the code.  
There is a section titled “Post Only Your Own Stuff” here:  
_[FAQ - Processing Foundation](https://discourse.processing.org/faq)_

Are you able to display just the _obj_ file in your data folder?

Modified example for P3D from:

- [rotate() / Reference / Processing.org](https://processing.org/reference/PShape_rotate_.html)\*
- [loadShape() / Reference / Processing.org](https://processing.org/reference/loadShape_.html)\*

I had to scale it and rotate it and work around a bug:

```auto
PShape s;

void setup() 
  {
  size(500, 500, P3D);
  // The file "bot.obj" must be in the data folder
  // of the current sketch to load successfully
  s = loadShape("biplane.obj");
  s.rotate(TAU/2, 0, 0, 1); //Fix for a bug in Processing to rotate around an axis
  s.scale(25, 25, 25);
  }

void draw() 
  {
  background(204);
  lights();
  translate(width/2, height/2);
  shape(s, 0, 0);
  }
  }

```

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/7/7c9a21543297cf37481d97d8941c302a1928b41b.png)

Works (some modifications) for teapot.obj as well:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/a/ac925f33726e07de21453101c0d389760efdaf26.png)

`:)`

---

<div class="post-metadata">

### Author: ![ethankong](https://avatars.discourse-cdn.com/v4/letter/e/8491ac/32.png) [@ethankong](https://discourse.processing.org/u/ethankong)
#### Post date: [March 19, 2021, 12:07am UTC](https://discourse.processing.org/t/mpu-teapot-not-showing-3d-model/28632/4 "2021-03-19T00:07:51Z")

</div>

No I am unable to display anything in there

---

<div class="post-metadata">

### Author: ![HackinHarry](https://avatars.discourse-cdn.com/v4/letter/h/3e96dc/32.png) [@HackinHarry](https://discourse.processing.org/u/HackinHarry)
#### Post date: [March 19, 2021, 11:28pm UTC](https://discourse.processing.org/t/mpu-teapot-not-showing-3d-model/28632/5 "2021-03-19T23:28:10Z")

</div>

Is your device connected when you run the processing sketch? I’ve done that before and then realize the sketch won’t work until I connect the device. Can you see output in the Serial monitor in Arduino IDE?

glv’s example sketch isn’t relying on serial.

One more thought, what is your device name? Is this linux? If so, go to /dev directory when you are connected and see your device name. For example, it might be /dev/ttyUSB0 or /dev/ttyACM0, etc. depending on the serial chip your Arduino uses.

---

<div class="post-metadata">

### Author: ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)
#### Post date: [March 20, 2021, 11:41am UTC](https://discourse.processing.org/t/mpu-teapot-not-showing-3d-model/28632/6 "2021-03-20T11:41:48Z")

</div>

> [@ethankong](#):
>
> No I am unable to display anything in there

If you format your code I can test it:  
[https://discourse.processing.org/faq#format-your-code](https://discourse.processing.org/faq#format-your-code)  
I won’t look at it as is.

`:)`

---

<div class="post-metadata">

### Author: ![ethankong](https://avatars.discourse-cdn.com/v4/letter/e/8491ac/32.png) [@ethankong](https://discourse.processing.org/u/ethankong)
#### Post date: [March 20, 2021, 12:03pm UTC](https://discourse.processing.org/t/mpu-teapot-not-showing-3d-model/28632/7 "2021-03-20T12:03:49Z")

</div>

ok i thjink i did it

---

<div class="post-metadata">

### Author: ![ethankong](https://avatars.discourse-cdn.com/v4/letter/e/8491ac/32.png) [@ethankong](https://discourse.processing.org/u/ethankong)
#### Post date: [March 20, 2021, 12:04pm UTC](https://discourse.processing.org/t/mpu-teapot-not-showing-3d-model/28632/8 "2021-03-20T12:04:53Z")

</div>

Yes my device is connected when I run the code, and I am using mac osx big sur

---

<div class="post-metadata">

### Author: ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)
#### Post date: [March 20, 2021, 2:07pm UTC](https://discourse.processing.org/t/mpu-teapot-not-showing-3d-model/28632/9 "2021-03-20T14:07:46Z")

</div>

> [@ethankong](#):
>
> ok i thjink i did it

Try to copy your code and run it and you will see why I am unable to test it.

If you properly format your code as per the link I provided anyone should be able to copy it and run it without errors.

---

<div class="post-metadata">

### Author: ![ethankong](https://avatars.discourse-cdn.com/v4/letter/e/8491ac/32.png) [@ethankong](https://discourse.processing.org/u/ethankong)
#### Post date: [March 21, 2021, 7:02am UTC](https://discourse.processing.org/t/mpu-teapot-not-showing-3d-model/28632/10 "2021-03-21T07:02:01Z")

</div>

I did format it though, or did my code not paste correctly or something?

---

<div class="post-metadata">

### Author: ![HackinHarry](https://avatars.discourse-cdn.com/v4/letter/h/3e96dc/32.png) [@HackinHarry](https://discourse.processing.org/u/HackinHarry)
#### Post date: [March 21, 2021, 9:50pm UTC](https://discourse.processing.org/t/mpu-teapot-not-showing-3d-model/28632/11 "2021-03-21T21:50:54Z")

</div>

Well, I asked if you are able to run serial monitor in the Arduino IDE and see output because from what I read, on a mac, if it can do that then Processing makes use of the same driver. A blank screen seems to suggest that Processing isn’t connecting.

---

<div class="post-metadata">

### Author: ![ethankong](https://avatars.discourse-cdn.com/v4/letter/e/8491ac/32.png) [@ethankong](https://discourse.processing.org/u/ethankong)
#### Post date: [March 22, 2021, 5:49am UTC](https://discourse.processing.org/t/mpu-teapot-not-showing-3d-model/28632/12 "2021-03-22T05:49:34Z")

</div>

Yes, I am able to see all the ypr info in the serial monitor of arduino.

---

<div class="post-metadata">

### Author: ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)
#### Post date: [March 22, 2021, 10:30am UTC](https://discourse.processing.org/t/mpu-teapot-not-showing-3d-model/28632/13 "2021-03-22T10:30:20Z")

</div>

> [@ethankong](#):
>
> I did format it though, or did my code not paste correctly or something?

Hello,

Take a good look at what you posted in the topic and [scrutinize](https://www.merriam-webster.com/dictionary/scrutinize) it; there is a long line that shows up in red.

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/e/e942ddf63ad3d7db3e0b4d317631a0e4ca577718.png)

Try to copy it from the forum and back into Processing and you will see the issues.

You can edit the original post.  
Format it (original working code) in Processing first.  
Test it and ensure that it is working code.  
Paste it again as per instructions on how to “Format new code”.  
If you “Format existing code” it may not work properly.

`:)`

---

<div class="post-metadata">

### Author: ![HackinHarry](https://avatars.discourse-cdn.com/v4/letter/h/3e96dc/32.png) [@HackinHarry](https://discourse.processing.org/u/HackinHarry)
#### Post date: [March 22, 2021, 11:04pm UTC](https://discourse.processing.org/t/mpu-teapot-not-showing-3d-model/28632/14 "2021-03-22T23:04:36Z")

</div>

Can you try your sketch(using appropriate device port name)on a different platform like windows10? If it works on Windows then you know your code is good and working. If it doesn’t work there either, then go to another area of the troubleshooting flowchart. 😉

---

<div class="post-metadata">

### Author: ![ethankong](https://avatars.discourse-cdn.com/v4/letter/e/8491ac/32.png) [@ethankong](https://discourse.processing.org/u/ethankong)
#### Post date: [March 23, 2021, 5:58am UTC](https://discourse.processing.org/t/mpu-teapot-not-showing-3d-model/28632/15 "2021-03-23T05:58:06Z")

</div>

ok I’ll try it tonight Thanks.

---

<div class="post-metadata">

### Author: ![syedsulaiman7](https://avatars.discourse-cdn.com/v4/letter/s/dfb087/32.png) [@syedsulaiman7](https://discourse.processing.org/u/syedsulaiman7)
#### Post date: [June 30, 2022, 5:52pm UTC](https://discourse.processing.org/t/mpu-teapot-not-showing-3d-model/28632/16 "2022-06-30T17:52:29Z")

</div>

did you get it working on Mac OS??  
the code is working fine on windows 10 but not on Mac OS the 3d object is not displaying but the values are being correctly read by the system
