Using Arduino to Simulate MPU-6050


I’m trying to replace the InvenSense MPU-6050 sensor on an existing board with an Arduino Mega 2560, in order to simulate the outputs of the sensor artificially. I have desoldered the MPU, and set up the Arduino as a slave with the same address as the MPU (0x68) on the I2C bus.

First I need to figure out which data does the host MCU ask for, so I uploaded this code to the Arduino to echo the I2C data in the serial monitor:

#include <Wire.h>

void setup() {
  Serial.begin(9600);           // start serial for output

void loop() {


void receiveEvent(int howMany) {
  Serial.println("Receive Event");
  while (1 < Wire.available()) { // loop through all but the last
    char c =; // receive byte as a character
    Serial.print(c);         // print the character
  int x =;    // receive byte as an integer
  Serial.println(x);         // print the integer

void requestEvent(){
  Serial.println("Request Event");

When I run the code, it gets stuck in the requestEvent() function, which means that the host MCU keeps asking for some data without writing anything first. As far as I know, the address of the desired register needs to be written first. Does the MPU send anything upon startup?


Never use the Serial object in an interrupt handler as you might lock the Arduino in interrupt waits. The I2C is clocked at 100kHz so a 9600 serial line is by far not fast enough to transfer the data you might get.