CEC adventures on the Raspberry Pi

OUTDATED

I’ve written an updated version about compiling at CEC 3.0.0 on the Raspberry Pi

If you are just looking for a precompiled version, a-premade-libcec-deb

TL;DR

Many blogs tell you about how wonderfully easy it is to use the Raspberry Pi to interact with CEC. That was not my story. Two issues hit me: 1) the first HDMI cable I used did not have a CEC wire in it. 2) the cec-utils package in the raspbian repository doesn’t work. Cures are get a HDMI cable with the CEC wire and recompile libcec.

Preparation

To prevent failure due to already fixed bugs, I updated the RPi before doing anything else.

sudo apt-get update
sudo apt-get dist-upgrade
sudo rpi-update
sudo reboot

The cec-client program is in the cec-utils package.

sudo apt-get install cec-utils

First Errors

I’ve tested now with the original bad cable and the newly bought good cable, and the cec-client from the raspbian repositories always gives the following error

geoff@devpi:~$ cec-client 
No device type given. Using 'recording device'
CEC Parser created - libCEC version 1.6.2
no serial port given. trying autodetect: DEBUG:   [               2]	trying to autodetect all CEC adapters
FAILED

And similarly with the -l option to list the devices

geoff@devpi:~$ cec-client -l
DEBUG:   [               2]	trying to autodetect all CEC adapters
Found devices: NONE

Building a new cec package

First remove the cec-utils provided by the rasbian repository.

sudo apt-get remove libcec1 cec-utils

The source code for the cec package can be found on github. You get it by

git clone https://github.com/Pulse-Eight/libcec 

Install some extra packages for building. Make sure to install the libudev-dev. I missed that the first time around which caused another whole host of problems.

sudo apt-get install gcc liblockdev1-dev autoconf automake libtool checkinstall libudev-dev

The actual build is pretty easy but be prepared to wait a few minutes.

cd libcec
./bootstrap
./configure --with-rpi-include-path="/opt/vc/include" --with-rpi-lib-path="/opt/vc/lib/" --enable-rpi
make
sudo checkinstall
sudo ldconfig

Using the new cec-client

The newly packaged version cec-client ends up in /usr/local/bin/. With the dodgy cable in place the output looks like

geoff@devpi:~$ /usr/local/bin/cec-client 
No device type given. Using 'recording device'
CEC Parser created - libCEC version 2.1.4
no serial port given. trying autodetect: 
 path:     Raspberry Pi
 com port: RPI

opening a connection to the CEC adapter...
DEBUG:   [             104]	unregistering all CEC clients
DEBUG:   [             107]	Broadcast (F): osd name set to 'Broadcast'
DEBUG:   [             109]	InitHostCEC - vchiq_initialise succeeded
DEBUG:   [             110]	InitHostCEC - vchi_initialise succeeded
DEBUG:   [             111]	InitHostCEC - vchi_connect succeeded
DEBUG:   [             113]	logical address changed to Broadcast (f)
DEBUG:   [             115]	RegisterLogicalAddress - registering address e
DEBUG:   [             296]	logical address changed to Recorder 1 (1)
DEBUG:   [             297]	logical address changed to Free use (e)
DEBUG:   [             298]	Open - vc_cec initialised
NOTICE:  [             299]	connection opened
DEBUG:   [             301]	<< Broadcast (F) -> TV (0): POLL
DEBUG:   [             303]	initiator 'Broadcast' is not supported by the CEC adapter. using 'Free use' instead
TRAFFIC: [             304]	<< e0
DEBUG:   [             305]	processor thread started
DEBUG:   [             395]	command 'POLL' was not acked by the controller

That ‘POLL’ was not acked by the controller is the first indication that all is not well. Not having prior experience with CEC, I wasn’t sure at first if this was a real error or an indication that I had a dodgy implementation of CEC in my TV. After a few hours more of investigation I learnt that not all HDMI cables come with the CEC wire. A trip to my local supermarket and for only AUD$8 obtained a “high speed” HDMI cable that also advertised that it had the Audio Return Channel.

With the new cable in place the equivalent output looks like

ff@devpi:~$ /usr/local/bin/cec-client 
No device type given. Using 'recording device'
CEC Parser created - libCEC version 2.1.4
no serial port given. trying autodetect: 
 path:     Raspberry Pi
 com port: RPI

opening a connection to the CEC adapter...
DEBUG:   [             104]	unregistering all CEC clients
DEBUG:   [             107]	Broadcast (F): osd name set to 'Broadcast'
DEBUG:   [             108]	InitHostCEC - vchiq_initialise succeeded
DEBUG:   [             109]	InitHostCEC - vchi_initialise succeeded
DEBUG:   [             110]	InitHostCEC - vchi_connect succeeded
DEBUG:   [             112]	logical address changed to Broadcast (f)
DEBUG:   [             113]	RegisterLogicalAddress - registering address e
DEBUG:   [             295]	logical address changed to Recorder 1 (1)
DEBUG:   [             296]	logical address changed to Free use (e)
DEBUG:   [             297]	Open - vc_cec initialised
NOTICE:  [             298]	connection opened
DEBUG:   [             300]	<< Broadcast (F) -> TV (0): POLL
DEBUG:   [             302]	initiator 'Broadcast' is not supported by the CEC adapter. using 'Free use' instead
TRAFFIC: [             304]	<< e0 DEBUG:   [             306]	processor thread started DEBUG:   [             335]	>> POLL sent
DEBUG:   [             336]	TV (0): device status changed into 'present'

Pressing buttons on the TV remote now yields a satisfying

TRAFFIC: [            5836]	>> 01:44:02
DEBUG:   [            5837]	>> TV (0) -> Recorder 1 (1): user control pressed (44)
DEBUG:   [            5838]	key pressed: down (2)
DEBUG:   [            5839]	making Recorder 1 (1) the active source
NOTICE:  [            5841]	>> source activated: Recorder 1 (1)
TRAFFIC: [            5906]	>> 01:8b:02
DEBUG:   [            5907]	>> TV (0) -> Recorder 1 (1): vendor remote button up (8B)
DEBUG:   [            5909]	key released: down (2)
Advertisements
Tagged with: , ,
Posted in Uncategorized
8 comments on “CEC adventures on the Raspberry Pi
  1. […] ich den cec-client für den RPi selbst kompilieren. Dies klappt aber ohne Probleme mit dieser Anleitung. Mit dem […]

  2. Alex says:

    Please redo this with a Raspberry pi 2.

    • Alex says:

      Never mind. Just note that some versions of linux require the sudo to be added to the cec-client commands.

      • Hi Alex, Thanks for your comments. Could you post some error messages so that other people can more easily diagnose when they have the exact same problem? I’m guessing that they say something like “Permission denied”.

    • Alex has already got over his problem but to those reading and wondering if all this works on the RPi2 then the answer is “yes, its all the same.” I should also point out that I only test on Raspbian (the default OS that comes with the RPi)

  3. Arg, time wasting Pi says:

    This process doesnt work with raspbian wheezy and Pulse-Eight/libcec ver 3+

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: