A while ago I needed to learn how the I2C protocol worked, so I set about writing some code to understand it better. I find the best way to learn something is to try and teach it, so this code is written as an introduction to I2C with myself as the teacher; however before I started writing this code I had very little knowledge of how the whole thing worked. Anyways, before I post the code I should mention that I am using a Teensy 3.2 to communicate with a Kootek GY-521, which is a breakout board for the MPU 6050 IMU (3 axis accelerometer and 3-axis gyroscope). I found out that recent batches of the GY-521 had a capacitor with an incorrect value, which caused horribly noisy readings. Here is my post on the Arduino forums detailing this.

And here is my code: