Arduino Code for the First Prototype

A project log for Manucon - A glove based controller

Use this sensor-loaded glove to precisely and intuitively control any model aircraft. Heck, control everything!

RaptorTechRaptorTech 08/17/2014 at 20:340 Comments

Hardware completed, I started in on the software for the OSSEP Uno R3.

I knew the OSSEP was compatible with the Arduino IDE, so I plugged in the board and went to upload the blink sketch just as a test. Unfortunately the upload failed. Off to a good start already :)

A quick google search revealed that in order to use the OSSEP board, driver software was required. Even on a Mac! Can you believe it?! 

Once I installed the driver software (available here), the blink sketch uploaded just fine and I got to the programming. 

Reading data from the flex sensor was as simple as pulling the analog data from one of the analog input pins, and scaling the values from 0 to 1000 (I'll explain why I chose those numbers in a minute).

The MPU6050 is a little more complicated, but still not too bad.

MPU6050 is an I2C device, so I started by downloading and installing the I2Cdevlib library (on github). This library is a collection of many of the most common I2C devices, and makes interfacing these devices very easy. 

Running the MPU6050 example sketch from i2cdevlib, I was easily able to display the raw data from the MPU6050's accelerometer, gyroscope, and thermometer. This was nice, but not terribly useful, because I needed the absolute orientation of the glove, not component accelerations.

After puzzling over how I might be able to get this information easily, I resigned myself to writing a Kalman filter, and settled in to start self educating on the topic. Kalman filters are very math intensive and require extensive tuning, so this code was shaping up to be more difficult that intended.

Then, it occured to me, the i2cdevlib library includes an example sketch to allow a 3D rectangle in Processing to mimic the position of the MPU6050. This means that somewhere in that code, there is information about the absolute orientation of the IMU. Although the serial output is not designed to be human readable because the data is passed straight to Processing, a few lines of code fixed that.

I commandeered that example sketch (and removed all the fluff),  and printed all my data to the console.

Everything seemed to be working well, but there's only so much you can see from the rapidly scrolling numbers.

View the code on Github!