This page will change in accordance with hardware updates.

NOTE: If you link, please let me know. I would just like to know where this is showing up.


Recently, Apple released the iPhone/iTouch software update version 3.0. Included in this update was the ability to 'shake to shuffle'. This utilized the internal accelerometer within the iPhone/iTouch to sense a vigorous shaking motion. After shaking , the Cupertino Music Player would randomly select a song from the songs loaded in memory. Earlier versions of the iPod Nano had this capability. However, I was not happy with this because it provides no control over the song selection and no other motion related control.

About a year ago, after purchasing my iTouch, I found myself trying to use the player and drive my car at the same time. Since the iTouch is a touch screen and void of physical navigation buttons for the music portion of the player, I would have to take my eyes off the road and look at the player to unlock and eventually find the advance button to change to the next song. Working for a leading motion sensor company, I decided to make a motion-based iPod/iTouch/iPhone (henceforth referred to as iPod) controller utilizing a MEMS based gyro for motion capture.

The concept is simple. I wanted to have 4 functions; Track forward, track backward, volume up and volume down. The InvenSense IDG Dual Axis gyro lent itself perfectly to this application. I had previously developed the iPodGPS and had utilized that experience and code to help rapidly develop the motion controller, affectionately referred to as the iPodGyro.

Why a Gyro? Direction! An accelerometer is great for measuring force. However, it is easy to confuse an algorithm utilizing accelerometers by re-orienting the sensor. This is easily illustrated by placing the iTouch a table, face up and spinning it. The internal accelerometer can detect that the ipod is experiencing a centripetal acceleration,but it cannot detect which direction the iTouch is spinning. This is a prime reason why I selected a gyro over an accelerometer to perform my motion sensing. I want to know direction along with angular magnitude. A secondary consideration is the linear shock resistance. Since my algorithm looks for specific rotational movements (explained below), you could even take it jogging and not worry about skipping songs from the jarring movement!

iPodGyro on Nano

Figure 1. iPodGyro.


Overall Progression

The iPodGyro was developed in 3 Generations, each improving upon the earlier design. Generation 1 consisted of a Atmel STK500 prototyping board, an InvenSense IDG evaluation board and an iPod Touch (also tested with iPod Nano, not shown).

Gen1 Development Platform

Figure 2. Generation 1 development setup.

Even though it is difficult to see in Figure 2, an Atmel ATmega168P microcontroller was chosen for the option of coming in a QFN package size (for development Generation 2 and Generation 3) and for its miniscule power consumption. From direct measurements I performed, it appears that the iPod Nano can only deliver 25mA@3.2V from its dock connector. Since I wanted the iPodGyro to work with all dock-enabled iPod's, this was a prime design consideration. The InvenSense gyro would consume approximately 6mA of current at 3V, which left the remainder of the power to drive the microcontroller any LED's I decided to use. Dock connectors were obtained originally from SparkFun, and then later purchased from Ridax. The programmer (blue device, right side) is the Atmel AVRICEmkII. You could just as easily utilize the cheaper AVRISPmkII to program the microcontrollers as well.

The firmware code for the Mega168 was written utilizing Atmels AVR studio development environment. I find this no-cost development tool surprisingly mature and easy to use. I have used it several times in the past and am pleased with the results. Everything is coded in C language and takes advantage of the GNU compiler for AVR microcontrollers. Also, as a helping hand, AVR Freaks is an active development community for nearly all of Atmel's products with several helpful individuals .

Generation 2 was the PCB construction stage. Eagle Layout Editor (www.cadsoft.com) was used to develop the schematic and board layout. The folks at PCB Fab Express(PCB-FE) fabricated the first round of boards for me. Receiving the boards from PCB-FE, I learned my first lesson: Never trust the PCB footprints from the web! Even though the layout and circuit was sound, there were 3 issues detrimental to the layout: the iPod connector was backwards and inverted on the board layout diagram from the actual connector (the pins are lined up on the back side), the QFN 5x4 landing pads (for the gyro) were too small for hand soldering, as were the landing pads for the microcontroller. These are all indicated in red.

Trouble spots

Figure 3: Trouble hotspots.

Quick changes in Eagle Layout Editor to the individual component configurations resulted in a clean second fabrication of the PCB's. Code upload to the microcontroller by way of ISP netted my first working prototype of the second generation of iPodGyro.

Operation is simple:

1) Plug into iPod.

2) Internal configurations automatically calibrate the iPodGyro to your specific iPod device.

2) Internally, the iPod is set to random Play mode. Music starts playing.

3) Flick iPod forward to advance the music track. Flick iPod backward to go to previous music track.

4) Twist iPod clockwise to increase volume. Twist iPod counterclockwise to reduce volume.

5) Enjoy your now motion controlled music player!

Video 1. Second Generation in action.

The third and final generation of the iPodGyro project consisted of a smaller PCB, more LED's and an upgraded motion detection algorithm.

Gen2 vs. Gen3

Figure 4. Comparison of 3rd Generation (top) and 2nd Generation (bottom) iPodGyro units.

Size constraints made this PCB especially difficult to design. Placement of the Gyro and the Microcontroller were optimized to reduce board-induced stress on both IC components and allow for greater flexibility in trace routing. Because this design incorporated 5 LED's and generation 2 incorporated two LED's (single, tri-color) special attention was paid to ensure only one LED 'side' was illuminated at a time (to maintain low power). In Video 2, in the track adjustment motion, two LED's appear to be lit simultaneously, but in fact they are being switched on-and-off in an alternating fashion in microsecond pulse widths.


Gen3 Disassembled Gen 3 Assembled

Figure 5. Third Generation iPod Gyro - Disassembled and assembled.


Video 2. Third Generation in action.


Algorithmically speaking, the iPodGyro is a simple device. After the analog signal is digitized by the ADC, the data is averaged and then checked to see if the values exceed a preset limit. If the gesture axis threshold is exceeded, while the cross-axis threshold is NOT exceeded, then the specific command is sent to the iPod. Apples Accessory Protocol was used to ensure compatability with iPods that have and have not been jailbroken. Figure 6 shows an excitation of one axis while the cross (opposite) axis remains relatively motionless.

Gesture accept

Figure 6. Graph of accepted gesture motion (music track advance).


The below example shows how the software rejects a given gesture. Should both axis be excited simultaneously with significant motion, the software will simply reject the gesture entirely and then wait for the next gesture.

Rejected Gesture

Figure 7. Graph of rejected gesture.

The single largest time sink was trying to display pictures on the screen of the iPod. Fortunately this happened after the iPodGyro was able to control the iPod and had only taken about 15 hours worth of work to develop all of the modules. Displaying a picture on the screen of the iPod took approximately 5 hours of work. Most of that was trying to remember how to do it from my iPodGPS days :-) (about 2 years prior).

For the motion control portion of this project, the software flow is as follows:

Software Flow

Figure 8. Software flow.


Bill of Material

Except for the sunk cost of the PCB, I found this project relatively inexpensive.

1) IDG-650 DualAxis analog gyro. -- $40.00

2) Atmel ATmega168P microcontroller -- $4.00

3) PCB Fabrication -- $8.00/each

4) iPod dock connector & shell - $4.00

5) Resistors, capacitors and LED's - $4.00

Total Cost per populated board: ~$60.00US -- Not Much!



After all of this awesome experience, I would like to know the market viability of this device. I was thinking of selling these, but I don't know if there is much of a demand. My own personal development units currently have the ability to transmit the raw gyro motion (instead of control commands) data to the iPod of which I can receive and utilize for my own iTouch software development.

If you are interested in purchasing either the iPodGyro control unit, OR the iPodGyro raw data unit, please let me know at benkokes@hotmail.com .


Final Thoughts

I will offer advice and help to anyone who asks. No sweat on algorithm development, coding hints and or motion processing advice.On the iPodGPS project, I offered to send my source code to anyone who asked. Since that, I have been asked by professors to not readily release the source code, because already students were directly plagiarizing it from my site and snippets that I had sent them. So I will be hesitant to send out the entire code base. But like I said, its an easy algorithm and circuit design, you can get something like this up and running in just a few days. Besides, it was a ton of fun!


Thanks for looking, and happy iPodding.


Last updated June 22nd, 2009 - Copyright Enfinicorp.

Page maintained by: benkokes@hotmail.com