So at this point you have an Pro Micro (or clone) plus a funky MPU-6050 breakout board. You will need some additional Libraries to get the MPU-6050 talking to your Arduino.
These can be grabbed here on github. Click ‘Download Zip’.
Super smart dude Jeff Rowberg has done all the hard work. Looking inside the zip (ic2devlib-master/Arduino) you will find a whole bunch of libraries for interfacing to many many cool devices. We only need MPU6050 and IC2DEV but I copied all these to the Arduino Library folder (<your arduino insall folder>/libraries) for later enjoyment.
You will need to quit and re-run the Arduino IDE to pick up the libraries. You can tell if it’s worked by clicking ‘File->Examples->” You should see MPU6050 examples in there.
I Dream of Wires
I soldered the right-angle pins to mine so that once mounted on the side of some headphones the chip would stick out sideways. This worked fine, but so does mounting the sensor board vertically. This means you’re able to mount the finished device on the top of your head or on the side next to your ear. This is because;
- We’re outputting all 3 axis to the PC
- You can select which axis to use in Elite Dangerous Head Tracking config
- You can invert the axis in the control config.
Here you can see the right angle pins. I’ve marked those that are needed with a yellow blob.
- VCC is your +volts (these modules are usually happy with between 3 to 5 v, but do check!)
- GND is ground
- SCL Is a Data Clock
- SDA is a Data In/Out
- Int is an interrupt pin that the MPU-6050 can use to tell the Pro Micro that is has finished generating data.
N.B Jumping ahead somewhat but, oddly, if you leave the interrupt pin unconnected the Head Track sketch will usually work for a bit and then stop. I think an unconnected interrupt pin (code says “listen to interrupts on this pin and execute XXX when you get one”) can generate dodgy interrupt signals. Anyways…
Wiring up is a doddle. The power for this rig is simply what’s supplied over USB.
The Arduino has a ground pin (gnd) and a vcc (+5v) pin. You connect these to the vcc and gnd on the 6050. I always connect ground first. I think that’s a good thing.
Most MPU6050 boards I’ve seen are happy at 3 or 5v. If you have once that says 3v then the Arduiono Micro has a 3.3v pin that you can use instead.
Arduino -> MPU6050
- VCC -> VCC
- GND- > GND
- Pin 7 -> Int
- Pin 2 -> SDA
- Pin 3-> SCL
NOTE The button in the picture below is no longer connected as shows. It simply needs to be connected between Pin 10 and Ground.
Handily the pins on my 6050 board are labelled in the back as well as the front.
At this point double check your wires (especially Vcc and Gnd). I’ve never broken anything by getting data or interrupt wires crossed but be careful with the power pins.
You now try our some of the MPU-6050 examples sketch, e.g. File->Examples->MPU6050->Example->MPU6050_raw
LED pin on Arduino Micro is 17. Most sketched will have the LED on 13. It’s easy to change .
Open the serial monitor window (shift-ctrl-m) to see text output from the device. If you see garbage make sure the BAUD rate in the monitor window matches the one specified in the code,e.g. Serial.begin(38400);
The final Head Track sketch has debug output turned off but if you need to see what’s happening you can enable it simply enough (see sketch).
I also have a small momentary switch placed at the end of the board. This acts as a recalibrate button so if you find the Head Tracker has drifted away from centre you can look forward and press the button once. The sketch will then sample the orientation for a few seconds (while you keep still) and use this as the new ‘looking ahead’ offset.
The Arduino Micro has internal pull-up resistors than can be configured when setting a pin as ‘Input’. The button then simple needs to go between Pin 10 and ground. The ‘unpressed’ state is then ‘HIGH’ with the value going ‘LOW’ when the botton is pressed.
The bit of code which bring this all together can be found here :
This gdrive folder contains the sketch, MPU6050Joy.ino , which is the code which gets the orientation data from the MPU6050 and sends it to the PC.
The folder also contains two arduino library files (HID.cpp and USBAPI.h) which need to replace the ones under <your arduino ide folder>\hardware\arduino\avr\cores\arduino
Make a copy of the existing files and stick the modded files in there. These files have been updated to add USB Joystick emulation along with the existing mouse and keyboard code.
You should now be able to open the Arduino IDE, load MPU6050Joy.ino , select Arduino Micro (under Tools->Board) and hit ‘Upload’.
Open up Windows USB Game Controller config to verify that the device is working:
The device now reports itself as a hi-resolution joystick, each axis having the range -32768 to 32767. This is far better than the initial version of the sketch which had a range of only -128 to 127. The 16 bit range results in much smoother head tracking in game.
In Elite:Dangerous you should now be able to bind the head look up/down and left/right axis to the USB Head Tracker.