In car iPod remote

I've slowly been building up all the audio hardware in my car for the past couple of years, and recently got to the point where I needed a nice way to skip a track on my iPod.

Armed with a iPod dock connector breakout board and a 3.3v Arduino pro mini I've got a working widget that allows me to skip and pause tracks remotely via the iPods serial port, yay


not the ideal layout, but it'll do the job for now

I've got 3 youtube hosted movies taken at the breadboard, boxed and fitted stages on my site
http://www.beigematchbox.co.uk/site/BeigeMatchbox.co.uk/Hobbies/Entries/2009/4/21_arduino_controlled_ipod.html

Next is to have the Arduino control bass, treble and volume, my dad seems to think a renesas m61523p is ideal, but I'm have trouble finding info, apparently everything can be controlled over SPI :sunglasses:

Then mount everything on one box with a cable to connect to the iPod, and another with the remote buttons.

hey, can we have some code/ specific? :wink:

I've currently borrowed some code from someone else to calculate the checksum so I wont post that as it's not all mine, but with only 3 commands getting used it makes more sense to pre calculate it and just put all the byes in a single array, will use less program space too,

When I've done the above I'll post up the code :slight_smile:

I'm currently trying to track down a tone control IC, when I've got one the circuit will start getting busy enough to warrant some schematics, so I'll happily post them too

Righty then, finally got a chance to rewrite all the code, so it no longer uses any of anybody elses :sunglasses:

//       *********************************************************************
//       *                                                                   *
//       *    This is the software to run a simple iPod control box using    *
//       *    2 buttons and 2 LEDs.                                          *
//       *    SERIAL PORT MUST RUN AT 3.3v!!                                 *
//       *                                                                   *
//       *********************************************************************



// What the buttons and LEds are hooked up to
#define REDPIN 6
#define GREENPIN 5
#define LEFTBUTTON 3
#define RIGHTBUTTON 4

// Is it time to tell the ipod the button has been released
boolean sendRelease = true;

// Various things to do with the LED fader
boolean greenLedfading = true;
boolean greenLedon = false;
int greenPwm = 255;
boolean redLedfading = true;
boolean redLedon = false;
int redPwm = 255;
long fadeMillis = 0;
#define fadeSpeed 10


// Arrays strings to tell the iPod what to do
const char buttonRelease[] = {
  0xFF, 0x55, 0x03, 0x02, 0x00, 0x00,0xFB};

const char dataPlay[] = {
  0xFF, 0x55, 0x03, 0x02, 0x00, 0x01, 0xFA, 0x0D};

const char dataPrev[] = {
  0xFF, 0x55, 0x03, 0x02, 0x00, 0x10, 0xEB, 0x0D};

const char dataNext[] = {
  0xFF, 0x55, 0x03, 0x02, 0x00, 0x08, 0xF3, 0x0D};



void setup() 
{ 

  Serial.begin(19200);             // Setup the serial port

  pinMode(REDPIN, OUTPUT);         // Setup the input and output pins
  pinMode(GREENPIN, OUTPUT);

  pinMode(LEFTBUTTON, INPUT);
  pinMode(RIGHTBUTTON, INPUT);
} 



void loop()
{ 
  doButtons();                     // Service the buttons and tell the iPod what to do
  fadeLeds();                      // Service the LEDs
}










void doButtons(){
  if(digitalRead(LEFTBUTTON) == HIGH || digitalRead(RIGHTBUTTON) == HIGH){                     // if a button is pressed
    delay(100);                                                                                 // wait 100ms
    if(digitalRead(LEFTBUTTON) == HIGH && digitalRead(RIGHTBUTTON) == HIGH){                    // if both buttons are now on
      iPodPlay();                                                                                // Tell the iPod to play/pause
      redLedon = true;                                                                           // Start the red led fading
      sendRelease = true;                                                                        // When both buttons are relesed tell the iPod
      return;                                                                                    // Exit the if
    }
    else if(digitalRead(LEFTBUTTON) == HIGH){                                                   // if left button is on
      iPodPrev();                                                                                // Tell the iPod to prev track
      greenLedon = true;                                                                         // Start the green led fading
      sendRelease = true;                                                                        // When both buttons are relesed tell the iPod
      return;                                                                                    // Exit the if
    }
    else if(digitalRead(RIGHTBUTTON) == HIGH){                                                  // if left button is on
      iPodNext();                                                                                // Tell the iPod to next track
      greenLedon = true;                                                                         // Start the green led fading
      sendRelease = true;                                                                        // When both buttons are relesed tell the iPod
      return;                                                                                    // Exit the if
    }
  }

  if(digitalRead(LEFTBUTTON) == LOW || digitalRead(RIGHTBUTTON) == LOW && sendRelease == true){ // if all buttons are released and it's time to tell the iPod
    iPodRelease();                                                                               // tell the iPod the butts have been released
    sendRelease = false;                                                                         // don't tell the iPod again until another button has been pressed
  }


}












void iPodPlay(){
  for (int i = 0; i < 9; i++) {                 // Send Play/Pause bytes
    Serial.print(dataPlay[i], BYTE);
  }
}

void iPodPrev(){
  for (int i = 0; i < 9; i++) {                 //Send Prev bytes
    Serial.print(dataPrev[i], BYTE);
  }
}

void iPodNext(){  
  for (int i = 0; i < 9; i++) {                 //Send Next bytes
    Serial.print(dataNext[i], BYTE);

  }
}

void iPodRelease(){
  for (int i = 0; i < 8; i++) {                 //Send Button Release bytes
    Serial.print(buttonRelease[i], BYTE);
  }
}
















void fadeLeds(){     // from my library of useful code, need to add comments

  // *************************************
  if(greenLedon == true){
    greenLedon = false;
    greenPwm = 255;
    analogWrite(GREENPIN, greenPwm);
    greenLedfading = true;
  }



  // *************************************

  if(redLedon == true){
    redLedon = false;
    redPwm = 255;
    analogWrite(REDPIN, redPwm);
    redLedfading = true;
  }



  // *************************************

  if (millis() - fadeMillis > fadeSpeed) {
    int lag = (millis() - fadeMillis) / fadeSpeed;


    fadeMillis = millis();

    if(greenLedfading == true){
      if(greenPwm > 0){        

        int spaceCount;
        for(int i = 1; i <= lag; i++){
          greenPwm = greenPwm*100/115;
        }

        analogWrite(GREENPIN, greenPwm);
      }
      else{
        greenLedfading = false;

      }
    }

    if(redLedfading == true){
      if(redPwm > 0){
        for(int i = 1; i <= lag; i++){
          redPwm = redPwm*100/115;
        }
        int spaceCount;
        spaceCount = redPwm/4;
        analogWrite(REDPIN, redPwm);
      }
      else{
        redLedfading = false;

      }
    }
  }
}

Hopefully I’ll be able to draw up the hardware soon too, but it really is very simple, even if I did manage to tie the buttons low instead of high ;D oops…

A video of it in action - http://www.youtube.com/watch?v=1-_BKU-_ETA

And lastly a video of what i’m slowly adding functionatly too, and a pointer as to what this is all leading to - http://www.youtube.com/watch?v=bEFTQyc88V8

amazing!!! it's the same for iphone?! my idea was to connect iphone and arduino via wireless/bluetooth, an than have only 3 button to control music. It's possible?!