Low Cost Universal Remote for XBMC on Ubuntu

I currently have an RCA RCRP05BR 5 Device Cable Replacement Universal Remote (Black), and it works well for controlling an LG TV, Roku XD, and original XBox.  My home theater PC (picked up by a friend when Borders went out of business) did not have a built in infrared receiver, so the objective was to find a receiver compatible with the universal remote that would be nicely detected by Ubuntu.

The uncreatively named Wireless USB PC Remote Control Mouse for PC was cheap enough that I wouldn’t  be too unhappy if I couldn’t get it to work in Ubuntu. With the receiver plugged into the PC, lsusb indicates that it is a “Chaplet Systems, Inc. infrared dongle for remote.”  It even has a boot interface subclass 1, which means you might be able to use it like a keyboard from inside the BIOS.  Playing around with the remote, you can use it almost like a full keyboard and mouse, if you are patient enough to type via cellphone-multi-tap-esque entry.

Assigning Functions

The media control keys seemed to work automatically with XBMC, and the universal remote had no difficulty learning them.

The action of the 5×3 grid of keys is handled on the receiver side.  Pressing the up-arrow/2abc key always sends the same IR signal, but depending on the mode of the current mod of the receiver (toggled by the Numlock key), determines the command seen by the computer.  This means that you need to pick which mode you will use with XBMC, as there’s no great way to handle mode switching on the universal remote.  I opted to set the receiver in “white silkscreen mode.”  This gives you access to the arrow keys, enter key, tab, backspace, and escape, which already have context in XBMC.  The function assignments I came up with are in the following table:

PC Remote Key
RCA Universal Remote Key
XBMC Function
Play/Pause, Stop, Rewind, Fast Forward, Skip Back, Skip Forward
ArrowsArrowsNavigation
EnterOKSelect
TabGuideFullscreen mode toggle
BackspaceExitBack
Launch MailMenuContextual Menu

I’m a big fan of using the default controls whenever possible, but I ran out of white silkscreen commands on the PC Remote. I taught the E-mail button of the PC Remote to the Menu key of the universal remote.  Then, I mapped the launch_mail “key” in XBMC by creating a keymap file in the XBMC configuration directory.  On a standard Ubuntu/Mint install, it is ~/.xbmc/userdata/keymaps/, so I created a new file called pc-remote.xml in that directory with the following contents:

<keymap>
  <global>
    <keyboard>
      <launch_mail>ContextMenu</launch_mail>
    </keymap>
  </global>
</keyboard>

The full list of keys available for XBMC mapping is available on the XBMC wiki, including the names of media remote keys like launch_mail.

RCRP05BR Key Learning Procedure

For convenience, here’s the procedure for learning a key on the universal remote:

  1. Press and hold SETUP until the last-selected mode key blinks twice, then press 9 7 5.
  2. Press a mode key once (TV, DVR, CBL, DVD, AUD) to assign a mode for learning.
  3. Press the desired key on the RCRP05B once to put the remote in listening mode for the pressed key.
  4. Point the teaching remote at the learning remote about 2″ apart.
  5. Press (hold if necessary) the button on the teaching remote to be taught.
  6. Repeat steps 2 through 5 for each key you want to learn.  Press and hold SETUP until the active mode key blinks twice to exit programming.

Converting a jQuery array to an Ember array

Ember.js is incorporating more UI abilities natively every day, but for now there’s a lot of functionality provided by jQueryUI that is nice to take advantage of.  In order to convert the result of a jQuery selector or other array-like jQuery object, use the following:


properEmberArray = Ember.A($.makeArray(jQueryArrayLike));

Sorry if this is obvious, but it gave me some grief before I realized that I was calling map on a jQuery object and not a fully fledged Ember Array.

Installing MPLAB X and PICkit2 on Ubuntu

Background

