Shallow Thoughts : : Jul

Akkana's Musings on Open Source Computing and Technology, Science, and Nature.

Tue, 31 Jul 2012

Raspberry Pi quickstart: headless setup (no monitor)

Raspberry Pi, the tiny, cheap, low-power Linux computer, dropped their order restrictions a few weeks ago, and it finally became possible for anyone to order one. I immediately (well, a day later, since the two sites that sell them were slashdotted with people trying to order) put in an order with Newark/element14. They said they were backordered six weeks, but I wasn't in a hurry -- I just wanted to get in the queue.

Imagine my surprise when half a week later I got a notice that my Pi had shipped! I got it yesterday. Thanks, Element14!

The Pi comes with no OS preloaded -- it boots off the SD card. a download page where you can get an image of Debian Wheezy their recommendation), Arch, or several other Linux distros. I downloaded their latest Wheezy image and unzipped it.

But instructions on what to do from there are scanty, and tend to be heavy on "click on this, then drag to here" directives that make no sense if you're not using whatever desktop they assume you have. So here's what ended up working.

Writing the SD card with dd

First, make sure you downloaded the image correctly: sha1sum and compare the sum it prints out with the one on the download page.

Then get an appropriate SD card. The image is sized for a 2G card, so that's what I used, but you can use a larger card if needed ... you'll only get 2G initially but you can resize the partition later.

Plug the SD card into a reader on your regular Linux desktop/laptop machine, and figure out which device it is: I used cat /proc/partitions.

Then, assuming the SD card is in /dev/sdb (make sure of this! you don't want to destroy your system disk by writing the wrong place!)

dd bs=1M if=2012-07-15-wheezy-raspbian.img of=/dev/sdb
Wait a while, make sure all the lights are off in your SD drive, then remove the SD card from the reader. (Yes, even if you're about to mount it to change something.)

Headless Raspberry Pi

Now you have an SD card that will probably boot your Pi. If you want to run X on it and see a desktop, you'll need a USB keyboard and mouse, some sort of monitor, and the appropriate cable. That stopped me. The Pi needs either an HDMI to DVI cable -- which I don't have, though I will buy one as soon as I get a chance -- or an RCA composite video cable. I think our old CRT TV can take composite video, but what I see on the net suggests this is a poor solution for the Pi since the resolution and image quality aren't really adequate.

But in any case, one of my main intended uses for the Pi involves using it headless, as a robotics controller, in connection with an Arduino or other hardware for analog device control. So the Pi needs to be able to boot without a monitor, taking commands via its built-in ethernet interface, probably using ssh. That means making some changes to the SD card.

Reinsert the card. (Why not just leave it in place? Because the image you just wrote changed the partition table, and your computer won't see the change unless you remove and reinsert the card.)

The card now has two partitions on it -- you can check that via /proc/partitions. The first is the /boot partition, where you shouldn't need to change anything. The second is the root filesystem. Mount the second partition if your system didn't do that automatically:

mount /dev/sdb2 /mnt

Now specify a static IP address, so you'll always know how to get to your Pi. Edit /mnt/etc/network/interfaces and change the iface eth0 inet dhcp line to something like this, using numbers that will work for your local network:

iface eth0 inet static

Now, if you google for other people who want to ssh in to their Raspberry Pis or run them headless, you will find approximately 1,532,776 pages telling you that to enable sshd you'll need to rename a file named boot_enable_ssh.rc somewhere on the /boot partition to boot.rc. Disregard this. There is no such file on the current official wheezy pi images, and you will go crazy looking for it.

Happily, it turns out that the current images have the ssh server enabled by default. You can verify that by looking at /mnt/etc/init.d/ssh and seeing that it starts sshd. So after setting a static IP, you're ready to umount /mnt

You're done! Remove the card, stick it in the Raspberry Pi, plug in an ethernet cable, then power it with a micro USB cable. Wait a minute or two (it's not the world's fastest booter, and you should be able to ssh pi@ or whatever address you gave it. Log in with the password specified on the Downloads page where you got the OS image ... and you're good to go.

Fun! Now I'm off to find an HDMI-DVI cable.

Tags: , , ,
[ 21:26 Jul 31, 2012    More hardware | permalink to this entry | ]

Fri, 27 Jul 2012

A haunted clock

One of the local digital clocks has developed some odd behavior.

It's in a location where it doesn't get seen that much, so it never got reset to daylight savings time, and consequently has been off by an hour since the last time switch. But that's not the odd part.

The odd part is that some time in the evening, between 10 and 11 pm, it stops displaying 9:something or 10:something like it had been, and switches to 12:44. It will then stay on 12:44 for hours, usually all night and occasionally into the morning, before switching back to one-hour-before-current-time some time in the mid-morning. Then it stays at the (one hour off from) correct time all day -- it doesn't fail again in the afternoon to show 12:44 pm. It only does its 12:44 trick late at night.

Once I noticed it, I tried resetting it to daylight savings time, to see if that would kick it out of its old habits. After the reset, the time stayed correct through most of the evening (I had an insomniac night, so I had all too many chances to check it). But then in the morning, around 8 am, there it was, showing 12:44 again. It corrected itself before 10 am.

Definitely one of the odder failure modes I've seen in a while ...

[ 15:55 Jul 27, 2012    More misc | permalink to this entry | ]

Sat, 21 Jul 2012

Vim tip: opening lines without delay

I use vim to reply to email messages in mutt. And something I do very often is to open some new lines between quoted sections. For instance, if I'm replying to mail with a section like

> Have you noticed anything weird about squirrels lately?
> I think they're plotting something.
I might want to open up space after the first line, and say
> Have you noticed anything weird about squirrels lately?

You too? One of our local squirrels ran off with my Arduino yesterday.

> I think they're plotting something.
So I need three blank lines, with the cursor on the middle line.

In vim, typically I would place the cursor on the line before the space I want to open, and type o<RETURN><ESC>O :

open a line below the current line
make an empty line below the quoted line
get out of insert mode
open a new line above the current line and enter insert mode there

Sounds complicated, but it's pretty fast to type o<RET><ESC>O especially when you do it many times a day.

Except vim has an odd quirk: after you type that O, you have to wait a second or two. If you start typing immediately, somehow you're not in insert mode any more, and the line you just opened, and thought you were typing in, disappears.

Well, it turns out this happens because <ESC>O is a sequence that can also happen from arrow keys. So vim has a timeout it uses to figure out whether an <ESC>O sequence was from an arrow key, or two characters typed by a real person. If the O follows too soon after the <ESC>, it figures it's an arrow key. (This is discussed in more detail in this Stack Overflow thread: Vim: Delay before 'O' opens a new line?)

It turns out there's a simple solution: set the timeout much shorter, like 100 milliseconds, in .vimrc:

set ttimeoutlen=100

Then arrow keys should still work -- unless you typically use vim over a very slow connection -- but you can type the sequence yourself (unless you type very fast) and not have it confused with an arrow key.

But really, there's a better solution. Since opening up space like this is something I do so often, why not make a vim binding for it?

map <leader>o o<CR><ESC>O

Now all I have to do is type \o (backslash, \, is the "leader" character) and I get a space opened up, with a blank line both before it and after it.

Tags: ,
[ 12:20 Jul 21, 2012    More linux/editors | permalink to this entry | ]

Mon, 16 Jul 2012

Editing tab-separated files with Emacs

I wanted to keep maintenance records for my car in a local file. Things like the date and mileage of the last oil change, when the timing belt was replaced, stuff like that.

I didn't want to hassle with databases or spreadsheets -- a simple, human-readable file is a lot easier to deal with. But I also wanted it in a predictable format so it could potentially be parsed later: I might some day want to write a program that keeps track and reminds me when I need to do things. (You'd think this program would already exist, but curiously, I haven't found one.)

So, something like:

7/9/12 <TAB> 86306 <TAB> Oil change, filter
6/11/12<TAB> 84813 <TAB> Smog test

Simple, right? And super easy just to type in in a text editor.

Well ... in emacs, maybe not. As an editor oriented toward programmers, emacs tends to prefer spaces instead of tabs ... and that's normally the way I prefer it. Tabs are a bad idea in most software projects, unless everybody on the project has already agreed on a tab style and width. (The complete tabs-vs.spaces religious war is beyond the scope of this article, but take my word for it that they can be a problem.)

But this wasn't code, and I needed an easy way to get those tabs into the file. Of course, I could quote them directly: type Ctrl-Q TAB every time I wanted a tab. But I knew I wouldn't remember to do that every time.

So I needed a local variables line, sometimes called a modeline, to flag this file as different from any other file I edit -- in this one, I really do want a TAB when I hit the TAB key.

My first try put this as the first line of the file:

-*- Mode: Text; indent-tabs-mode: t -*-
(Actually, my first try omitted the -*- part and didn't work at all, but let's ignore that part.)

When I re-loaded the file, emacs loaded it in text mode, and indent-tabs-mode was set to t if I checked it with describe-variable. Great! I could add new lines at the end of the file, and when I hit TAB, emacs inserted tabs. But wait -- if I added a line at the beginning of the file, and typed something lke 7/9/12<TAB> ... it inserted a space, not a tab.

It turns out indent-tabs-mode isn't really documented. If you check the help, it says:

Indentation can insert tabs if this is non-nil
-- note that "can" insert, not "will" insert, a tab. So how could I get emacs to really insert a tab, every time I hit the tab key?

Well, of course, I could bind the TAB key to "self-insert". But I didn't want to change it for every file, only for this one. how could I make that happen as part of a local variables line? The local variables line documentation shows how to set variables or file modes, but it looks like you can't bind keys or run functions.

Well, you can't run functions, but you can define a new mode that runs functions. At the suggestion of some helpful people on the #emacs IRC channel, I defined a new mode in my .emacs, like this:

(define-derived-mode tabbed-mode text-mode "Tab separated mode"
  (local-set-key (kbd "TAB") 'self-insert-command)

Then in the file, I put this line:

-*- Mode: Tabbed -*-

Now, every time I load the file, emacs turns on tabbed mode -- which is just text mode except that the TAB key always inserts a tab.

Tags: ,
[ 19:35 Jul 16, 2012    More linux/editors | permalink to this entry | ]

Wed, 11 Jul 2012

Disregard this fitness claim!

[Sketchers self-contradictory advertising] I noticed this oddly self-contradictory message on a box in a shoe store.

It says:

The key to Shape-ups LIV by Sketchers is the diagonally curved bottom. It helps guide you back to the body's barefoot stride.


Doesn't the second paragraph contradict and cancel out the first one?

I was curious, so I did a little poking around. But all I found was accounts of Sketchers being pressured to pull an advertisement aimed at teen girls, in which it makes different claims regarding a different Shape-up shoe. Supposedly the advertiser was also putting stickers on shoeboxes saying "Disregard all fitness benefit claims."

But the box I was reading was an adult shoe, unrelated to the teen advertising cartoons, and the sign isn't a sticker -- it's part of the printing on the box.

So it's a mystery. To be honest, I was already primed to disregard any fitness claims I read on the front of a shoebox. But I guess it's glad that the company uses valuable advertising space to remind everyone to discount the company's own claims.

Tags: ,
[ 21:09 Jul 11, 2012    More humor | permalink to this entry | ]

Sat, 07 Jul 2012

Strange wildlife in San Luis Obispo

On a brief and visit to San Luis Obispo, an unexpected bonus was the unusual wildlife about town.

We walked from our hotel on Monterey St. to downtown to stretch our legs, explore the mission and river walk and then get dinner. (Mo's Smokehouse has excellent barbecue.)

On the way back, I noticed a small figure in the gutter just below the curb, scratching and nosing around in the litter there. It was the size and shape of a chipmunk, but its coloration showed it to be a California ground squirrel -- a baby, probably on one of its first forays out of the burrow.

Burrow? Well, as I pulled my camera out of a pocket, suddenly the youngster vanished. I stepped into the street to see where it had gone -- and discovered that SLO has gutter drain holes in their concrete curbs that are exactly the size and shape of a typical ground squirrel's burrow entryway.

[Grossly fat California ground squirrel at Morro Rock] The size of these tiny ground squirrels was especially amazing because just a few miles northwest, at Morro Rock, we'd encountered the most humungous, gihugicle California ground squirrels known to man -- animals so swollen from tourist handouts that at first I took them for prairie dogs. (I wasn't able to photograph the tiny and quick SLO squirrels, but the sluggish Morro Rock squirrels were a much easier target ... as you see.)

Back in SLO, we walked on, marvelling at the little squirrel -- and half a block later, another squirreling the same size as the other one dashed out from under a car, ran to the curb and disappeared. Yep -- another of those round gutter holes. They must have a whole colony of these cuties!

Then just a few blocks later, I noticed motion out of the corner of my eye ... and turned in time to watch a pair of scarlet macaws fly across the street, up an adjacent street and into a tree.

I read an article once from a biologist who visited South America and thrilled to the sight of these huge, bright red, long-tailed parrots flying free ... but I never expected to see the same thing on the street of a California city.

Tags: ,
[ 13:42 Jul 07, 2012    More nature | permalink to this entry | ]