Tag Archives: Linux

Early impressions of my RaspberryPi

RaspberryPi sitting in its case without the upper half
Last year I ordered a RaspberryPi; I wanted to check out the hype and, who knew, maybe I’d get a decent media (or at least music) player out of it. The machine arrived right in time for Christmas, together with an SD card preinstalled with Raspbian and a USB power supply.

Wow, the CPU of this thing is slow. I was lucky to get the new version with 512MB RAM, I guess. Any CPU-heavy task feels extremely sluggish, be it aptitude, X or — beware! — watching videos. The GUI software package that comes with Raspbian is all but useless, too, so I soon decided to stick to a native terminal.

I was quite disappointed with the video performance which resembled a slide show; I had wanted to use the Pi as media center, after all. So I did some research and learned that there is apparently only one player which can harness the hardware video decoding capabilities the Pi has to offer: the OMXPlayer.

Turns out Raspbian with OMXPlayer does a better job of playing full HD videos than my gaming PC, and without the noise and barely any heat. Of course, you should not start X but run the player from shell (yes, that works!); not the most intuitive interface — and you have to change the terminal font if you use a big TV — but very efficient. Files are stored on an external HD connected to another PC which the Pi mounts via ssh. So far, I have not experienced any problems with this setup.

The only sore point has been the board layout; the connectors you can’t go without (Ethernet, USB, HDMI, AC) face three different directions, so the Pi is awkward to place if you want to run all cables to the back. Some minor annoyances are missing codecs, for example WMV, and a handful of inconveniences in OMXPlayer.

I have not yet tried using XMBC which is supposed to work well. Installing it on Raspbian does not seem to be straightforward; maybe I’ll try out Raspbmc on another card. Does anybody have experience with that?

Keep Your Display Active

Do you have problems with your display going idle on you all the time, too? Here is the solution: trick it into believing you were doing something useful by doing something stupid.

while [ true ]; do xsendkeys Shift_L; sleep 30; done

Download Photos From Canon EOS

My Canon EOS 450D is not recognised as mass storage by my system when connected via USB. In order to get photos from camera to PC, you can use gphoto2:

echo -n "[pullphotos] Detecting camera ...";
gphoto2 --auto-detect > /dev/null;
sleep 1s;
echo " Done";

echo -n "[pullphotos] Pulling photos ...";
gphoto2 -P &> /dev/null;
sleep 1s;
echo " Done";

echo -n "[pullphotos] Rotating photos ...";
jhead -autorot * &> /dev/null;
echo " Done";

This script copies all images currently stored on the camera into the current folder and rotates them if necessary1. The necessary programs gphoto2 and jhead are available as packages with the same name from the Ubuntu repositories. Note that you have to empty your camera’s storage manually afterwards.

Furthermore, note that gphoto2 is a very powerful tool. It allows you to configure and control many aspects of your camera via USB, including remote capture—something you might want to employ?

  1. Employing some sensor trickery, modern cameras annotate image files with information about picture orientation.

Control Pulseaudio from Shell

As you know I mainly use Fluxbox on a minimal Ubuntu installation without access to all the every-day functionality provided by panel applets in Gnome, including volume control. Therefore, I have been using pavucontrol for controlling Pulseaudio. It is a really nice application that gives you very finegrained control, for instance over which application should be how loud. Lately I have been annoyed with opening a whole application just for the sake of adjusting volume a little bit, so I set out to find a way to control it via shell. Turns out there is no convenient interface to pulseaudio at all, leaving me to script something together, this time in Ruby. It uses a very unwieldy interface to Pulseaudio named pacmd, contained in Ubuntu package pulseaudio-utils.

def current
  c = IO::popen("pacmd \"list-sinks\" | grep volume | head -1").readlines[0]
  return c.split(" ").last.sub("%", "").strip.to_i

def max
  c = IO::popen("pacmd \"list-sinks\" | grep \"volume steps\" | head -1").readlines[0]
  return c.split(" ").last.strip.to_i - 1

def index
  c = IO::popen("pacmd \"list-sinks\" | grep index | head -1").readlines[0]
  return c.split(" ").last.strip.to_i

def set(v)
  IO::popen("pacmd \"set-sink-volume #{index} #{v}\"").readlines

def muted
  c = IO::popen("pacmd \"list-sinks\" | grep muted | head -1").readlines[0]
  return c.split(" ").last.strip == "yes"

def toggle
  t = 1
  if ( muted )
    t = 0
  IO::popen("pacmd \"set-sink-mute #{index} #{t}\"").readlines

interval = 5

if ( ARGV.size == 0 )
  puts current
elsif (ARGV[0] == "?" )
  puts muted
elsif ( ARGV[0] == "+" )
  set([current + interval, 100].min * (max / 100.0).round)
elsif ( ARGV[0] == "-" )
  set([current - interval, 0].max * (max / 100.0).round)
elsif ( ARGV[0] == "!" )

This is certainly not the most efficient way to do it, retrieving all the info multiple times, but it works and I do not perceive any delays. Note that the script will just use the first sink that pacmd prints, so if you have a setup with multiple sinks you will have to be more clever.

Of course, the obligatory Fluxbox key bindings

None XF86AudioLowerVolume :execCommand pavol -
None XF86AudioRaiseVolume :execCommand pavol +
None XF86AudioMute :execCommand pavol !

and conky volume display:

Vol: ${exec if [ `pavol ?` != 'true' ]; then echo `pavol`%; else echo 'Muted'; fi}

Update: The script now has a home on GitHub.

Cover Art With conky And mpd

After one year of using mpd on my Fluxbox machine I have started to sift through my music collection, fixing tags and adding album covers. Since there is no need for having album art if you do not show it, I set out to make conky show the images on my disk. I was lucky to find script in the depth of some forum (reference lost) that inspired the following piece of bash code.

IFS=$'\t' mpd_array=( $(MPD_HOST=localhost MPD_PORT=6600 \
          mpc --format "\t%artist%\t%album%\t%file%\t") );


if [[ ! -f /tmp/"${mpd_array[1]}".album ]] ; then
  rm -f /tmp/*.album &> /dev/null;

  album=`dirname "/path/to/music/${mpd_array[2]}"`;
  cover=$album"/"`ls $album | egrep "jpeg|jpg|png|gif" | head -n 1`;

  if [[ ! -f $cover ]]; then
    cp $placeholder /tmp/$filename;
    convert $cover -resize "130>x" -alpha On -channel A \
                   -evaluate set 25% /tmp/$filename;

When this script is run, the currently playing album’s artist and name are retrieved and the corresponding image — or a dummy — is copied to /tmp for conky to pick up. Note that always the first image in the album’s folder is chosen and then manipulated with imagemagick; you might have to do a little coding yourself if you store your music or covers differently. Note that all time consuming stuff is done only once per album run.

On the conky side, life is easy now. Just add something like this to your .conkyrc:

${if_running mpd}
MPD: ${alignr}${mpd_status}${if_mpd_playing}
 ${mpd_artist 25}
 ${mpd_album 25}
 ${mpd_title 25}
 ${mpd_bar 3,130}
 ${exec ~/bin/conky_mpd_art}${image /tmp/conky_cover.png -p 3,772 -s 130x130 -n}

You have to adapt the visual thingies to your liking, of course.