Sunday, November 23, 2014

Raspberry Pi Media Center

Recently I created a Raspberry Pi DVR to record over-the-air TV.  I enjoyed working with the Pi so much that I wanted to do a second project and create a Raspberry Pi media center, more commonly called a Home theater PC (HTPC).  On my previous project I looked at many of the Linux distros available for the Pi, so this project was much easier.  It was merely a matter of putting together everything I learned from the first project.


Hardware
The hardware for this project was very similar to the first project.  I used another Raspberry Pi model B+, the same 16GB Samsung EVO micro SD card, the same 2 amp power supply, the same Rosewill RNX-N180UBE wireless network adapter, the same copper heat sinks, and the same case off etsy.  I felt the last hardware worked great, so I wanted to duplicate it.  The only new hardware I added was this wireless keyboard and trackpad to be able to control the media center (more on that later).


Software
Since this will be a media center I will be running XBMC, which basically means Raspbmc, OpenElec, or Xbian.  I previously tried all three distros.  I felt that Raspbmc was the oldest, slowest, and least desirable.  I really wanted to use Xbian, but it had problems for me (mainly the network adapter did not have drivers).  So I decided to use OpenElec.  Which is not so bad.  OpenElec is the smallest image of the 3 - I guess you could call it lean and mean.  It is also the most actively developed, which means it will probably run the best with the fewest issues.  As of now the latest stable image of OpenElec is 4.2.1, so that is what I used.

Installation is straight forward and simple.  Use Win32 Disk Imager to copy the image onto your SC card, boot the Pi, and follow the onscreen wizards to configure wireless network access.  Some more settings you might want to change in OpenElec are:
  1. The system name, so you can remotely access the machine via SSH.
  2. Enable Samba, to make it easier to access the machine by name instead of just IP address.
  3. Set one or more time servers so it has the correct time.  I used pool.ntp.org and time.windows.com.
  4. Set your timezone, also required to have the correct time.
In addition to these basic settings, there are some more advanced settings you might want to make:
  1. Under video playback, I set "adjust display refresh rate to match video" to always.  This should make video playback smoother.
  2. Disable any unused services, like Avahi (zeroconf) and Bluetooth.
  3. Disable control of XBMC over HTTP port 80, unless you want to use this feature.
  4. Enable overclocking.  I went for a more aggressive 900MHz CPU, 333 MHz GPU, and 450 MHz RAM.  As for temperatures.  At idle the Pi is 104° F, and playing a video it goes up to 111° F.  I know from previous tests the heatsinks reduce the temperature about 2° F.
  5. I personally set up a cron job to reboot the Pi every morning at 5 AM.  I figure I am asleep at that hour, so why not have it reboot itself to ensure any memory leaks do not get too large.  To create a cron job to do this you need to SSH into the machine.  Then type the command "crontab -e"  Add the line "0 5 * * * /sbin/shutdown -r now" and save the file.


MPEG2 License
The Raspberry Pi foundation sells a license key to enable MPEG2 hardware decoding for a small fee.  Here in the US, broadcast TV uses MPEG2 encoding.  Also, DVDs are encoded using MPEG2.  But the question is, do you need to buy this license?  Can the Pi still decode MPEG2 without the hardware encoder?  Can you overclock the Pi to better decode using software?  Well the answer is, you MUST buy this license.  Without the license, OpenElec will not even attempt to decode the video portion of an MPEG2 video.  The audio will play, but no video.  However, with the hardware license the Pi can play full HD MPEG2 videos with no slow down.  So if you plan to watch any MPEG2 content, you will need to buy the license.  It costs less than $5, so just go for it.


Remote Control
The remote control I purchased to control the media center was a mixed purchase.  One the one hand it works great.  Just plug the RF dongle into the Pi and the keyboard and mouse worked without any additional config.  I also love that the remote is RF wireless and not line-of-sight IR like all other remotes.  The downside is it's not the best as a media center remote.  First off, the touchpad is almost unusable.  Second, it lacks some common buttons that would be helpful - mainly Page Up and Page Down which make navigating XBMC easier, but also dedicated stop, play and pause buttons.

I was researching a replacement remote when I discovered something cool!  HDMI has something called Consumer Electronics Control (CEC).  This is basically a protocol that allows two devices connected via HDMI to talk to each other.  The Raspberry Pi running OpenElec supports CEC.  And it turns out my TV does to, although it was disabled by default.  When I enabled it CEC on my TV suddenly I could control XBMC using my standard TV remote control.  The buttons that work include up, down, left, right, enter, and escape for navigation as well as play, pause, stop, forward, and reverse.  So now with one remote I can control the TV and all aspects of XBMC.  I still have the other remote in the event I need a full keyboard or mouse, but CEC is definitely the way to go!


Results
I am very pleased with the results.  The Raspberry Pi makes a great low-cost low-power media center.  The ironic thing is, I connected this to a TV that is already a "smart" TV.  My experience is "smart" TVs are not that great.  Once you have used something like XBMC and see what a real media center could be like you won't go back to a "smart" TV.  The plug-ins available for XBMC make it a great media center.

No comments:

Post a Comment