Home > Arduino, Code, General > More H/W and S/W on the Apple Aluminum Remote

More H/W and S/W on the Apple Aluminum Remote

February 22, 2011 Leave a comment Go to comments


here is a post showing the disassembling of the Apple Aluminum Remote. Indeed, it is manufactured from a single piece of aluminum. Very nice engineering implementation not just in manufacturing the case, but in designing the insides to allow a simple snap-in assembly.


The latest release of the Arduino IDE (v 0022) has added a time out during the measuring of a pulse. This allows “native” support for my remote code. The release notes indicate:

* Applying the timeout parameter of pulseIn() during measurement of the  pulse, not just while waiting for it.

Readers that have read the code will note that in order to measure the pulses of the Apple Remote, I rely on the function “pulseIn()” to measure the size (time) of the different pulses generated by the remote.

By definition all pulses have a start and an end. In the absence of an external pulse, the IR receiver outputs HIGH. When there is a pulse from the remote, the IR receiver will output LOW and then back to HIGH, so measuring pulses from the IR receiver point of view is measuring pulses going LOW.

However, the NEC protocol used by the Apple remote utilizes pulse distance (not pulse width) to encode information.

(Diagram taken from here)

Therefore, from the IR receiver point of view, measuring the time distance between pulses  is the same as measuring the size of UP pulses after you’ve detected the start of communication (there are other methods of doing this but this way seems the easiest). Think of it as measuring the time of the white space in the diagram above. (Remember an up-pulse from the remote results in a down-pulse at the IR receiver; thus, between two pulses in the remote, you will see an up-pulse at the IR receiver)

A problem may arises when you try to measure the last pulse of the communication. From the IR receiver point of view, this is the white space after the last pulse which goes on forever (or until you press the remote again). If there is no time out in the pulse reading routine, then your code will hang right there.

The pulseIn() function in previous releases lacked a time-out during the measurement of the pulse which resulted in the code being stuck waiting for the end of that UP pulse (or the end of the white space, which in real life goes on forever). In order to remedy that problem, I redefined pulseIn() with a new function”newpulseIn()” as follows

unsigned long newpulseIn(uint8_t pin, uint8_t state, unsigned long timeout)
  uint8_t bit = digitalPinToBitMask(pin);
  uint8_t port = digitalPinToPort(pin);
  uint8_t stateMask = (state ? bit : 0);
  unsigned long width = 0;

  unsigned long numloops = 0;
  unsigned long maxloops = microsecondsToClockCycles(timeout) / 16;

  // wait for any previous pulse to end
  while ((*portInputRegister(port) & bit) == stateMask)
    if (numloops++ == maxloops)
      return 0;

  // wait for the pulse to start
  while ((*portInputRegister(port) & bit) != stateMask)
    if (numloops++ == maxloops)
      return 0;

  // wait for the pulse to stop
  while ((*portInputRegister(port) & bit) == stateMask){
    if(width++ == maxloops)  // added the check for end of pulse       return 0;
  return clockCyclesToMicroseconds(width * 20+16);  // Recalibrated because of additional code
   // in the width loop }

I added the code indicated by the comments in red (thanks to users in the Arduino Forum). This allowed exit from the measuring part of the pulse (in my case while measuring “white space”) and also re-calibrated the timing because more instructions are present in that part of the code.

The latest release of the Arduino software implements that fix. Release B07c of the Hifiduino code and newer leverage this fix. This means no need for a new function “newpulseIn()” and just use the plain pulseIn() function.  However, one advantage of the older code with the “newpulseIn()” function is that it works with either the old or new Arduino S/W. With Release B07c, Arduino v 0022 or newer is required


The Apple remote returns the following codes:
   Up key:     238 135 011 089
   Down key:   238 135 013 089
   Left key:   238 135 008 089
   Right key:  238 135 007 089
   Center key: 238 135 093 089 followed by 238 135 004 089 
   Menu key:   238 135 002 089
   Play key:   238 135 094 089 followed by 238 135 004 089 

For our application the only significant byte is the third byte. Also notice that the center key and the play key emit two sets of 4-byte codes. According to iospirit.com, the double set of code is for backwards compatibility since the new remote has an additional button as compared to the old remote. For the center key and play key, the second set of code corresponds to the old way and the first code distinguishes the separate keys.

Legacy hardware and old driver software receive the additional prefix code and ignore it. Right after, they receive and handle the “old” button code that follows and react to the “Center” and “Play/Pause” button presses like they previously did when receiving a “Play/Pause” button press from a plastic Apple® Remote.

Apple® found a smart solution to achieve backward compatibility. But it comes at a price: hardly any current Universal Remote will be able to correctly learn and emulate the new codes. I fully expect that, instead, they’ll just record and replay the raw IR signal of the new buttons. The effect of this will be that one button press on the Universal Remote will be translated into several raw replays of the new Apple® Remote codes. Or, in other words: one button press on the Universal Remote will act like multiple button presses, because that’s what’ll be sent.

Update: for some reason, there exist another set of valid codes for the Apple Aluminum Remote. You can read about it here.

  1. September 14, 2016 at 17:17

    regain relationship

  2. September 14, 2016 at 18:52

    Plastic Surgery

  3. September 17, 2016 at 08:48

    I know this if off topic but I’m looking into starting my own weblog and was curious what all is needed to get setup? I’m assuming having a blog like yours would cost a pretty penny? I’m not very internet savvy so I’m not 100 positive. Any suggestions or advice would be greatly appreciated. Cheers

  1. May 11, 2011 at 05:04
  2. May 14, 2011 at 05:54

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s