Projects‎ > ‎

Raspberry Pi

Introduction

           

 
  The Raspberry PI is a very small and cheap computer that can be gough for about  35$. It has the following features
  • 256 MB RAM shared between GPU/CPU
  • ARM CPU 700MHz
  • HDMI output
  • 2 USB 2.0
  • 1 LAN
  • GPIO pins
  • SD card
  • Power supply: USB micro (minimum 700 mA)
  • Powerful GPU with hardware support for decoding H264(full HD)
Note that computers and powered USB hubs can only provide 500 mA so it is necessary to use an external power supply. I have choosen to use a cheap mobile phone charger that gives me 5V@1A. To be able to get good performance is it good to have a fast SD card so I bought a 8 GB ScanDisk Ultra(200X) SDSDU-008G-U46. It is possible to have smaller cards(minumum size is 2GB) but you probably want to have a larger SD card if you want to build something. Verified peripherals can be found here: RPi_VerifiedPeripherals.

Installation

I have used Raspbian "wheezy" (2012-08-16) from http://www.raspberrypi.org/downloads
The installation is quite simple, just write the image file to the SD card.
After inserting the SD card and connecting the Raspberry PI to your TV(by using HDMI) will you get a menu and the first step is to choose to use the entire SD-card(instead of just the first 2 GB). The Raspberry Pi is autamatically retrieving it's ip address by using DHCP so you can connect to it by using user:ip password: raspberry

Video Player

Introduction

The Raspberry Pi have a very good GPU that can be used for decoding movies.  This tutorial will use OMXPlayer which is a command line OMX Player for Raspberry Pi. Since the CPU is not so good in the Raspberry Pi must we use this player if we want to be able to play video files, without dropping frames during playback. The OMX Player has support for decoding H264. It is also possible to buy licences for decoding MPEG-2 and VC-1 licences from the Raspberry Pi Store.   OMX Player(omxplayer) is already installed in Raspbian so the tutorial below is only needed of you want to learn how to build omxplayer on the Raspberry Pi.

Installation

Before we start with downloading the omxplayer should we make sure that the system is updated and we also need to install some packages
$ sudo apt-get update && sudo apt-get upgrade
$ sudo apt-get install ca-certificates git-core binutils libboost1.50-dev libva1 libpcre3-dev

Download the source code:
$ mkdir /usr/local/src
$ sudo chown pi:pi /usr/local/src/
$ cd /usr/local/src
$ git clone https://github.com/thintux/omxplayer.git
$ cd omxplayer

I have created a fork of omxplayer since I wanted to fix the makefiles so that I can build omxplayer on Rasbian. My fork also include support for controlling the omxplayer through sockets instead of using only keyboard input.

