The steps described in this post was tested and used on a Raspberry pi 3 running a debain wheezy distribution.
This post will include how to compile and use CEC, be aware that CEC only works with displays which supports the technology. The library we will be compiling in this post is the libcec
from Pulse Eight.
Dependencies
Before we can begin we need to ensure that all the dependencies required for libcec to compile and run are installed on the Raspberry pi.
sudo apt-get update && sudo apt-get install \
build-essential \
autoconf \
liblockdev1-dev \
libudev-dev \
git \
libtool \
pkg-config \
cec-client \
dh-autoreconf \
cec-utils
Download libcec
The next step will be to download the source files from the libcec repository on GitHub.
sudo git clone https://github.com/Pulse-Eight/libcec
cd libcec
The only version which support the Raspberry pi at the time of this writing is the 2.2.0
version of libcec. To get the correct version before we begin to compile the source, we have to checkout the source code from the git tag named libcec-2.2.0
.
git checkout tags/libcec-2.2.0
Compile source
We are now ready to compile the source code. Its important to notice the arguments we are passing to the configure
command. Those arguments sets our compilation target to the Raspberry pi. Be aware that this step can take few minutes, so go grab a cup of coffee while its running.
sudo ./bootstrap
sudo ./configure --with-rpi-include-path=/opt/vc/include --with-rpi-lib-path=/opt/vc/lib --enable-rpi
sudo make
Install libcec
We are now ready to install the compiled code so it can be used by the cec-client
.
sudo make install
Finally we have to run the ldconfig
command to enable the cec-client
to use the compiled source.
sudo ldconfig
Test CEC
Here are some examples of commands which turns the display on or off.
Remember this only works on displays which supports CEC.
# turn display off
echo "standby 0" | sudo cec-client -s
# turn display on
echo 'on 0' | sudo cec-client -s