{"id":131,"date":"2008-01-17T15:02:52","date_gmt":"2008-01-17T20:02:52","guid":{"rendered":"http:\/\/www.tigoe.net\/pcomp\/code\/category\/code\/arduinowiring\/131"},"modified":"2008-01-25T12:47:07","modified_gmt":"2008-01-25T17:47:07","slug":"ipod-control-from-arduino-or-wiring","status":"publish","type":"post","link":"https:\/\/www.tigoe.com\/pcomp\/code\/arduinowiring\/131\/","title":{"rendered":"iPod control from Arduino or Wiring"},"content":{"rendered":"<p>Rosie Daniel wrote a nice piece of Arduino code to control an iPod.  Rosie used a <a href=\"http:\/\/www.rosiedaniel.com\/2007\/04\/ipod-aud.html\">hacked iPod remote<\/a> to connect her Arduino to the iPod.  The remote&#8217;s AUD connection is its data in connection, which is connected to the Arduino\/Wiring board&#8217;s data out. The iPod&#8217;s power (VCC) and Ground are connected to the power and ground of the microcontroller.  Then this code works.<\/p>\n<p>Thanks to Rosie for writing this:<\/p>\n<p><!-- technorati tags start --><\/p>\n<p style=\"text-align:right;font-size:10px;\">Technorati Tags: <a href=\"http:\/\/www.technorati.com\/tag\/arduino\" rel=\"tag\">arduino<\/a>, <a href=\"http:\/\/www.technorati.com\/tag\/atmel\" rel=\"tag\">atmel<\/a>, <a href=\"http:\/\/www.technorati.com\/tag\/serial\" rel=\"tag\">serial<\/a><\/p>\n<p><!-- technorati tags end --><br \/>\n<!--more--><\/p>\n<pre>\/\/code that controls basic (play\/pause, next, previous, volume up, and volume down) functions of ipod\n\/\/rosie daniel\n\nint hits = 0; \n\nint buttonStates[]={0,0,LOW,LOW,LOW,LOW,LOW};\nint buttonPrevious[]={0,0,LOW,LOW,LOW,LOW,LOW};\nint buttonRelease[] = {0xFF, 0x55, 0x03, 0x02, 0x00, 0x00,0xFB};\n\nint commands[]={0,0,0x01,0x08,0x10,0x02,0x04}; \n\nint checkSum(int len, int mode, int command1, int command2, int parameter) {\n  int checksum = 0x100 - ((len + mode + command1 + command2+ parameter) &#38; 0xFF);\n  return checksum;\n}\n\nvoid setup() { \n  Serial.begin(19200);\n  pinMode(2, INPUT);\n  pinMode(3, INPUT);\n  pinMode(4, INPUT);\n  pinMode(5, INPUT);\n  pinMode(6, INPUT);\n}\n\nvoid loop() {\n  \n  for (int c=2; c&lt;7; c++)\n  {\n     buttonStates = digitalRead(c);\n    \n  \n  buttonStates = digitalRead(c);\n\n  if (buttonStates != buttonPrevious ) {\n    delay(5); \/\/helps avoid a 'double' press - check a second time to see if the button is still pressed after a delay \n     buttonStates = digitalRead(c);\n    if (buttonStates == HIGH) {\n      sendCommand(commands);\n      \/\/Serial.print(hits);\n      hits++;\n    }\n    buttonPrevious = buttonStates;\n  } \n\n}\n\n}\n\nvoid sendCommand(int cmd) {\n  int cs = checkSum(0x03, 0x02, 0x00, cmd, 0);\n   Serial.println(cs,HEX);\n  \n \n  \n  int bytes[] = {0xFF, 0x55,  0x03, 0x02, 0x00, cmd, cs};\n  for (int i = 0; i &lt; 8; i++) { \n    Serial.print(bytes[i], BYTE);\n   \n  }\n  \n  for (int i = 0; i &lt; 8; i++) {\n     Serial.print(buttonRelease[i],BYTE);\n    }\n}\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Rosie Daniel wrote a nice piece of Arduino code to control an iPod.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-131","post","type-post","status-publish","format-standard","hentry","category-arduinowiring"],"_links":{"self":[{"href":"https:\/\/www.tigoe.com\/pcomp\/code\/wp-json\/wp\/v2\/posts\/131","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tigoe.com\/pcomp\/code\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tigoe.com\/pcomp\/code\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tigoe.com\/pcomp\/code\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tigoe.com\/pcomp\/code\/wp-json\/wp\/v2\/comments?post=131"}],"version-history":[{"count":1,"href":"https:\/\/www.tigoe.com\/pcomp\/code\/wp-json\/wp\/v2\/posts\/131\/revisions"}],"predecessor-version":[{"id":195,"href":"https:\/\/www.tigoe.com\/pcomp\/code\/wp-json\/wp\/v2\/posts\/131\/revisions\/195"}],"wp:attachment":[{"href":"https:\/\/www.tigoe.com\/pcomp\/code\/wp-json\/wp\/v2\/media?parent=131"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tigoe.com\/pcomp\/code\/wp-json\/wp\/v2\/categories?post=131"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tigoe.com\/pcomp\/code\/wp-json\/wp\/v2\/tags?post=131"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}