Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 17:46 02 Aug 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Reading the Apple Tv Remote with Mmbasic…

Author Message
Plasmamac

Guru

Joined: 31/01/2019
Location: Germany
Posts: 580
Posted: 02:08am 22 Jul 2025
Copy link to clipboard 
Print this post

If i remember me correct anybody in the Forum has released Code to read an AppleTV
remote. unfortunately i cant find anything about.
who can help?
thanks
Plasma
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2642
Posted: 03:33am 22 Jul 2025
Copy link to clipboard 
Print this post

It depends on what protocol AppleTV uses. MMBasic has the IR command which decodes NEC or Sony infrared remote control protocols.

If it uses Philips RC-5, RC-6 or Samsung32 or JVC-16 there are MMBasic Subs to decode them. They are in these threads.
RC-5 and RC-6
NEC, Samsung and JVC

If none of the above you will need to log the data transmitted by your remote control as a set of timestamps for rising and falling edges from an IR receiver.

CSub LOG can do that but I think it was last compiled for MMBasic V5.08, however IR data is slow enough to capture with MMBasic. I had a program to do just that but can't find it.
It went something like this untested prog.
'Untested IR time logging program.
 Dim integer m, N=100, IRpin = mm.info(pinno GP0) 'IR input pin, N = number of transitions to record
 Dim float b(N), T
 Setpin IRpin, Din

 Do :Loop Until Not Pin(IRpin) 'Wait for first falling edge then start recording
 T=timer
 Do While m<(N-2) 'get pulse/pause times from an IR receiver module
  Do :Loop Until Pin(IRpin) Or (Timer-T > 50)
  b(m)=Timer-T 'record time at rising edge
  T=Timer
  Inc m
  Do While Pin(IRpin) And (Timer-T < 51):Loop
  b(m) = T - Timer 'record negative time at falling edge
  T=Timer
  Inc m
 Loop

 Math V_Print b()
End
Values greater than 50mS indicate no more data.

Repeat for each button on the remote. The part of the data that doesn't change will be the Device code and data that is different for each button will be the Key code.

Edit
Tested, output from a NEC remote.
> RUN
  8.9940,   -4.4440,    0.5920,   -1.5980,    0.5930,   -1.6370,    0.5510,   -0.5410,    0.5540,   -0.5430,    0.5550,   -0.5430,    0.5560,   -0.5430,    0.5560,   -0.5400,    0.5500,   -0.5500,    0.5520,   -0.5090,    0.5910,   -0.5160,    0.5530,   -1.6350,    0.5940,   -1.6380,    0.5560,   -1.6360,    0.5510,   -1.6330,    0.5940,   -1.5970,    0.5930,   -1.6350,    0.5550,   -0.5440,    0.5560,   -1.6380,    0.5510,   -1.6380,    0.5510,   -0.5500,    0.5570,   -0.5450,    0.5550,   -0.5390,    0.5590,   -1.6290,    0.5900,   -0.5040,    0.5930,   -1.6400,    0.5510,   -0.5440,    0.5540,   -0.5440,    0.5550,   -1.6320,    0.5540,   -1.6390,    0.5530,   -1.6380,    0.5520,   -0.5450,    0.5550,   -1.6340,    0.5550,  -39.6920,    8.9630,   -2.2230,    0.5520,  -51.0490,    0.0930,  -44.4900,    8.9650,   -2.1800,    0.5930,  -51.0620,    0.0920,  -51.0650,    0.0930,  -51.0430,    0.0930,  -51.0610,    0.0880,  -51.0450,    0.0920,  -51.0650,    0.0930,  -51.0760,    0.0930,  -51.0690,    0.0890,  -51.0540,    0.0880,  -51.0610,    0.0930,  -51.0730,    0.0000,    0.0000,    0.0000
>

For NEC it starts with a 9mS burst of carrier to allow the receiver to set its AGC level followed by a 4.5mS pause then the start bit followed by Run-Length-Encoded data. 560uS pulses and data encoded in the pauses between pulses. Nominally 560uS = 0 and 1680uS = 1. A reasonable amount of variation is allowed as some IR chips use a rudimentary clock.

The -39.6920 pause indicates the end of data and the following bits indicate the button was held down longer than 1 cycle. Most other protocols don't use this feature.
The first value over 50 is a time-out at the end of the data.

An example of RC-5 Manchester code. Both pulses and spaces vary as each bit is composed of High/Low or Low/High half bits. Adjacent half bits join to make short or long pulses and pauses.
No initial carrier burst to set the receiver AGC so the receiver AGC needs to be fast attack slow decay.
> RUN
  0.9440,   -0.8680,    1.7730,   -0.8620,    0.8740,   -0.8720,    0.8360,   -0.9080,    0.8740,   -0.8710,    0.8750,   -1.7300,    1.7720,   -0.8670,    0.8770,   -1.7780,    0.8730,   -0.8730,    1.7680,   -1.7420,    0.8740,  -51.0580,    0.0940,  -38.5120,    0.8360,   -0.9020,    1.7360,   -0.9090,    0.8370,   -0.9090,    0.8360,   -0.8710,    0.9130,   -0.8660,    0.8740,   -1.7370,    1.7730,   -0.8700,    0.8770,   -1.7720,    0.8370,   -0.9090,    1.7340,   -1.7850,    0.8740,  -51.0510,    0.0930,  -51.0760,    0.0930,  -51.0750,    0.0930,  -51.0450,    0.0890,  -51.0460,    0.0940,  -51.0570,    0.0890,  -51.0760,    0.0890,  -51.0710,    0.0930,  -51.0790,    0.0930,  -51.0760,    0.0970,  -51.0430,    0.0930,  -51.0660,    0.0940,  -51.0440,    0.0950,  -51.0520,    0.0940,  -51.0580,    0.0890,  -51.0770,    0.0890,  -51.0750,    0.0890,  -51.0830,    0.0890,  -51.0850,    0.0890,  -51.0660,    0.0890,  -51.0750,    0.0890,  -51.0620,    0.0890,  -51.0800,    0.0890,  -51.0710,    0.0890,  -51.0460,    0.0940,  -51.0460,    0.0970,  -51.0410,    0.0000,    0.0000,    0.0000
>


Another difference between protocols is the carrier frequency.
Sony - 40kHz
NEC and variants - 38kHz
Philips - 36kHz.

NEC receiver bandwidth is usually wide enough to receive the others.
Edited 2025-07-22 18:13 by phil99
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2642
Posted: 01:01am 23 Jul 2025
Copy link to clipboard 
Print this post

Which type of Apple TV remote do you have?

  Quote  Apple TV Infrared Protocol
The Apple TV remote uses a combination of technologies for communication. While the Apple Remote (an older model) uses a modified NEC IR protocol with differential PPM encoding on a 38 kHz 950 nm infrared carrier
, the newer Apple TV remote, particularly for the Apple TV 4K, primarily uses Bluetooth for communication with the Apple TV box. However, it also includes an IR emitter for controlling other devices such as TVs and receivers.

For the Apple TV itself, it is not entirely IR-based; it uses Bluetooth for communication with the remote. However, some models do have an IR receiver, allowing for IR control of the Apple TV box.
The IR protocol used by Apple devices is unique and may require specific software or tools like IrScrutinizer or MakeHex to work with universal remotes.

If you want to control a receiver or TV using IR, you can enable the "Control Receivers and TVs" setting in the Apple TV's settings under "Remotes and Devices".
This allows the Apple TV remote to send IR signals to control other devices.

AI-generated answer. Please verify critical facts.


  Quote  From Wikipedia, the free encyclopedia
This article is about the Apple IR remote control. For the iOS iTunes Wi-Fi app, see iTunes Remote. For the Mac OS remote desktop software, see Apple Remote Desktop.
Apple Remote

