I have recently worked on adding external controls for my Raspberry PI CarPC project because while driving it is better to have some physical controls to rely on, rather than looking at the touch screen to find the buttons.
This post provide information on how to set up buttons or rotary encoders to control XBMC from Raspberry PI.
Rotary encoder
Rotary encoders are very cheap and very nice controls(eBay link). You can find them in car stereos for volume control. You can also use them to browse through menu items or to skip to next song etc.
They are looking very similar to a potentiometer, but there are major differences: they can be turned in both directions with infinite steps(you know just the direction of the spin), they provide digital output, a full rotation have a number of steps and they have push button also.
Connections for Raspberry PI should be done as follows:
+ pin to 3.3V
GND pin to Raspberry PI GND
SW to one GPIO
CLK and DT to two GPIOs
When the push button is pressed the pin labelled SW is connected to GND. This can be set up as any push button(see below).
Push button
The tool
I have created a tool to allow you interface rotary encoders(and also push buttons) with Raspberry PI GPIO's. Also you can set an XBMC command to be executed for click, left rotation and right rotation.
The tool can be otbained from my Google Code project(link to page).
It is very easy to use it. You just have to accomplish two steps:
- copy rpi-xbmc-remote in a place where it can be accessed from anywhere(e.g. /usr/bin)
- call it using sudo rpi-xbmc-remote /path/to/configuration/file
The configuration file
Example:
This post provide information on how to set up buttons or rotary encoders to control XBMC from Raspberry PI.
Rotary encoder
Rotary encoders are very cheap and very nice controls(eBay link). You can find them in car stereos for volume control. You can also use them to browse through menu items or to skip to next song etc.
They are looking very similar to a potentiometer, but there are major differences: they can be turned in both directions with infinite steps(you know just the direction of the spin), they provide digital output, a full rotation have a number of steps and they have push button also.
Connections for Raspberry PI should be done as follows:
+ pin to 3.3V
GND pin to Raspberry PI GND
SW to one GPIO
CLK and DT to two GPIOs
When the push button is pressed the pin labelled SW is connected to GND. This can be set up as any push button(see below).
Push button
A push button can have two states on or off. There are two ways to hook up a button to a logical circuit(e.g Raspberry PI GPIO's):
We have to use the first setup(with pull up resistor) for the tool to work properly. So, for the push button of the rotary encoder above, we have to cable it like this:I have created a tool to allow you interface rotary encoders(and also push buttons) with Raspberry PI GPIO's. Also you can set an XBMC command to be executed for click, left rotation and right rotation.
The tool can be otbained from my Google Code project(link to page).
It is very easy to use it. You just have to accomplish two steps:
- copy rpi-xbmc-remote in a place where it can be accessed from anywhere(e.g. /usr/bin)
- call it using sudo rpi-xbmc-remote /path/to/configuration/file
The configuration file
Example:
ip:localhostbutton:7:KB:returnencoder:clk:23:KB:up:dt:24:KB:down
The configuration file can reside anywhere on the disk. It provides a way to define two kind of inputs for XBMC: regular button and rotary encoder. Lines should be less than 100 characters in length. Lines starting with # are comments and are not being processed.
Example of regular button definition:
button:7:KB:return
- 'button' means it is a regular button
- '7' means use GPIO7 for this button
- 'KB' means XBMC device map
"KB" - Standard keyboard map
"XG" - Xbox Gamepad
"R1" - Xbox Remote
"R2" - Xbox Universal Remote
"LI:devicename" - valid LIRC device map where 'devicename' is the actual
name of the LIRC device
- 'return' means XBMC button name to be called(see XBMC keymaps)
Example of rotary encoder definition:
encoder:clk:23:KB:up:dt:24:KB:down
- 'encoder' means it is a rotary encoder
- '23' means use GPIO23 for rotary encoder CLK
- 'KB' means XBMC device map for rotary encoder left turn(same as above)
- 'up' means XBMC button name to be sent for left turn of the rotary encoder
- '24' means use GPIO24 for rotary encoder DT
- 'KB' means XBMC device map for rotary encoder right turn(same as above)
- 'return' means XBMC button name to be called(see XBMC keymaps)
Keep in mind!
You have to put a pull up resistor for every push button you define in the configuration file. If you don't do this then the state of the button will be variable when not pressed(it will oscillate between 0 and 1) and it will behave like it is pressed randomly.Have fun!