iPod XBee Remote Control

iPod/iPhone Remote Control using XBee

Intro

I would like to introduce my latest project, an iPod/iPhone remote control using XBee. For those unaware, XBee is a module which allows you to wirelessly transmit commands and data over the 802.15.4 protocol (like Bluetooth and WiFi, only slower and more power efficient). This remote is based on the work of David Finlay, who built an iPod control using an Arduino, which attaches to the iPod/iPhone, and controls music playback. I loved his idea, but I wanted to take it a step further and make it wireless. To accomplish this spectacular feat, I use an Arduino and 2 XBee modules, one connected to the serial-in port of the iPod/iPhone, and the second one connected to the Arduino with an Arduino XBee shield. You can also use an XBee to control the iPod from your computer if you want.

Basics

The iPod (and the iPhone) has a serial interface, which it uses to communicate with docks and other devices that control music playback. By sending it the proper commands in 19200 baudrate, we can command it to Play or Pause a song, adjust the volume, play the next song etc. The only thing we need in order to send commands to the iPod with an Arduino is an iPod dock connector, like the PodBreakout from PodGizmo, an Arduino (ofc) and a 3.3v-5v level shifter, because the serial port of the Arduino works in 5v, while the serial port of the iPhone works on 3.3v, and it could be damaged if we were to connect that to 5v. Therefore, we need to convert the 5v to 3.3v. For more information on connecting an Arduino to control an iPod directly, I suggest you read the original blog post by David Finlay, as well as his follow-up post. After making the connections, we need to know exactly what commands to send. Thankfully, David also made an Arduino library which takes care of that problem.

Cutting the wires

So far so good, but as I said, our goal is to take things to the next level, and make a truly remote (read: wireless) control for our iPod. That’s where the XBee modules come in. XBee modules have a serial (Rx/Tx) interface, and by default, they broadcast any input they get on their Rx pin over the air, and they send any data received over the air on the Tx pin. Therefore, by connecting the first XBee to the Arduino and the second one to the iPod, we essentially replace the serial connection between the Arduino and the iPod with a wireless one.

We’ll connect the XBee to the iPod as shown in the schematic. I am using an XBee Explorer Regulated from Sparkfun as a breakout board for the XBee. The XBee is powered from pin 18 of the iPod, which always provided 3.3v. It’s a low power pin, but enough to power our XBee module*. The GND pin of the XBee is connected to pin 15 of the iPod (GND), and the DOUT(Tx) pin of the XBee is connected to pin 13(Rx) of the iPod. Last but not least, we should connect a 500kOhm resistor between pins 15(GND) and 21(Accessory Selector) as described here, here, and here. This MIGHT not be needed, and it seems to work fine without it, but I added it. Connecting the XBee to the Arduino is much, much easier, since we’ll be using an Arduino XBee shield instead of making the connections ourselves(i recommend the one from Sparkfun) and we’re good to go**.

*I have tested this on an iPod Classic, an iPhone 3G, an iphone 3GS and iPhone 4 and it worked find. On my 4th gen iPod, this doesn’t work because it can’t provide the necessary power, but I suspect it is due to battery degradation over time because it works fine when the iPod is connected to a 5v USB and charging

**Notice that, because we can’t have the Xbee connected and program the Arduino at the same time, there’s a switch on the XBee shield which we will need to toggle when programming the Arduino. In order to program the Arduino, we need to set the switch to the DLINE position, and then set it back after we’re done.

Make it so

After connecting the XBee to the iPod, we need to set up our Arduino remote. I will use a sample code which is based on David Finlay’s SimpleRemote_with_Bounce_And_Wake sample code. The code is pretty straightforward. We basically send a sendPlay command every time the button is pressed. This toggles Play/Pause on each click.

// Simple example of using iPodSerial library to send
// Simple Remote Play command on the press of a button.
// This will alternate between Play and Pause on the iPod.
// Based on David Finlay's examples
#include 
SimpleRemote simpleRemote;

const byte BUTTON_PIN = 5;
bool buttonState=0, oldButtonState = 0;

void setup()
{
  pinMode(BUTTON_PIN, INPUT);
  simpleRemote.setup();
}

void loop()
{
  simpleRemote.loop();

  static unsigned long timestamp = 0;
  if(millis() - timestamp > 50)
  {
    buttonState = digitalRead(BUTTON_PIN);
    if(buttonState && !oldButtonState)
    {
      // prod the iPod in case it went to sleep since we last talked to it
      // (after which older iPods will stop responding to us otherwise)
      simpleRemote.sendiPodOn();
      delay(50);
      simpleRemote.sendButtonReleased();
      simpleRemote.sendPlay();
      simpleRemote.sendButtonReleased();
    }
    oldButtonState = buttonState;
    timestamp = millis();
  }
}

Taking it to the next level

My final goal was to make an iPod dock with a bult-in wireless receiver for the remote, so I’ve added a mini-usb charging port, which also powers the XBee, instead of getting power from the iPod, as well as an audio jack for the speakers. You can see the schematic below. The connections for the audio adaptor are pretty straightforward, and so are the ones for the mini-USB connector. Notice that, in addition to the necessary connections, we need to connect pins 16 and 11 to the GND as well. The first one is the USB GND, so we need to connect it to the GND we get from the USB connector, and the second one tells the iPod to use the dock’s audio jack (pins 2, 3, 4) instead of the headphone jack for audio out.

Last but not least, the newer iPod and all iPhones will not charge unless there is a specific voltage on their USB D+ and D- lines. There is an excellent tutorial explaining everything in detail (as well as a quick explanatory video by ladyada) by Adafruit here. Suffice to say, in order to get iPods to charge at 250mA and iPhones to charge at 500mA (make sure your USB charger can provide as much), we need to solder a 75KOhm resistor between each of the two pins and 5v, and a 49.9KOhm resistor between each pin and the Ground, as shown in the last image*.

Note: Some USB chargers designed to work with iPhones should include these resistor values in their circuitry. In this case, all you need is to connect the D+ and D- lines of the USB connector to the iPod/iPhone dock connector.

Gallery

Here are a couple of photos of the iPhone-powered remote:

And the dock (with iPod/iPhone charging, and audio out):

Tzikis is using WP-Gravatar