How to display 16-bits of MPU6050 in serial monitor of arduino

Hi there, I'm a new comer in this forum. I've worked on my project that uses two MPU6050 with an arduino to display the angle between the two MPUs. I already used the code from J. Rowberg with some additions to fit in with my project.

Here's the code

#include "I2Cdev.h"
#include "MPU6050_Wrapper.h"
#include "TogglePin.h"
#include "DeathTimer.h"

// Arduino Wire library is required if I2Cdev I2CDEV_ARDUINO_WIRE implementation
// is used in I2Cdev.h
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
#include "Wire.h"
#endif


/* =========================================================================
  NOTE: In addition to connection 3.3v, GND, SDA, and SCL, this sketch
  depends on the MPU-6050's INT pin being connected to the Arduino's
  external interrupt #0 pin. On the Arduino Uno and Mega 2560, this is
  digital I/O pin 2.
   ========================================================================= */

/* =========================================================================
  NOTE: Arduino v1.0.1 with the Leonardo board generates a compile error
  when using Serial.write(buf, len). The Teapot output uses this method.
  The solution requires a modification to the Arduino USBAPI.h file, which
  is fortunately simple, but annoying. This will be fixed in the next IDE
  release. For more info, see these links:

  http://arduino.cc/forum/index.php/topic,109987.0.html
  http://code.google.com/p/arduino/issues/detail?id=958
   ========================================================================= */

// uncomment "OUTPUT_READABLE_QUATERNION" if you want to see the actual
// quaternion components in a [w, x, y, z] format (not best for parsing
// on a remote host such as Processing or something though)
//#define OUTPUT_READABLE_QUATERNION
// uncomment "OUTPUT_READABLE_EULER" if you want to see Euler angles
// (in degrees) calculated from the quaternions coming from the FIFO.
// Note that Euler angles suffer from gimbal lock (for more info, see
// http://en.wikipedia.org/wiki/Gimbal_lock)
//#define OUTPUT_READABLE_EULER
// uncomment "OUTPUT_READABLE_YAWPITCHROLL" if you want to see the yaw/
// pitch/roll angles (in degrees) calculated from the quaternions coming
// from the FIFO. Note this also requires gravity vector calculations.
// Also note that yaw/pitch/roll angles suffer from gimbal lock (for
// more info, see: http://en.wikipedia.org/wiki/Gimbal_lock)
#define OUTPUT_READABLE_YAWPITCHROLL
//#define OUTPUT_READABLE_PITCHROLL

// uncomment "OUTPUT_READABLE_REALACCEL" if you want to see acceleration
// components with gravity removed. This acceleration reference frame is
// not compensated for orientation, so +X is always +X according to the
// sensor, just without the effects of gravity. If you want acceleration
// compensated for orientation, us OUTPUT_READABLE_WORLDACCEL instead.
//#define OUTPUT_READABLE_REALACCEL

// uncomment "OUTPUT_READABLE_WORLDACCEL" if you want to see acceleration
// components with gravity removed and adjusted for the world frame of
// reference (yaw is relative to initial orientation, since no magnetometer
// is present in this case). Could be quite handy in some cases.
//#define OUTPUT_READABLE_WORLDACCEL

// uncomment "OUTPUT_TEAPOT" if you want output that matches the
// format used for the InvenSense teapot demo
//#define OUTPUT_TEAPOT


#ifdef OUTPUT_TEAPOT
// Teapot demo can only output from one MPU6050
const bool useSecondMpu = false;
MPU6050_Array mpus(1);
#else
const bool useSecondMpu = true;
MPU6050_Array mpus(useSecondMpu ? 2 : 1);
#endif

#define AD0_PIN_0 4  // Connect this pin to the AD0 pin on MPU #0
#define AD0_PIN_1 5  // Connect this pin to the AD0 pin on MPU #1

#define LED_PIN 13 // (Arduino is 13, Teensy is 11, Teensy++ is 6)

#define OUTPUT_SERIAL Serial
//#define OUTPUT_SERIAL Serial2
//#define OUTPUT_SERIAL softSerial


uint8_t fifoBuffer[64]; // FIFO storage buffer

// orientation/motion vars
Quaternion q;        // [w, x, y, z]         quaternion container
VectorInt16 aa;      // [x, y, z]            accel sensor measurements
VectorInt16 aaReal;  // [x, y, z]            gravity-free accel sensor measurements
VectorInt16 aaWorld; // [x, y, z]            world-frame accel sensor measurements
VectorFloat gravity; // [x, y, z]            gravity vector
float euler[3];      // [psi, theta, phi]    Euler angle container
float ypr[3];        // [yaw, pitch, roll]   yaw/pitch/roll container and gravity vector

// packet structure for InvenSense teapot demo
uint8_t teapotPacket[14] = { '

the code above is a literally code from Mr. J. Rowberg (not a full code and does not include my additions). So, the question is "how can I put the millisecond to count every data that show up in serial monitor? and what should I do, if I'd like to put every bit that has been translated by MPUs and put it beside the angle values? (so the output shows the angle in raw values and also in bit values)"

Thanks and best regards,

Ismail., 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0x00, 0x00, '\r', '\n' };

TogglePin activityLed(LED_PIN, 100); DeathTimer deathTimer(5000L);

// ================================================================ // ===                      INITIAL SETUP                       === // ================================================================

void setup() {  // join I2C bus (I2Cdev library doesn't do this automatically)

if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE

 Wire.begin();  Wire.setClock(400000); // 400kHz I2C clock. Comment this line if having compilation difficulties

elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE

 Fastwire::setup(400, true);

endif

 // initialize serial communication  // (115200 chosen because it is required for Teapot Demo output, but it's  // really up to you depending on your project)  Serial.begin(115200);

 while (!Serial)    ; // wait for Leonardo enumeration, others continue immediately

 // NOTE: 8MHz or slower host processors, like the Teensy @ 3.3v or Ardunio  // Pro Mini running at 3.3v, cannot handle this baud rate reliably due to  // the baud timing being too misaligned with processor ticks. You must use  // 38400 or slower in these cases, or use some kind of external separate  // crystal solution for the UART timer.

 // initialize device  Serial.println(F("Initializing I2C devices..."));  mpus.add(AD0_PIN_0);  if (useSecondMpu) mpus.add(AD0_PIN_1);

 mpus.initialize();

 // configure LED for output  pinMode(LED_PIN, OUTPUT);

 // verify connection  Serial.println(F("Testing device connections..."));  if (mpus.testConnection()) {    Serial.println(F("MPU6050 connection successful"));  } else {    mpus.halt(F("MPU6050 connection failed, halting"));  }

 // wait for ready // Serial.println(F("\nSend any character to begin DMP programming and demo: ")); // while (Serial.available() && Serial.read())    ; // empty buffer // while (!Serial.available()) // activityLed.update(); // flash led while waiting for data //while (Serial.available() && Serial.read())    ; // empty buffer again  //activityLed.setPeriod(500); // slow down led to 2Hz

 // load and configure the DMP  Serial.println(F("Initializing DMP..."));  mpus.dmpInitialize();

 // supply your own gyro offsets here, scaled for min sensitivity  MPU6050_Wrapper* currentMPU = mpus.select(0);  currentMPU->_mpu.setXGyroOffset(220);  currentMPU->_mpu.setYGyroOffset(76);  currentMPU->_mpu.setZGyroOffset(-85);  currentMPU->_mpu.setZAccelOffset(1788); // 1688 factory default for my test chip  if (useSecondMpu) {    currentMPU = mpus.select(1);    currentMPU->_mpu.setXGyroOffset(220);    currentMPU->_mpu.setYGyroOffset(76);    currentMPU->_mpu.setZGyroOffset(-85);    currentMPU->_mpu.setZAccelOffset(1788); // 1688 factory default for my test chip  }  mpus.programDmp(0);  if (useSecondMpu)    mpus.programDmp(1); } ```

the code above is a literally code from Mr. J. Rowberg (not a full code and does not include my additions). So, the question is "how can I put the millisecond to count every data that show up in serial monitor? and what should I do, if I'd like to put every bit that has been translated by MPUs and put it beside the angle values? (so the output shows the angle in raw values and also in bit values)"

Thanks and best regards,

Ismail.

Try asking the question a different way. Show us some sample code that has a loop() function so it does something.. Tell us what it actually does and how that is different from what you want it to do.