The second-generation Apple Remote, released in October 2009
Developer Apple Inc.
Type Infrared remote
Release date October 12, 2005 (first generation)
October 20, 2009 (second generation)
Successor Siri Remote
The Apple Remote is a remote control introduced in October 2005 by Apple Inc. for use with a number of its products with infrared capability. It was originally designed to control the Front Row media center program on the iMac G5 and is compatible with many subsequent Macintosh computers. The first three generations of Apple TV used the Apple Remote as their primary control mechanism. It has now been replaced with the Siri Remote in the fourth generation. Prior to the Apple Remote, Apple produced several nameless IR remotes for products such as the Macintosh TV, TV tuner expansion boards, and the PowerCD drive.[1][2][3]

Design
Plastic (2005)

Original Apple Remote (2005)
The original Apple Remote was designed with six buttons and made of white plastic. Its shape and layout resembled the first-generation iPod Shuffle. A circular Play/Pause/Select button sat in the center of a larger four-button circle (clockwise): Volume Up, Next/Fast-forward, Volume Down, and Previous/Rewind. A separate Menu button was positioned below. Size - 83*32*8 mm. The price was set at US$29.00.[4]

Aluminum (2009)
Apple Remote Aluminium (2009)
Apple Remote Aluminium (2009)
In October 2009, the remote was redesigned as a thinner and longer aluminum version. The new remote was released along with the 27- inch aluminum iMacs and multi-touch Magic Mouse. The Play/Pause button was moved out of the center of the directional buttons and put beside the Menu button (under the directional buttons). The symbols for the Volume Up/Down and Next/Fast-forward buttons were replaced with small dots, to make it clear that the buttons were also used to move up, down, left, and right within menus. Along with the new design, the price was dropped to US$19.99. In earlier aluminum remotes, the navigation ring was flush with the curvature of the remote's aluminum body. In the later revision, the ring is slightly raised to make it easier to locate the ring by touch.

Replacement of the CR2032 battery in the original remote is done with a small pointed object such as a paper clip at the bottom right edge of the device, where the battery slides out on a tray. The newer version has the battery located behind a compartment in the middle of the device which is accessed by turning a coin in the compartment door's indent.[5]

Functions
The Apple Remote's original function was to enable navigation in Front Row, which allows users to browse and play music, view videos (DVDs and downloaded files) and browse photos. Although Front Row was removed from OS X 10.7 and later, some Apple software still works with the remote. It can still be used to control presentations in Apple Keynote, slide shows in iPhoto and Aperture, DVD films via DVD Player, and to play video, and audio in iTunes and QuickTime. Other software that is still compatible includes Elgato's EyeTV 3.5, and VLC media player. The remote can also be used to run presentations in Microsoft PowerPoint 2008 or in OpenOffice.org Impress.

Other functions controlled by the remote can include putting a device into sleep mode, selecting a partition to boot from on startup, and ejecting optical discs.[6] A device can be configured to respond only to a particular remote.[7]

iPods
An iPod placed in a dock featuring an IR sensor can be used with the remote for music and media control.[8] The iPod's menus cannot be operated with the remote. The Apple Remote can also be used to control the iPod Hi-Fi or third-party devices tailored to it.[9]

Boot Camp
Starting with Boot Camp 1.2, the remote has some functionality when a user is running Windows. If iTunes is installed on the Windows partition, pressing the Menu button on the remote will start the program. The remote's media controls also support Windows Media Player, as well as system volume control.[10] Other third-party programs may also utilize the remote's capabilities; media applications such as foobar2000 and Media Player Classic allow users to control their functions via the remote. Applications must be in focus for the remote to control them. Boot Camp 5, released on March 14, 2013, also includes drivers for the remote control.[11]

iOS app
Main article: iTunes Remote
Apple offers a free 'Remote' app for iOS devices (available in the Apple App Store) which allows for wireless control of iTunes on Mac/Windows computers or the Apple TV.


Footnote added 2025-07-26 12:02 by phil99
Found some extra info on WikiPedia.
  Quote  Apple Remote 2nd generation with lit infrared LED
Technical details
The Apple Remote uses a modified NEC IR protocol[21] which consists of a differential PPM encoding on a 1:3 duty cycle 38 kHz 950 nm infrared carrier.
There are 32 bits of encoded data between the AGC leader and the stop bit:[22]

Protocol on (μs) off (μs) total (μs)
leader 9000 4500 13500
0 bit 560 560 1120
1 bit 560 1690 2250
stop 560 — 560
The first two bytes sent are the Apple custom code ID (0xEE followed by 0x87), which are followed by a one byte command and a one byte remote ID (0-255)
making a total of 32 bits of data. All bytes are sent least significant bit first. The least significant bit of the command byte is a parity bit over the
command byte and the ID byte.[23] The commands consist of:

Value Button Command
0x01 Menu Menu
0x2e followed by 0x02 Center Select
0x03 Right Next/Fast-Forward
0x04 Left Previous/Rewind
0x05 Up Volume Up
0x06 Down Volume Down
0x2f followed by 0x02 Play/Pause Play/Pause
The aluminium Apple remote control has 7 buttons; the extra button is a play/pause button and sends the same code as the center button.
However, both these buttons prepend their code with another 32 bit sequence containing the commands 0x2f and 0x2e, respectively.
So my NEC_Rx Sub should give the correct Key (command) code (byte 3) but will ignore the ID code (byte 4).

The NEC_Tx Sub however sends an inverted copy of the Key code in byte 4, which may confuse an Apple device receiving it.

If there is a demand for it I will write Rx and Tx Subs for it.

Footnote added 2025-07-27 18:03 by phil99
Found some more info.
  Quote   https://hifiduino.wordpress.com/apple-aluminum-remote/
Apple’s IR format is custom and only “based” on NEC. They have taken the premise and re-used all the command bits in a custom fashion.

7 bits for the button code
1 PARITY bit
8 bits for ID

The parity is a XOR sum of the button and ID bits, and since it flips around between 1 and 0 depending on the other bits, of course you’ll think the codes are different between two remotes with two different IDs.

Press and hold MENU + PLAY/PAUSE on any Apple remote to change (roll) its ID
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2944
Posted: 05:26am 23 Jul 2025
Copy link to clipboard 
Print this post

Yes, the original Apple Remote (small silver one) I ‘decided’ a few years back and posted on here.
I will do a search later today and update (although someone else may find it before I finish work!).

It can definitely be done and worked very reliably …..
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2944
Posted: 05:31am 23 Jul 2025
Copy link to clipboard 
Print this post

Found it!

Forum link

If link fails for any reason, then search something like‘: Using an Apple Remote with MicroMite’

Hope this helps!

NOTE: if I remember correctly, since writing this code back then, I believe the IR command now decodes the Apple Remote (would need to test to confirm as it’s been a long while since using one!
Edited 2025-07-23 15:35 by WhiteWizzard
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2642
Posted: 08:47am 23 Jul 2025
Copy link to clipboard 
Print this post

@WhiteWizzard from your link the Apple remote protocol appears to be a variant of NEC so the MMBasic IR command should work.

The pulse timing isn't exactly the same, but close enough. 550µS vs. 560µS, same as Samsung32 variant, which does work.
The only other difference is byte 4 is a non-inverted repeat of byte 3 instead of inverted.
I think the IR command only uses byte 3 for the Key code so it should be ok.

The 16 bit Device code is &HEE87 or 61063.

Footnote added 2025-07-26 17:32 by phil99
  Quote  byte 4 is a non-inverted repeat of byte 3 instead of inverted
On further investigation that isn't correct. Byte 4 is a "remote ID number" whose purpose isn't explained.
Perhaps it is to allow different Apple remotes to control different things in the same room.
 
Plasmamac

Guru

Joined: 31/01/2019
Location: Germany
Posts: 580
Posted: 10:20am 23 Jul 2025
Copy link to clipboard 
Print this post

Thx a lot ! Will check it tonight! Thx again
Plasma
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2642
Posted: 01:48pm 23 Jul 2025
Copy link to clipboard 
Print this post

If that doesn't work this should.
'AppleTV (NEC) IR code logging program.
Dim integer Key, Dev, IRpin = MM.Info(pinno GP0) 'IR input pin
Dim float b(N), T
SetPin IRpin, Din

Do :Loop Until Not Pin(IRpin) 'Wait for first falling edge then start recording
Do While m<(N-1) 'get pulse/pause times from an IR receiver module
 Do :Loop Until Pin(IRpin) Or (Timer-T > 50)
 T=Timer
 Do While Pin(IRpin) And (Timer-T < 51):Loop
 b(m) = Timer-T 'record time at falling edge
 Inc m
Loop

' Math V_Print b()

For m=2 To 17
  If b(m)>0.4 And b(m)<0.8 Then  Dev = Dev<<1
  If b(m)>1.4 And b(m)<1.8 Then  Dev = (Dev<<1) +1
Next

For m=18 To 25
  If b(m)>0.4 And b(m)<0.8 Then Key = Key<<1
  If b(m)>1.4 And b(m)<1.8 Then Key = (Key<<1) +1
Next

Print "Device =";Dev, "Key = ";Key
End
Tested on Samsung32 and NEC remotes.

Edit.
Converted to a Sub for easier inclusion in a program.
'AppleTV (NEC) IR code logging program.
Dim integer Dev, Key, IRpin = MM.Info(pinno GP0) 'IR input pin
SetPin IRpin, INTL, IR_Rx

'Main
 Do
  Pause 5
  If Key>-1 And Dev>0  Then Print "Device =";Dev, "Key =";Key 'Dev>0 = Respond to any device
 'Replace Dev>0 (above) with Dev=&Hff87 or other device code you want it to respond to
  Dev=0 'prepare for next input
 Loop

 Sub IR_Rx 'get pulse/pause times from an IR receiver module
  SetPin IRpin, off 'Disable interrupt
  Local Float b, T, T2
  Local Integer m, N=33
  T2=Timer : Dev=0 : Key=0 'reset variables
  SetPin IRpin, Din 'prepare to read

  Do While m<=N And (Timer-T2 < 99)
   Do :Loop Until Pin(IRpin) Or (Timer-T > 29)
   T=Timer 'record time at falling edge

   Do While Pin(IRpin) And (Timer-T < 29):Loop
   b=Timer-T 'record pulse duration
   If b>11 Then Exit Do
   If m>1 And m<18 Then 'get Device code
    Inc Dev, Dev 'Shift bits up one, add 0 for short pulse
    If b>1.4 And b<1.8 Then Inc Dev 'Add 1 for long pulse
   EndIf

   If m>17 And m<26 Then 'get Key code
    Inc Key, Key 'Shift bits up one, add 0 for short pulse
    If b>1.4 And b<1.8 Then Inc Key 'Add 1 for long pulse
   EndIf

   Inc m
  Loop

  If m<N Then Key=-1 'missed some pulses, data invalid
  Pause 200 'prevent repeats
  SetPin IRpin, INTL, IR_Rx 'restore interrupt
 End Sub

End

Edited 2025-07-24 15:14 by phil99
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2642
Posted: 01:52am 01 Aug 2025
Copy link to clipboard 
Print this post

To see if the inbuilt IR command can read Apple remotes the NECsend Sub linked to in the second post has been updated to include the Apple protocol.
The result is the IR command gives adequate output to identify most buttons on most Apple remotes.

The main issues are:-
1/ Apple use the same device code for all remotes even though some have different buttons.
2/ Instead the remotes have a ID code in byte 4 which the IR command ignores. NEC use byte 4 for an inverted copy of the Key code for error detection.
3/ The LSB of the Apple Key byte is a parity bit that is calculated from the Key and ID codes.

As the NEC protocol is LSB first and the IR command is MSB first the parity bit is the MSB of the key code returned. To get the original key code:-

Key = (Key << 1) AND &hFE ' then reverse bit order.
Key = ((Key And 255) * &H0202020202 And &H010884422010) Mod 1023


Footnotes added to the third post explain the Apple protocol teased out by others.

The IR_Rx_NEC_V Sub has also been updated to decode both Key and ID.
The NECsend Sub has been updated to send Apple codes.
.
Edited 2025-08-01 13:39 by phil99
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025