Calibrate to Agitate
Each MPU-6050 chip needs calibrating to ensure drift free fun.
There is an excellent guide here: http://www.i2cdevlib.com/forums/topic/91-how-to-decide-gyro-and-accelerometer-offsett/
Over on the i2c library forums a kind fellow has posted a sketch that will output some values that you can then plug into the Joystick sketch.
Upload the sketch in the usual way, set the MPU-6050 as flat as possible and run the sketch. Open up the serial coms window (shift-ctrl-m) and after a few minutes the sketch should output some ‘offset values’.
These can then be used in the joystick sketch
mpu.setXGyroOffset(45); mpu.setYGyroOffset(24); mpu.setZGyroOffset(5); mpu.setZAccelOffset(1234);
That should ensure drift free operation.
On top or On The Side?
The data sheet for the MPU-6050 talk about ensuring it’s mounted flat and level. This doesn’t mean you can only mount it on top of your head. The chip needs to be flat againt the object you interested in, i.e. RC bugger, glider or your head. As long as the axis of rotation line up then you can mount on top, on the side and any way up.
My head appears to pitch on the axis through my ears, so I’ve mounted my Head Tracker with the MPU6050 as close to this axis as possible, i.e stuck on the side of my headphone.
Wherever you mount you device it needs to be fixed firmly with no wriggle room. I also tape the USB cable to make sure that can’t pull on or move the device.
The original joystick emulation code used 8 bits for each axis. That only gives 255 distinct head positions in each dimension. The effect is if you move your head slowly you get multi-pixel jumps in the on screenm view.
I’ve updated the HID description and code to now use 16 bit values. This gives sub-pixel head tracking resolution and a much smoother experience.
The updates files also implement a shorter re-calibration time, down from 5 seconds to 2. So if you do need to hit the recal button it’s less of a pain waiting.