I have been using an ODROID-C2 with LibreELEC for quite a while, but was frustrated by the lack of Amazon Prime Video and Netflix support. I was also using a wireless keyboard/mouse to control it, which led to the disapproval from the spouse, so I wanted a proper TV remote control to control both the TV (power/volume) and the ODROID-C2.
Here is the procedure I followed. It assumes you are somewhat comfortable with Android, such as finding Apps, and Settings, and will require use of Linux via the Android Terminal Emulator.
This procedure is to install not only Kodi, but also Youtube TV, Amazon Prime Video, Netflix and some individual Channel Apps. It also helps with installing apps from the Google Playstore. Although Netflix would not install from the Playstore one can download the APK and install that. The Remote Control configuration took the most time, because I could not find a single online tutorial detailed the entire process. Hopefully this article will help others with that.
The first step is to install Android on a Flash Card. Android for C2 can be downloaded from https://goo.gl/cuLqSU. At the time of this article, v3.5 is the latest version, and that is what I used. Download the image, uncompress it and install it to the flash card using Etcher, which is available for many operatins systems, or win32diskimager, which runs on Microsoft Windows, or the Linux dd utility. More information may be found at https://goo.gl/RPyiwr.
Install the flash card into the ODROID-C2 plugged into a TV via HDMI along with a USB keyboard/mouse and power on. It takes a few minutes, but eventually you should end up with a shiny new Android system, and the mouse should allow you to navigate.
The first step after Android is running is to adjust the overscan on the screen. I found on my TV that all the edges were missing. I could not see the notification bar at the top and the soft-keys at the bottom were mostly truncated. This is easily fixed by using the “ODROID Utility” app. Through this utility you can set the resolution (the default “autodetect” also works for me), use the arrows to adjust overscan and turn off the blue LED, which blinks to distraction. After adjusting the settings in this app, you must click “Apply and Reboot”, which will reboot the system.
The next step is to install Google Apps to get the Google Play store utility. Using the stock default browser, the Google Apps APK can be downloaded from http://opengapps.org/.
On this page I selected the following:
- Platform: ARM
- Android: 6.0
- Variant: pico
Pico is the minimum collection. You can also try to install nano and micro. Although I did not install the Calendar and other apps on my TV box, I believe they will work.
Selecting Download will pull a ZIP file into the Download folder. This ZIP file needs to be treated as an Android Update, and hence is loaded using the same Odroid Utility App used to update the Overscan and Blue LED above. Run the Odroid Utility app, and click on the upper right corner (three dots). The menu present will have an option “Package install from storage” which is clicked. On the next page, choose “File Manager” and navigate to the Download folder where you will select the open_gapps ZIP file. You will be prompted to proceed, after which time the odroid will reboot and the Google Apps will be installed.
After the installation is complete, you can open the Google Play Store app and install the following:
- Amazon Prime Video
- Chrome Browser
- Pluto TV
- VPN client (if desired…I use OpenVPN)
Although there are numerous video apps, not all of them are TV-friendly. Install them one by one and test them to ensure they work as expected. You can uninstall the apps that do not work.
By default the Android setting “Settings -> Security -> Untrusted Sources” is set to “Yes”. This is needed to install Netflix. Netflix was the one app that is not available on Google Play Store. However, Netflix has a help page with a link to their v4.16 version of the APK at https://goo.gl/22XXZi.
I downloaded that APK and installed it with FileManager. It runs well with the remote control. There are newer versions of the Netflix APKs available from https://goo.gl/tkDbkz. However, when I downloaded a couple of them, I found they were not remote-control friendly. It is unclear why.
Configuring the apps is the same on all platforms. My Kodi installation communicates with a MythTV backend on another server which does all the LiveTV recording and manages my Movie collection. Finding the MythTV PVR addon was a bit of a challenge in Krypton. It is already in Addons->My Addons, but in a disabled state.
I use an ODROID-C2 TV box with some old TVs that I inherited, and the original remotes were lost long ago. However, I have lying around some old Dish Network 3.0 IR PVR remote controls. These can be had on Ebay for under $10. In my opinion these are good sturdy remotes with good tactile feel and enough buttons that I should be able to do what I need. They are also “programmable” in that they come with a list of TV and other Device Codes which cause them to emulate the other manufacturer’s remotes.
It was pretty easy to find the code to control my old TV. Power, Volume Up, Volume Down and Mute are all I really need. I thought I wanted “Input select” to work so that I can change HDMI ports, but nothing I did could get that remote button to work. Fortunately, the ODROID-C2 is the only input device I have, so no switching is needed. If I ever add a second HDMI device, it will probably require a revisit to the research process, to find a viable solution.
The first source of frustration was finding a device code that would activate all the buttons with the right protocol. The ODROID-C2 uses the Amlogic S905 chip which contains an interface to the Infrared receiver. The Hardkernel Android OS install contains the “amremote” driver built into the kernel (i.e., not loaded as a module). As far as I can tell, the “amremote” driver only recognizes the NEC Infrared Protocol. IR codes in other protocols (R5/R6 or Sony) simply are ignored by the “amremote” driver. If you want to read more on Consumer IR, check out https://goo.gl/WLgtv9.
Armed with a list of a few hundred codes, I sought out a remote control device code that would send NEC codes for all the buttons. Frustration set in when I found that many devices supported in the Dish Network remote control would only send codes for a limited set of buttons. I had a really hard time finding one that would send codes on the 5 navigation buttons (up, down, left, right and center). Many codes would facilitate only 3 options (up/down/center or left/right/center), or 4 or 5 of the options. I finally found a Memorex DVD player (code 709) which offered all 5 navigation directions and all the number buttons on the remote. It would not send the ‘*’, ‘#’, Volume or Mute codes. The Volume and Mute codes are relegated to the TV code and so I can only control the TV Volume using the buttons, not the Android Volume.
Since the “number keys” are mostly useless for a TV box (except for channel numbers), I re-purposed them in the remote.conf to perform operations such as the Android Home, Android Volume Up/Down/Mute and Fast Forward/Reverse.
To understand how an incoming IR signal gets to the App correctly you need to realize that there are 3 separate signals involved:
- the IR code as sent by the Remote
- the Linux KEYCODE, and
- the Android ACTION code
The trick is to map the incoming IR code to the correct Android ACTION code via a Linux KEYCODE, and this conversion is done by two separate files in Android:
/system/etc/remote.conf -- maps IR code to Linux KEYCODE /system/usr/keylayout/Vendor_0001_Product_0001.kl -- maps Linux KEYCODE to Android ACTION
In my case, both of these files required manipulation, although I tried to limit the changes to the keylayout. To change these files, I used the Android Terminal Emulator app, which gets me a “bash” shell, and the “vi” editor. If you do not know to use the “vi” editor, you may be able to copy the files to /storage, use the FileManager App that is installed and edit using that, and then copy back to the /system location. Below I rely on “vi” and various Linux commands to get the job done.
The first task is to change /system filesystem from ReadOnly to ReadWrite so that we can update the files. Open the Android Terminal Emulator app and type:
$ su - # mount -o remount,rw /system
The first command (su -) gives you SuperUser privileges. The first time you use it you will get a popup asking whether this app (Android Terminal Emulator) should always get this privilege. I answered “Yes” and made it permanent. It is assumed that all following commands will be done in with SuperUser privileges. If you leave Android Terminal Emulator and come back, you may need to run the ‘su -‘ command, again.
The second command will change the /system filesystem from ReadOnly to ReadWrite. Next, we need to edit /system/etc/remote.conf to turn on Debugging. Debugging will allow us to determine what codes we are receiving. Change “debug_enable” from “0” to “1” with vi and activate with remotecfg:
# vi /system/etc/remote.conf # remotecfg /system/etc/remote.conf
The file remote.conf is read by remotecfg which will parse the contents and then send the information to the amremote software in the Linux kernel. This is normally done once on boot as specified in /system/init.odroidc2.rc. It is convenient because we can make changes and then immediately activate them.
With debug_enable set to “1”, any remote sending an NEC protocol will be detected, and the amremote software will log errors to the system log. We will use “dmesg” to see that system log. Test the change now by using these commands:
$ dmesg -c > /dev/null # clear previous log contents $ while sleep 1; do dmesg; dmesg -c > /dev/null; done
With the “while sleep” running pressing a button on the remote control should elicit something like this:
[98086.788285@0] remote: Wrong custom code is 0x7c83ff00
The last four digits of the number at the end of the log message tells us what what remote type this is (0xff00 in my case). The default remote.conf from Odroid Android looks for code 0x4db2. I am not sure what the odds are that you have a remote with that code if you are not using the Remote available from HardKernel (https://goo.gl/yVLVLC). If you are unlucky, and the remote you are using does transmit 0x4db2, then you will see something else in dmesg. If you see nothing in dmesg, then you are not using a remote that transmits NEC protocol and must find another remote (or device code).
In my case, this is where I started searching the Dish Network 3.0 IR device codes looking for a suitable device. I set the device code in the remote, and hit the buttons to see if I got responses in dmesg. I tried many many codes until I was close enough to my requirements with the Memorex DVD code 709, which transmits remote type 0xff00.
The long HEX number 0x7c83ff00 is actually 2 pieces of real info. Break it up in into bytes: 7c 83 ff 00, and you should notice that the first 2 bytes are ones complement of each other (ie 01111100 -> 10000011 — zeros and ones flipped). Similarly, the 3rd/4th bytes are ones complement in many (but not all) cases. The “real” information is in bytes 2 and 3/4 (0x83 is the button, 0xff00 is the type of remote).
In remote.conf, it is now time to set the type of remote you are using in remote.conf by setting the entry for “factory_code” and replacing the XXXX with the 4 digit code found above (I set mine to 0xff000001):
$ vi remote.conf $ remotecfg /system/etc/remote.conf $ while sleep 1;do dmesg;dmesg -c > /dev/null;done
After these commands, you should again be able to press buttons and one of two things will happen: You will see an error indicating the remote button does not map to anything, or you will see information on what the button mapped to.
[101131.973324@0] remote: scancode is 0x00c5,invalid key is 0x0000. or [101214.803355@0] remote: press ircode = 0xc5 [101214.903456@0] remote: scancode = 0x74,maptable = 0,code:0x3ac5ff00 [101214.903492@0] [101214.993555@0] remote: release ircode 0xc5 [101214.997312@0] remote: scancode = 0x74,maptable = 0,code:0x00000000
The first one occurs because the button 0xc5 is not in remote.cfg. The second one occurs when the button is found in remote.cfg. If the remote you are using sends codes similar to those of the Hardkernel remote, you may see the second type of message.
This is where the fun begins. You need to press every button and see what code it sends, and note that. Then you need to figure out what you want it to do and find the Android action in the Vendor_0001_Product_0001.kl file that corresponds to the action you want the button to do. Finally, you need to get the Linux KEYCODE from Vendor_0001_Product_0001.kl that will be used to tie everything together.
These are the ANDROID actions I am using:
- POWER — key 116
- HOME — key 102
- BACK — key 15
- MENU — key 139
- DPAD_CENTER — key 97
- DPAD_LEFT 1 — key 105
- DPAD_RIGHT — key 106
- DPAD_UP — key 103
- DPAD_DOWN — key 108
- VOLUME_UP — key 115
- VOLUME_DOWN — key 114
- VOLUME_MUTE — key 113
- MEDIA_REWIND — key 121
- MEDIA_FAST_FORWARD — key 120
- APP_SWITCH — NO KEY available!
The last one, “APP_SWITCH”, is not in Vendor_0001_Product_0001.kl! It took me 2 hours to figure that one out. So I appropriated a key (158, which was formerly BACK) by updating Vendor_0001_Product_0001.kl with vi and changing “BACK” to “APP_SWITCH” on the appropriate line.
Now glue everything together by updating remote.conf in the key_begin/key_end section and possibly in the repeat_key_begin/repeat_key_end section. I do not rely on key repeats, so my repeat_key_begin/repeat_key_end section is empty. Also, I am not relying on the mouse_begin/mouse_end section either.
My resulting remote.conf file looks like:
work_mode = 0 repeat_enable = 1 repeat_delay = 40 repeat_period = 39 release_delay = 121 debug_enable = 0 factory_code = 0xff000001 left_key_scancode = 0x88 right_key_scancode = 0xc8 up_key_scancode = 0xc9 down_key_scancode = 0xd7 ok_key_scancode = 0x8b mouse_begin mouse_end key_begin 0xc5 116 # Power 0x8b 97 # Center 0xc9 103 # Up 0xd7 108 # down 0x88 105 # Left 0xc8 106 # Right 0x93 15 # cancel 0x93 15 # Info 0x81 114 # 1 -- becomes VOLUME DOWN 0x83 113 # 2 -- becomes MUTE 0xc1 115 # 3 -- becomes VOLUME UP 0x82 121 # 4 -- becomes REWIND 0x80 139 # 5 -- becomes MENU 0xc0 120 # 6 -- becomes FF 0x8d 8 # 7 0x8f 158 # 8 -- APP SWITCH 0xcd 10 # 9 0x8c 102 # 0 -- becomes HOME key_end repeat_key_begin repeat_key_end
Note that I also turned “debug_enable” off again by setting it to zero. After updating remote.conf again, type the following command:
$ remotecfg /system/etc/remote.conf
Now it is the time to test the remote. You want to test each app, since they can react differently to a particular code or ignore it completely. I am still not sure that I have all the keys where I want them, but the system is functional and usable.
Make a backup of Vendor_0001_Product_0001.kl and remote.conf by copying them to /storage/emulated/0/Download and make sure they are saved in the /system filesystem. If you upgrade Android, you may find that these files need restoration or your remote will not work anymore. Hope this is useful to at least one person. I will probably need to dig it up in the future so I can remember what I did. For comments, questions and suggestions, please visit the original forum post at https://goo.gl/6sc8GU.