Friday 2 November 2012

Pikea: A Custom Raspberry Pi Enclosure From an Ikea Plastic Food Container

After a long and disappointing[1] wait for my Raspberry Pi, friend and colleague Barry Carroll graciously gifted his one to me before I departed for Canada.

I finally got around to setting up OpenElec 2.0 on it as a media server to use in conjunction with my DNS-323 NAS, which works really well when you add the Android XBMC Remote into the mix.

I wanted an enclosure to keep it tidy and contained. A lot of the mass-produced ones available online are quite expensive so I had a rummage around the house to see what would suit. I found a small plastic  food container that my wife and I had purchased a few days earlier in Ikea; I believe it's part of the PRUTA set.


The board of Pi was big enough to fit in the top of the container but too big for the Pi to sit in the bottom of it.

All of the openings I created free hand using a Stanley (utility) knife, so if you feel like creating your own, use extreme caution! Alternatively, something like a Dremmel would be a good choice, but I didn't have one to hand.

I only made holes for the connections I'm using; HDMI, Ethernet, power and SD card. I marked holes for the USB and audio jack in case I need access to them in future. Making a hole for the RCA video connector was necessary, otherwise the Pi wont fit in this container.

Finished enclosure with ventilation holes in the lid



Notches were cut out for the corners of the board to make sure it remained seated. This also steadied the Pi when inserting/removing cables.



[1] - This deserves a blog post in its own right; suffice to say that Farnell/UPS made two failed attempts to deliver my Raspberry Pi to my office - an address that I've seen a UPS van outside of almost every day.

Monday 4 June 2012

Making Konsole the Default Terminal in Linux Mint 12

Last week I upgraded from Ubuntu 11.04 (Natty Narwhal) to Linux Mint 12 (Lisa). One thing that bothered me in Lisa was the lack of ability to select a terminal in the Preferred Applications settings; something that was available in Natty. My preference is to use Gnome Classic and to have Konsole as my default terminal.

Although not explicitly available in the settings, setting a preferred terminal was not as difficult as I thought it would be. Gnome uses GConf2 to handle these kind of settings. Using the gconf-editor on Natty, I could see that there was a setting entry for a terminal at /desktop/gnome/applications/terminal


On disk, this setting is stored in

~/.gconf/desktop/gnome/applications/terminal/%gconf.xml

In Lisa, there is no path to this file on disk, so lets sort that out. First install konsole, or your terminal of choice

sudo apt-get install konsole

Find the location of the konsole command. This is needed below:


noel@behemoth ~ $ which konsole
/usr/bin/konsole

Now create the setting

mkdir -p ~/.gconf/desktop/gnome/applications/terminal/
vim ~/.gconf/desktop/gnome/applications/terminal/%gconf.xml


In Vim, paste in the following text and save (:wq). 

<?xml version="1.0"?>
<gconf>
  <entry name="exec" mtime="1337527678" type="string">
    <stringvalue>/usr/bin/konsole</stringvalue>
  </entry>
  <entry name="exec_arg" mtime="1336942220" type="string">
    <stringvalue>-e</stringvalue>
  </entry>
</gconf>

With that in place, you should see your favorite terminal used with the Launch Terminal keyboard binding:

System Settings > Keyboard > Shortcuts 


Within Nautilus, the "Open in terminal" still launches the Gnome terminal. I suspect this is because Nautilus is a compiled dependency.

Sunday 23 October 2011

Garmin Forerunner 405 in Ubuntu 11.04

I recently decided it was time to improve my fitness. Keeping fit is one of those areas where I struggle to keep motivated, so I decided to bribe myself using the only currency I respect: gadgets.

After much deliberation and research, I chose a Garmin Forerunner 405 because of it's GPS accuracy and size. Linux compatibility was high on my list of concerns, and there aren't many articles to be found in Google about support for the 405. Thanks to this article, my apprehension was assuaged.

The Forerunner 405 comes with USB dongle called ANT+ that's used to communicate wirelessly with it, however Ubuntu doesn't correctly recognize the device out-of-the-box.

Setting up the ANT+ Dongle 

Plug the ANT+ stick in and run lsusb


noel@behemoth:~$ lsusb
Bus 003 Device 004: ID 0fcf:1008 Dynastream Innovations, Inc. 
Bus 003 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 002 Device 004: ID 17ef:1003 Lenovo Integrated Smart Card Reader
Bus 002 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 008: ID 0a5c:217f Broadcom Corp. Bluetooth Controller
Bus 001 Device 006: ID 04f2:b217 Chicony Electronics Co., Ltd 
Bus 001 Device 004: ID 147e:2016 Upek Biometric Touchchip/Touchstrip Fingerprint Sensor
Bus 001 Device 003: ID 0765:5001 X-Rite, Inc. 
Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub


The highlighted row above is the entry for ANT+. The important information is the USB vendor_id:model_id (0fcf:1008); it's what we'll use to tell Ubuntu how to set the device up.

Adding a udev Rule

Armed with the USB vendor ID and model ID of the ANT+, we can add a simple udev rule to make sure the usbserial kernel module is loaded for the ANT+.

Make sure you plug out the ANT+ before continuing.

sudo vim /etc/udev/rules.d/garmin-ant2.rules

Add the following on a single line:

BUS=="usb", SYSFS{idVendor}=="0fcf", SYSFS{idProduct}=="1008", RUN+="/sbin/modprobe usbserial vendor=0x0fcf product=0x1008"

You can see udev reacting to the ANT+ stick by running udevadm monitor before plugging it in.


noel@behemoth:~$ udevadm monitor
monitor will print the received events for:
UDEV - the event which udev sends out after rule processing
KERNEL - the kernel uevent

Plug in the ANT+ stick. You should see the following data output to the console:



KERNEL[1319380921.077220] add      /devices/pci0000:00/0000:00:1c.6/0000:0e:00.0/usb3/3-3 (usb)
KERNEL[1319380921.085927] add      /devices/pci0000:00/0000:00:1c.6/0000:0e:00.0/usb3/3-3/3-3:1.0 (usb)
KERNEL[1319380921.145292] add      /module/usbserial (module)
KERNEL[1319380921.145617] add      /bus/usb-serial (bus)
KERNEL[1319380921.145664] add      /bus/usb/drivers/usbserial (drivers)
KERNEL[1319380921.145723] add      /bus/usb-serial/drivers/generic (drivers)
UDEV  [1319380921.145742] add      /module/usbserial (module)
UDEV  [1319380921.146218] add      /bus/usb-serial (bus)
UDEV  [1319380921.146477] add      /bus/usb/drivers/usbserial (drivers)
UDEV  [1319380921.146493] add      /bus/usb-serial/drivers/generic (drivers)
KERNEL[1319380921.193433] add      /devices/pci0000:00/0000:00:1c.6/0000:0e:00.0/usb3/3-3/3-3:1.0/ttyUSB0 (usb-serial)
KERNEL[1319380921.193638] add      /devices/pci0000:00/0000:00:1c.6/0000:0e:00.0/usb3/3-3/3-3:1.0/ttyUSB0/tty/ttyUSB0 (tty)
KERNEL[1319380921.193861] add      /bus/usb/drivers/usbserial_generic (drivers)
UDEV  [1319380921.194619] add      /devices/pci0000:00/0000:00:1c.6/0000:0e:00.0/usb3/3-3 (usb)
UDEV  [1319380921.194695] add      /bus/usb/drivers/usbserial_generic (drivers)
UDEV  [1319380921.204297] add      /devices/pci0000:00/0000:00:1c.6/0000:0e:00.0/usb3/3-3/3-3:1.0 (usb)
UDEV  [1319380921.209858] add      /devices/pci0000:00/0000:00:1c.6/0000:0e:00.0/usb3/3-3/3-3:1.0/ttyUSB0 (usb-serial)
UDEV  [1319380921.243784] add      /devices/pci0000:00/0000:00:1c.6/0000:0e:00.0/usb3/3-3/3-3:1.0/ttyUSB0/tty/ttyUSB0 (tty)

