Arduino + IPod

35K399

Intro: Arduino + IPod

Easily control your iPod with Arduino using serial commands. This instructable includes the schematic, the code and some extra info; everything you need to make this work. 

USB,battery or wall power supply powered.

STEP 1: What You Need

Parts:
5x  1K ohm resistors
2x  1M ohm resistors
1x  12K ohm resistors
1x  1.5K ohm resistors
4x  normaly opened push buttons
wire
protoboard (optional)
3.5mm audio jack

Arduino Uno or similar    http://arduino.cc/
recycled iPod Dock or PodBreakout ( you can buy it here http://www.sparkfun.com/products/8295)

STEP 2: Schematic

In the protoboard.
Arduino serial is 5v while iPod logic level is 3.3v. Because of it we need to add a voltage divider.
The two 1M ohm resistors are required to make a 500k to select the device.
The dectect cable is conected to iPod TX pin and use to let the arduino know when an ipod is conected.


STEP 3: Code Info

STEP 4: Download the Program

Here is the arduino code:

/*
By Daniel Solis
Licensed under Creative Commons Attribution-ShareAlike 3.0 Unported
http://creativecommons.org/licenses/by-sa/3.0/

You are able to modify this code as well as the hardware. If you
have a better code or make any changes that improve the performa
nce please share them

Analog pin 4: ipod TX(to detect ipod)
Analog pin 0: button detection
Digital pin 1: arduino TX
*/

byte mode2[]={0xFF,0x55,0x03,0x00,0x01,0x02,0xFA};//mode 2 command
byte nobutton[]={0xFF,0x55,0x03,0x02,0x00,0x00,0xFB};//button release command
int release=200;
//commands
byte playxpause=0x01;
byte nextsong=0x08;
byte prevsong=0x10;
byte shuffle[]={0xFF,0x55,0x04,0x02,0x00,0x00,0x80,0x7A};
int long time;//
int butbefore=1023;
int dockbef=0;


void setup()
{
Serial.begin(19200);//sets serial com
for(int p=0; p<7; p++)
{Serial.print(mode2[p],HEX);}//sends mode2 command
}

void loop()
{
  int dock=analogRead(4);
  if(dock!=dockbef)//checks if there is an iPod conected
  {
   for(int p=0; p<7; p++)//if not, it sends again mode2 command
   {Serial.print(mode2[p],HEX);}
  }
int butnow=analogRead(0);
    if(butnow!=butbefore&&millis()-time>release)
    {
       if(butnow!=HIGH)//wait for button pressed
      {
       time=millis();
       if(butnow==0)//
       {
       srlcommand(playxpause);
       }
       if(butnow >948 && butnow<953)
       {
       srlcommand(nextsong);
       }
       if(butnow >=506 && butnow<508)
       {
       srlcommand(prevsong);
       }
       if(butnow >955 && butnow<963)
       {
         for(int d=0; d<8; d++)
        {Serial.print(shuffle[d],BYTE);}
       }
      }   
    }
else
{
  for(int d=0; d<7; d++)
  {Serial.print(nobutton[d],BYTE);} //no button pressed command
}
butbefore=butnow;
}


void srlcommand(byte select)
{
  byte checksum=0x00-0x03-0x02-0x00-select;//checksum of lenght, mode and command
  byte inst[]={0xFF,0x55,0x03,0x02,0x00,select,checksum};//general structure
  for(int m=0; m<7; m++)
    {Serial.print(inst[m],BYTE);}//sends the command
}

STEP 5: Assembly

Solder the ipod dock
Solder the arduino cables
Solder pushbuttons and resistors.
Solder the audio jack.

STEP 6: Place It in a Box

I used my ipod touch box.
You can also add some leds. Its all up to you.

STEP 7: The Thing Finished

Yeah, my buttons aref  poor quality.

http://www.youtube.com/watch?v=48pZSFSIGjw

9 Comments

This might be a bit much to ask but if you can show me how to make that with only a play button it would be much appreciated

In the code:

Why are some serial commands sent as bytes and some as hex? Does it matter which you use and when?

In the hardware:

I am also confused about which pins are coming out from the ipod. Could you specify?

Thanks

Hi! I am pretty sure its the same, hex and byte, I mean a number is a number, but I dont know if arduino does something else in the background depending on if its byte or hex. It would be interesting if you try it and see what you get, also, you can try using the Serial.write function. About the connections, there are only three wires between arduino and the dock: one is usually found as TX in the dock and it is connected to analog 4 pin, the second wire is usually found as RX in the dock and is attached to a voltage divider connected to arduino TX pin 1. The third wire is the ACCESORY INDICATOR, it has different names on different docks so you will need to find the pad it is connected to. You can do this with a continuity tester with one probe on pin 21 (of 30 pin ipod connector) and the other probe on each pad until yo have the closed circuit. Take a look at this site: http://pinouts.ru/PortableDevices/ipod_pinout.shtm...

Thanks for your feedback and I hope this was useful.

Thanks for your quick feedback. Here's what I've tried. When I use Serial.print(mode2[p],HEX) I get the following output in my computers serial monitor:

FF553012FA

This is correct and corresponds to the data we are trying to send. When I use Serial.print(mode2[p],BYTE) it gives me an error that this command does not work in the latest version and I should use serial.write if I want to send bytes. So I tried Serial.write(mode2[p]) and I got the following in my Serial Monitor:

ÿU ú

This is surprisingly also correct and represents the same thing when using this translation code that I found on the internet http://www.december.com/html/spec/codes.html.

I guess my main question about it is, did your program work just as above when you used both hex and byte and also, why did you choose to send some as hex and some as byte.

As far as the wires go, would it be possible to send these commands through a usb instead of using the dock? This would mean sending the commands through pins 25 and 27 (usb data + and usb data -) rather than pins 12 and 13 (Tx and Rx). Have you tried or thought about this?

Finally, can you confirm that I understand the wiring scheme. From your diagram it looks like the grey wire goes to ipod Rx, the brown wire is the accessory indicator and it's purpose is to tell the ipod that we will be communicating through Rx and Tx, and the light blue wire is ipod Tx. There is then a 4th wire, dark blue, and I'm guessing that just connects to the ipod docks ground. Is this all correct?

And finally finally, does any ipod dock work or do different docks have different pins on them. Will a simple charging dock work or does it need to be a dock that is meant for controlling your ipod?

Sorry for the essay and thanks for your last response and for putting together this entire project!

This is great thanks!

Only question I have is on the page showing the schematic... Which pins are all those wires coming from on the Ipod?

Some are fairly evident like the audio out left and right, but what's other pins you have connected to?

Thanks
First of all, this is a fantastic project!

Though I was wondering, do you think this could be done with an Arduino Lilypad? I have one lying around and would like to use it, but since it is quite a bit simpler than the UNO I wasn't sure.
Yes you can. I have no experience with lilipad but basically everything stays the same. All you have to do is change the pin numbers in the code so they match the physical conection. Remeber you only need three pins of the arduino (two analog pins and the serial transmitting pin). the biggest change would be the Tx pin which is located on the pin header of the lilypad. I hope this information helps you, if you have another question just ask.
Nice one!

You could add some info/notes to your fritzing layout to show which value resistors are used where. As displayed the image is too small to make out the colour bands. Also with careful selection of resistor values you make the analog readings for each button further apart, so there is less chance of the arduino getting the button reading wrong if there is a bit of stray resistance.

I have a little breakout board that I want to use for the same thing - your code will be a great kicking off point.

I was hoping to not only control the playback (it's ridiculous that there is such an overhead for sending next / back / vol up / vol down) but also to get song title, artist title etc. for displaying on a little LED screen.


Sorry, there are the resistor values. Of course you can get the song name, artis and lots of useful info. its not very difficult, but you need a logic level converter to receive the info. I had to buy it from sparkfun, if i get the thing before the contest closes maybe i can upload the instructable.