My first compilation failed since cc1 was killed and the reason is that the compilation of ffmpeg requires a lot of memory
{standard input}: Assembler messages:
{standard input}:77896: Warning: end of file not at end of a line; newline inserted
{standard input}:77703: Error: undefined local label `.L3791'
{standard input}:77726: Error: undefined local label `.L3791'
{standard input}:77747: Error: undefined local label `.L3791'
{standard input}:77791: Error: undefined local label `.L3791'
{standard input}:77859: Error: undefined local label `.L3791'
{standard input}:77884: Error: undefined local label `.L3791'
{standard input}:77910: Error: undefined local label `.L3791'
{standard input}:77918: Error: undefined local label `.L3791'
gcc: internal compiler error: Killed (program cc1)
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-4.6/README.Bugs> for instructions.
make[1]: *** [libavcodec/h264.o] Error 4
make[1]: Leaving directory `/usr/local/src/omxplayer/ffmpeg'
make: *** [compile] Error 2

So we basically have two options to choose between
1. Increase the memory that can be used  by the CPU.
2. Create a large swap-file.

We are going the use option 2 so we need to create an temporary 200 MB swap file
$ dd if=/dev/zero of=/home/pi/swapfile1 bs=1024 count=204800
$ sudo su
# mkswap /home/pi/swapfile1
# chown root:root /home/pi/swapfile1
# chown root:root /home/pi/swapfile1
# chmod 0600 /home/pi/swapfile1 
# swapon /home/pi/swapfile1
$ exit

The first thing we need to build is the ffmpeg packge. The compilation time on my Raspberry Pi(with a 200X SD-card was) 170 min(measured with time)
$ make ffmpeg

We can now remove the temporary swap file
$ sudo su
# swapoff /home/pi/swapfile1
rm /home/pi/swapfile1
# exit

We don't need the standard omxplayer any more so we can remove it
sudo apt-get remove omxplayer

The next step is to build omxplayer. The compilation took about 10 minutes
$ make

Installation of omxplayer 
$ make dist
$ sudo su
# cp -av omxplayer-dist/* /
# echo "/usr/local/lib" >> /etc/ld.so.conf
# ldconfig 

Usage

The omxplayer is now installed so we can now start to use it. To be able to transfer sound from the Raspberry Pi to the TV must we use option "-o hdmi".
A good place to find movie trailers is: http://trailers.apple.com/trailers/ and we are goind to download the movie trailer for the The Dark Knight(Batman) 
$ wget http://images.apple.com/movies/us/hd_gallery/gl1800/1080p/batman_begins_1080p.mov
$ omxplayer --socket -o hdmi -r batman_begins_1080p.mov 


The socket api is very small but it has support for pause/resume, info(number of seconds that has been playes so far) and quit(terminate the player) 
$ echo "pause" | nc 192.168.0.67 5000
OK
$ echo "pause" | nc 192.168.0.67 5000
OK
$ echo "info" | nc 192.168.0.67 5000
OK 62
$ echo "invalid" | nc 192.168.0.67 5000
NOK Unknown command
$ echo "pause" | nc 192.168.0.67 5000
OK

The socket api is itself not enough if we want to control the video player remotely, since we don't have the ability to start omxplayer. Tux Media Center(TMC) has support for selecting which file we want to play, by using a multi platform(Web) GUI and it has support for using the Raspberry Pi to play video files. 

Consumer Electronic Control(CEC)

Introduction

The Raspberry Pi has support for CEC and one thing that can be quite useful is the ability to set the Raspberry Pi as active source, i.e. the TV(must have CEC support) will automatically switch to the HDMI source that the Raspberry Pi is connected to. It is also possible to tell the TV to enter standby mode. We will use libCEC from PulseEight

Installation

To be able to build libCEC must we begin with installing some packages
sudo apt-get install git-core autoconf automake libtool liblockdev1-dev

We also need to setup some symbolic links and copying some include files so that libCEC can find the required files:
sudo ln -fs /opt/vc/lib/libEGL.so /usr/lib/libEGL.so
sudo ln -fs /opt/vc/lib/libEGL.so /usr/lib/arm-linux-gnueabihf/libEGL.so
sudo ln -fs /opt/vc/lib/libEGL.so /usr/lib/arm-linux-gnueabihf/libEGL.so.1
sudo ln -fs /opt/vc/lib/libEGL_static.a /usr/lib/libEGL_static.a
sudo ln -fs /opt/vc/lib/libEGL_static.a /usr/lib/arm-linux-gnueabihf/libEGL_static.a
sudo ln -fs /opt/vc/lib/libGLESv2.so /usr/lib/libGLESv2.so
sudo ln -fs /opt/vc/lib/libGLESv2.so /usr/lib/arm-linux-gnueabihf/libGLESv2.so
sudo ln -fs /opt/vc/lib/libGLESv2.so /usr/lib/arm-linux-gnueabihf/libGLESv2.so.2
sudo ln -fs /opt/vc/lib/libGLESv2_static.a /usr/lib/libGLESv2_static.a
sudo ln -fs /opt/vc/lib/libGLESv2_static.a /usr/lib/arm-linux-gnueabihf/libGLESv2_static.a
sudo ln -fs /opt/vc/lib/libbcm_host.so /usr/lib/libbcm_host.so
sudo ln -fs /opt/vc/lib/libbcm_host.so /usr/lib/arm-linux-gnueabihf/libbcm_host.so
sudo ln -fs /opt/vc/lib/libvchiq_arm.a /usr/lib/libvchiq_arm.a
sudo ln -fs /opt/vc/lib/libvchiq_arm.a /usr/lib/arm-linux-gnueabihf/libvchiq_arm.a
sudo ln -fs /opt/vc/lib/libvchiq_arm.so /usr/lib/libvchiq_arm.so
sudo ln -fs /opt/vc/lib/libvchiq_arm.so /usr/lib/arm-linux-gnueabihf/libvchiq_arm.so
sudo ln -fs /opt/vc/lib/libvcos.a /usr/lib/libvcos.a
sudo ln -fs /opt/vc/lib/libvcos.a /usr/lib/arm-linux-gnueabihf/libvcos.a
sudo ln -fs /opt/vc/lib/libvcos.so /usr/lib/libvcos.so
sudo ln -fs /opt/vc/lib/libvcos.so /usr/lib/arm-linux-gnueabihf/libvcos.so

sudo cp -R /opt/vc/include/* /usr/include
sudo cp /opt/vc/include/interface/vcos/pthreads/* /usr/include/interface/vcos

The code is retrieved by using git
$ cd /usr/local/src
$ git clone https://github.com/Pulse-Eight/libcec.git

We also need to configure libCEC:
cd libcec
autoreconf -vif
./configure --enable-rpi

I got some compilation issues during my first build:
make[2]: Entering directory `/usr/local/src/libcec/src/testclient'
g++ -DHAVE_CONFIG_H -I. -I../..  -I/usr/local/src/libcec/include -I/usr/local/src/libcec/src -I/usr/local/src/libcec/include   -g -O2 -fPIC -Wall -Wextra -Wno-missing-field-initializers -MT cec_client-main.o -MD -MP -MF .deps/cec_client-main.Tpo -c -o cec_client-main.o `test -f 'main.cpp' || echo './'`main.cpp
In file included from main.cpp:44:0:
../lib/platform/util/StdString.h:1598:14: note: the mangling of ‘va_list’ has changed in GCC 4.4
main.cpp: In function ‘int main(int, char**)’:
main.cpp:1139:35: error: invalid conversion from ‘int (*)(void*, CEC::cec_log_message&)’ to ‘CEC::CBCecLogMessageType {aka int (*)(void*, CEC::cec_log_message)}’ [-fpermissive]
main.cpp:1140:35: error: invalid conversion from ‘int (*)(void*, const cec_keypress&) {aka int (*)(void*, const CEC::cec_keypress&)}’ to ‘CEC::CBCecKeyPressType {aka int (*)(void*, CEC::cec_keypress)}’ [-fpermissive]
main.cpp:1141:35: error: invalid conversion from ‘int (*)(void*, const cec_command&) {aka int (*)(void*, const CEC::cec_command&)}’ to ‘CEC::CBCecCommandType {aka int (*)(void*, CEC::cec_command)}’ [-fpermissive]
main.cpp:1142:35: error: invalid conversion from ‘int (*)(void*, CEC::libcec_alert, const libcec_parameter&) {aka int (*)(void*, CEC::libcec_alert, const CEC::libcec_parameter&)}’ to ‘CEC::CBCecAlertType {aka int (*)(void*, CEC::libcec_alert, CEC::libcec_parameter)}’ [-fpermissive]
make[2]: *** [cec_client-main.o] Error 1
make[2]: Leaving directory `/usr/local/src/libcec/src/testclient'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/usr/local/src/libcec'
make: *** [all] Error 2
------------------------

that must be fixed. Use the patch(libCEC.patch) and apply it by using:
wget -O libCEC.patch "https://sites.google.com/a/roberteklund.org/www/projects/raspberry-pi/libCEC.patch?attredirects=0&d=1"
patch -p1 < libCEC.patch

The next step is to build and install the software. We also need to configure/update the dynamic linker since we have added shared libraries(*.so) in /usr/local/lib
make
sudo su
make install-strip
echo "/usr/local/lib" >> /etc/ld.so.conf
ldconfig

Usage

I have a Philips TV(42PFL3606H/12) that has support for CEC(Philips call it EasyLink) so the first step is to enable EasyLink by changing the TV:s settings. The first command that we will try to use is "scan" just to make sure that we have a connection between the Raspberry Pi and the TV:
$ echo "scan" | cec-client -d 1 -s "standby 0" RPI
log level set to 1
opening a connection to the CEC adapter...
requesting CEC bus information ...
CEC bus information
===================
device #0: TV
address:       0000
active source: no
vendor:        Philips
osd string:    TV
CEC version:   1.4
power status:  on
language:      swe


device #1: Recorder 1
address:       2000
active source: no
vendor:        Unknown
osd string:    CECTester
CEC version:   1.4
power status:  on
language:      eng


currently active source: TV (0)

CEC seems to be working since we can read the TV's vendor name. CEC has support for several commands but the most useful commands are:

Get current power mode
$ echo "pow 0000" | cec-client -d 1 -s "standby 0" RPI
log level set to 1
opening a connection to the CEC adapter...
power status: on

Tell the TV to enter standby mode
echo "standby 0000" | cec-client -d 1 -s "standby 0" RPI

Power on the TV
echo "on 0000" | cec-client -d 1 -s "standby 0" RPI

Tell the TV that the Raspberry Pi should be used as active source
echo "as" | cec-client -d 1 -s "standby 0" RPI
ċ
libCEC.patch
(2k)
Robert Eklund,
Sep 14, 2012, 12:38 PM
Comments