You can see that the usbserial module has been loaded and the /dev/ttyUSB0 device has been created.

noel@behemoth:~$ ls -l /dev/ttyUSB0 
crw-rw---- 1 root dialout 188, 0 2011-10-23 15:43 /dev/ttyUSB0

The ANT+ stick is now set up as a USB serial device at /dev/ttyUSB0. This allows Gant to communicate with the Forerunner 405. 

Now that the device is properly recognized by Ubuntu, we can start working on Gant. 

Installing and Using Gant

Gant is a small program that interfaces with the Forerunner 405 and dumps your training data to the hard drive. You will have to compile and run it from source. Make sure you've got git and build-essential installed from the package manager:

mkdir -p ~/Development/Native/

cd ~/Development/Native/

git clone git://get-open.com/gant

cd gant/

make

Once that completes successfully, Gant is ready to communicate with your Forerunner 405. First you'll have to make a one-off pairing between Gant the your Forerunner 405.

Put Forerunner 405 into pairing mode:
Menu > Settings > ANT+ > Computer > Pairing > On

Also, make sure that communication is enabled:
Menu > Settings > ANT+ > Computer > Enabled > Yes

You may need to also set "Force Send". This seems to send all data on the device, whether or not the data's been downloaded from the device before.
Menu > Settings > ANT+ > Computer > Force Send > Yes

Pair gant with the Forerunner 405 (once off)
./gant -f Forerunner-405 -a auth405

You will be prompted to confirm the pairing on the device. Once complete, you'll have a file auth405 in the current directory. This will be used to authenticate all future communication between Gant and the device.

You should now be able to transfer your data from the Forerunner 405:
./gant -nza auth405 > output

Alternatively you can move the authorization file to your home directory; Gant looks for it there automatically:
cp ./auth405 ~/.gant
./gant -nz > output

If it completes successfully, you should end up with one more *.TCX files in the current directory. You can now upload these to Garmin Connect, or import them into a desktop training app like PyTrainer

Enjoy!


Friday 12 August 2011

Putting Your Screen to Sleep with Hot Corners in Ubuntu 11.04

A college lecturer introduced me to Red Hat 7.1 in 2001. From then on, I was intrigued by the flexibility of Linux and the community behind it. For a long time now I've wanted to use Linux exclusively as the operating system of choice for my home computer. In 2007, I felt that Linux wasn't quite there as a Desktop OS, so I splashed out on a Macbook.

Having a UNIX base, I was pleased with OSX and I'd gotten used to some of its nicer features. One of my favourite features was Hot Corners. Hot Corners are where an action happens as a result of moving the mouse pointer to a certain area of the screen (usually one of the four corners). Typical actions are Lock Screen, Start Screensaver and Show Desktop. Having a laptop, I found it particularly useful to be able to use a Hot Corner to put my screen to sleep in order to save power if I left it for a few minutes.

I recently bought a ThinkPad W520, wiped Windows 7, and installed Ubuntu 11.04 (Classic Gnome). ThinkPads are renowned for having most, if not all of their hardware supported out of the box by Linux, so a ThinkPad was a no-brainer. Much to my disappointment however, Hot Corners are not available by default in Ubuntu 11.04

After doing a little digging around on Google, I found that it was a two-part solution. First I needed to install the brightside package, which is available in the repositories:

sudo apt-get install brightside

Once brightside is installed, open its preferences panel through the Run Application dialog (Alt+F2):


By default, brightside does not have a "Sleep Screen" action, but it does have a "Custom" action which can execute an arbitrary script.


Add /etc/acpi/screenblank.sh to the "On entering region" field and leave all other settings as they are, then click "Close".


With that, it should work! Move your mouse to the assigned Hot Corner to try it out. One final thing to remember is to add brightside to the list of start up application. Go to System >> Preferences >> Startup Applications >> Add and put in the following details.


Ref:
1: [http://www.webupd8.org/2011/04/set-up-hot-corners-edge-flipping-in.html]
2: [http://ubuntuforums.org/showthread.php?t=1090923]