In order to create the UAV flight control system from scratch, we’re going to need a microcontroller and a tool chain that is Linux compatible.  Since we know we’re going to be dealing with servo control signals, input capture (good for reading pulse widths), and PWM modules are going to be important in our device selection.  Microchip has a huge variety of microcontrollers available, and I have my eye on their dsPIC33 series because of the DSP hardware and variety of peripherals.  Also, I have some experience using them in previous hobby projects, as well as my Senior Design.  Best of all, I still have a PICkit2 emulator and PIC16F887 development board stashed away.

Installation

Download the installer from http://www.microchip.com/pagehandler/en-us/family/mplabx/#downloads. The installer is for both 64-bit and 32-bit systems, but if you are on a 64-bit system, you must first install the 32-bit compatibility libraries.

sudo apt-get install ia32-libs

Allow executing the downloaded script and run it.

chmod +x MPLABX-v1_70-linux-installer.run
sudo ./MPLABX-v1_70-linux-installer.run

Follow the fancy wizard. I installed to the default location (/opt/microchip/mplabx).

Screenshot from 2013-03-27 20:07:30

The wizard recommends rebooting after installation, but lets see how far we can get first. First, we’re going to install one of the compilers from http://www.microchip.com/MPLABxc. Since I’m interested in working with a PIC16F887 8-bit microcontroller, I’m going to install the XC8 compiler from http://www.microchip.com/mplabxc8linux.  You’ll need to mark the script executable and run it like we did for the IDE.  Make sure to configure the compiler in free mode.  We can activate the pro evaluation license down the road if desired, but it times out after 60 days.

If all goes well, when MPLAB X IDE is started (available in the launcher), it will indicate that it has found the compiler that was installed.

mplabx_ide

On Linux Mint with Cinnamon, I’m experiencing the symptoms described by https://github.com/linuxmint/Cinnamon/issues/473, but I can worry about that later.

Configuration

Create a new “PIC16 C Template” project from the “Samples/Microchip Embedded” category. There may be some configuration loading errors because the default project wants the “hi-tech-picc” build tool-chain. Open the tool-chain configuration from Run –> Set Project Configuration –> Customize…

Click Manage Configurations.., duplicate “XC8_PIC16F54,” and rename it to “XC8_PIC16F887.” Set it active. Select this new configuration from the Categories pane. In the configuration tab, change the family to Mid-Range 8-bit MCUs. Change the device to PIC16F887.  With the XC8 compiler installed, I get mostly green lights, and even the PICkit2 seems to be recognized.

pic16f887_config

Use Run –> Build Main Project to verify that the project can be successfully built. From Debug –> Debug Main Project, I can enter emulation, and pause and restart the program. I had to OK MPLAB changing the configuration settings to meet:

Watchdog Timer Enable bit = On
Low Voltage Programming Enable bit = RB3/PGM pin has PGM function, low voltage programming enabled

Modifying the stock main.c file a bit, we can make LED 0 blink:

/******************************************************************************/
/* Files to Include */
/******************************************************************************/

#if defined(__XC)
 #include <xc.h> /* XC8 General Include File */
#elif defined(HI_TECH_C)
 #include <htc.h> /* HiTech General Include File */
#endif

#include <stdint.h> /* For uint8_t definition */
#include <stdbool.h> /* For true/false definition */

#include "system.h" /* System funct/params, like osc/peripheral config */
#include "user.h" /* User funct/params, such as InitApp */

/******************************************************************************/
/* User Global Variable Declaration */
/******************************************************************************/

#define _XTAL_FREQ 4000000 // Default internal oscillator frequency

/* i.e. uint8_t <variable_name>; */

/******************************************************************************/
/* Main Program */
/******************************************************************************/
void main(void)
{
 /* Configure the oscillator for the device */
 ConfigureOscillator();

/* Initialize I/O and Peripherals for application */
 InitApp();

TRISD = 0; // Set port D as output

// Blink once per second
 while(1)
 {
 PORTD=0x01;
 __delay_ms(200);
 PORTD=0x00;
 __delay_ms(800);
 }

}

Conclusions

The installation and configuration for the PICkit2 was relatively painless. There are some configuration settings that need I haven’t resolved, but as a Linux microcontroller development toolchain, it seems competent. I prefer Eclipse-based IDEs over Netbeans, but the debugger integration is good and the IDE is certainly functional. It seems like there is support for the dsPIC33 series of microcontrollers, but I have to do some more research to know if they will work in MPLAB X with the PICkit2 or if a PICkit3 is necessary.

I do have some reservations that there is no open source compiler from Microchip. Ian from Dangerous Prototypes does a more eloquent job of explaining the state of the compiler license. This isn’t necessarily a deal-breaker, but for now, I’m going to take a look at some other microcontroller vendors and tool-chains.

Working with SASS on Bluehost

I’ve recently switched to WordPress since I was spending too much time configuring Drupal and not enough time making content.  I still prefer Drupal for sites that justify a CMS, but for a blog, why not use blogging software.  My biggest complaint with wordpress (other than The Loop) is how obviously WordPress most of the themes look.  I’m under no impressions that I can revolutionize WordPress aesthetics, but I figure I can make an obviously derivative theme on my own.

After a quick search, it seems like the big names in starter themes are Underscores and Bones.  I chose to go forward with Bones because it provides a little more default styling than Underscores.  Rather than styling with CSS, Underscores heavily recommends that you compile your stylesheets from LESS or SASS.  Since I have more familiarity with SASS, I’m going to go down that road.  However, either language should be compiled server side.  This blog is a low traffic learning experience, so I’m going to do all of my theme editing live (or on a testing subdomain) and not hosted locally.  It’s not great practice.

Anyway, lets work with SASS on Bluehost.  Our first step is to get SSH access to the Bluehost server.  You can request SSH access from the Bluehost cPanel. Once we have access to our account over SSH, we’ll need to install some gems.  Fortunately, Bluehost has the RubyGem package manager installed.

gem install sass
gem install --version '~> 0.8.8' rb-inotify # provides better performance when polling the filesystem for changed files

Now we watch the Bones library/scss folder for changes and automatically compile a new stylesheet:

cd <path-to-wordpress>/wp-content/themes/<my-bones-theme>
sass --watch library/scss:library/css

If we’re successful, we can edit _base.scss, change the body background, and watch sass recompile.  Then refresh your demo site and see your changes.  For more information on Sass, check out the tutorial.

Building a UAV

…or, how I started another project I was unlikely to finish.

It seems like everybody else has a UAV, and I don’t. So, let’s try to build one. I’m a poor writer, but if I force myself to document things in this blog, there’s a small chance I’ll keep myself from forgetting why I made decisions and going in circles.

I’m going to break down the UAV into a few subsystems to make things manageable.

  1. Airframe – holds things
  2. Flight Controller – keeps things flying straight and level and provide active stabilization on top of operator signals
  3. Mission Controller – make the UAV do interesting things on its own

There’s probably some other parts, but I don’t know enough about UAVs or R/C aircraft to speak to the subject. I’m not quite sure why I’m splitting up the Flight and Mission Controller yet, but it seems like a decent way of keeping the design requirements focused. I’ve been looking at some existing autopilot boards, and haven’t seem to find one I liked that had all the features I wanted. I’m looking for:

  • 8 receiver channels, with 1 channel being decoded in hardware to enable the autopilot or bypass the microprocessor
  • Accelerometer, gyroscope, altitude, and compass
  • DSP capable processor with a Linux compatible tool-chain

The architecture is something like this:

flight_controller

After some searching, I did the thing I usually do when I feel like Google isn’t providing a good idea of where the community is: hit up IRC. Nebukadneza from ##radiocontrol on Freenode was incredibly patient with me and pointed me towards the Naze32. It’s a great piece of hardware at an awesome price, but doesn’t have software independent bypasses. We’re doing a bunch of development stuff and need to give control to the ground operator if/when the software locks up. I’m going to thus use this minor nitpick to design my own flight controller. As I go, I’ll try to write articles about what I’ve learned and how I’ve applied it to the autopilot.

I’m open to any comments, criticisms, feature requests, etc.