Skip navigation

Raspberry Pi Projects

2 Posts authored by: pdcleyn

Introduction

In this post I will describe my initial tests to use the PiFace to control XBMC. This post is part of a series which is indexed on its introductory post.

 

Installing and configuring needed software

I initially started with a vanilla RaspBMC to get my project started, but soon it turned out that installing the dependency needed to get all software together broke the base functionality. So instead of diving into the reasons why XBMC no longer wanted to run on my adapted RaspBMC, I restarted with a vanilla Raspbian and installed all needed components on top.

 

Installing and configuring XBMC

I installed XBMC following this very nice blogpost: XBMC for Raspberry Pi | Michael Gorven. In order to be able to use the remote interface, you will need to change some settings on your XBMC. In the System section, select Settings and look for Services. Here you should find the section Webserver. Enable the webserver, provide a username and password and select a port number. You can go with the default parameters. r change them if you want to increase your level of security.

 

Screen Shot 2014-02-18 at 20.48.55.pngScreen Shot 2014-02-18 at 20.52.54.pngScreen Shot 2014-02-18 at 20.49.10.png

We now have a webservice available on our  XBMC to control it. This can easily tested from command line with following commands:

 

pi@rpi ~ $ wget  -q --header='Content-Type: application/json' --post-data='{ "jsonrpc": "2.0", "method": "INPUT.right" , "id": 1 }' http://xbmc:xbmc@10.0.1.100:8081/jsonrpc?request





This should move the 'cursor' in XBMC one position right. As you can see, you just need to send the right JSON encoded commands to the webservice in order to control XBMC. Besides controlling XBMC, you can also fetch date from it like the item currently playing, the content of your database, basically all info needed to create a full blown remote interface. I'll probably add some more of this stuff when visualising feedback from the system.  The complete XBMC API is well documented.

 

Installing the PiFace and its libraries

 

The PiFace is an add-on board for the Raspberry Pi offering some easy to control inputs and outputs, some onboard buttons and LEDs and two relays. In the pictures below, you see the my Pi with the PiFace on top. In case you're wondering, the nice little wireless keyboard comes with the XBMC bundle.

photo 1.JPG

photo 2.JPG

In order to control the PiFace, some additional software needs to be installed and the SPI kernel module needs to be activated. This is all well documented on the PiFace Digital Install Guide. These steps worked out pretty well for me.

 

piface-xbmc-remote

 

Using Python (my first python script, so don't be to hard on me ;-) ), it was fairly easy to create a script which catches the key which was pressed on the Piface (for now I just used the buttons on the shield it self) and send a command based on which key was pressed to XBMC.

 

I uploaded the code to GitHub so feel free to fork, extend and improve!

 

I copied the code below as well and it basically consists of two parts: a class 'face' which captures the key presses and a class 'remote' which sends the JSON commands.

 

 

Running the command without parameters will show following usage message:

 

$ ./piface-xbmc-remote.py
usage: piface-xbmc-remote.py [-h] [--debug] host port username password
piface-xbmc-remote.py: error: too few arguments



 

Following parameters can be specified at the command line:

 

  • host: the hostname or IP address where your XBMC is running
  • port: portnumber where the XBMC RPC API is reachable
  • username: username configured to have access to the remote API
  • password: password configured for above user

 

Optionally you can add the --debug flag which will show you some basic output when a key is pressed.

 

And finally, following video shows how it works:

 

Next up ...

 

Now that this basic setup is running, I will try to extend the setup by connecting external buttons. At least the 'enter' functionality is missing today to make this any useful ;-)

Project overview

I would like to create a multimedia system which my (young) kids can control themselves. XBMC on the RPi is a great system and has lots of easy ways to control, but although fiddling around with a keyboard or with remote controls on smartphones can be extreme fun for the kids, it is in general not really fit for our little ones to really get a movie selected or the sound adjusted. Especially in the weekend, mom and dad occasionally can enjoy an additional hour of sleep, so it would be great they can choose their own movie or show.

 

Besides controlling XBMC, we can go a step further and we could also control our DIY domotica system, dimming lights or powering the TV itself. In order to comfort mom and dad even more, a camera could provide a monitoring system.

 

You can follow my progress in separate blog posts:

  1. A child friendly multimedia center  - Part 2: PiFace controlled XBMC

 

Project steps

Multimedia center

XBMC will be at the heart of our media center. Using RaspBMC this should be straightforward to set up. With the XBMC bundle, we connect our RPi  with the HDMI cable to the TV. XBMC provides a JSON-RPC interface which we can use to build our own interface.

 

Interactive control board

In order to create an interactive control board, I plan to use a PiFace Digital. This addon shield should provide an easy way to add my own buttons which can than be mapped to XBMC functions. The state of the buttons will be read by a service on the RPi which will send the appropriate calls to the XMBC over the JSON-RPC interface.


To make it even more fun for the kids, I would like to add some light effects to the board. Using a LED matrix some response can be generated to clearly indicate e.g., the allowed sound levels.

Remote monitoring

 

By now, we should have a working media center which can be controlled by the kids to select their favourite movie while mom and dad can stay in bed for another hour. But, as worried parents you cannot directly catch your sleep again as it seems awfully quiet downstairs now. Are they just so focused on their favourite show or did they find something they are not supposed to play with? Can you ignore this doubt? Do you get out of bed to check and possibly disturb your angels while they watch their show or do you just grab your smartphone and check the camera on the PI to see what they are doing?

In this second part of the project, I would hook up the PI camera to RPI and make a web service so I would be able to remotely check the living room. Using the WiPi I can connect the RPi to our wireless network.

 

Home automation

 

In our home, we have most of the lights in our living room controlled by a wireless system. We don’t want our kids to stay in the dark all time, so I see two options for our kids to control the lights. Both options would use the RPI extension board I already made to create a webservice which can control the lights. It is an arduino like scheme on a Humble Pi connected to the RPi. With this board I can sent signals to the lights from the RPI. First option would be to just extend the card board control with some buttons to control the light. This should be straightforward with what we created before. Second option would be to have some (wireless) light sensors  verify if it is dark in the room when the entertainment system is used. If so, lights are automatically turned on. The RPi extension I made also contains a receiver for TinyTX like sensors, so I should be able to hook up those to read out the ambient light in the room. As we are now using both my own extension and the prototyping board needed for the cardboard control set, the PiRack might come in handy.  It seems it should be able to connect multiple extension boards to the RPi.

 

Finishing touch

 

The kids are not the only ones which would like to use the RPi media center! As a final touch, I would like to add a PiFace Control and Display to the stack to have some basic direct controls to the RPi. As the RPi could be used to collect data from the sensors (including temperature sensors), the display could show the latest received temperature readings. Using the buttons, I could change the function of the RPi from media center to Internet Radio and at the same time change channels.

Filter Blog

By date: By tag: