Shallow Thoughts

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

Mon, 30 Mar 2020

D is for Devilish Place Names

It was surprisingly hard to come up with a "D" to write about, without descending into Data geekery (always a temptation). Though you may decide I've done that anyway with today's topic.

Out for a scenic drive to shake off some of the house-bound cobwebs, I got to thinking about how so many places are named after the Devil. California was full of them -- the Devil's Punchbowl, the Devil's Postpile, and so forth -- and nearly every western National Park has at least one devilish feature.

How many are there really? Happily, there's an easy way to answer questions like this: the Geographic Names page on the USGS website, which hosts the Geographic Names Information System (GNIS). You can download entire place name files for a state, or you can search for place name matches at: GNIS Feature Search.

When I searched there for "devil", I got 1883 hits -- but many of them don't actually include the word "Devil". What, are they taking lessons from Google about searching for things that don't actually match the search terms?

I decided I wanted to download the results so I could count them more easily. The page offers View & Print all or Save as pipe "|" delimited file. I chose to save the file.

Nifty Command-Line Tricks

The downloaded file is a format called CSV ("Comma Separated Values", though in this case they're separated by the pipe character, "|"), typically used in spreadsheets. I'm not really a spreadsheet person, and CSV files are just as easy to analyze using basic shell tools. Most Linux users are familiar with the power of the command line, but don't feel left out if you're not using Linux: the commands I'll show work fine on a Mac, and they probably work on Windows too if you use the Linux Subsystem for Windows.

I started with a basic count. I'd seen already, on the website's search page, that a lot of the names didn't actually have "Devil" in the name even though that's what I searched for, so that 1883 number is bogus. So I ran a grep -i devil to pick out the place names that actually do have "devil" in the name (-i means "ignore case", so it will find devil as well as Devil). Then I piped the result through wc, word count, using -l to count the number of matching lines:

grep -i devil GNIS_Devil.csv | wc -l

There are 1764 place names that actually do contain the word "Devil".

Hmm, I wonder which state is the most devilish? That's a little trickier using just shell commands. First we have to extract the state. Lines in the CSV file look like this:

"Devils Well"|"896970"|"Basin"|"De Baca"|"NM"|"340337N"|"1044154W"|"4400"|"Devils Well"|""|"13-NOV-1980"
So the state part looks like |"NM"|. How about if we look for anything that includes two uppercase letters between pipes and quotes?
grep -i devil GNIS_Devil.csv | sed 's/.*|\"\([A-Z][A-Z]\)\"|.*/\1/'
gets a list of all the 2-letter state abbreviations.

But that's not too useful; what I want to know is how many times CA appears, how many times NM appears, etc. There's a nice trick for finding that: sort the list, so you'll see all the AKs first, followed by all the ALs, and so forth. Then you can use uniq -c to count how many times each state appears. So you'll see 45 AK, followed by 22 AL and so forth.

Almost there: but I'd like them in order by number, with the biggest number (the most devilish state) first. So I'll add one more sort at the end:

grep -i devil GNIS_Devil.csv | sed 's/.*|\"\([A-Z][A-Z]\)\"|.*/\1/' | sort | uniq -c | sort

Ta-da: CA is the most devilish state, with 221 devilish features, followed by Oregon with 187. 52 states are represented (including DC and GU (Guam), with one feature each. Here are the top ten:

    221 CA
    107 OR
     97 TX
     77 CO
     75 WA
     75 ID
     64 UT
     61 MT
     52 NM
     52 MO

Black Mesa / Black Mountain

Just for fun, as long as I still had the GNIS search page in my browser, I had another search in mind. A longstanding source of amusement when driving around Española is how there are two "Black Mesa"s a few miles apart, easily within site of each other. (Locals tend to use the Tewa name Tunyo, meaning "Spotted", for one, and one of several Spanish names, Mesa Prieta, meaning "Dark Mesa", for the other; though for Mesa Prieta I prefer one of the earlier Spanish names, Mesa Canoa, referring to its long and slender canoe-like shape.) Anyway, there's a local joke that the average distance between two features called "Black Mesa" in the state is how far you can see.

Not every state has mesas at all, but in states that don't, mountains fill the void, and "Black Mountain" is at least as popular a name as "Black Mesa".

How many are there really? I searched the GNIS site separately for Black Mesa and Black Mountain. Turns out that the US has 303 Black Mountains, and only 49 Black Mesas.

For mountains, CA is the big winner with 62 Black Mountains, versus AZ, NV and NM in a three-way tie for second place with 26 each. Mesas are far less common: there are 28 Black Mesas in AZ, 26 in NM, and a handful scattered among five other western states.

Also neat: New Mexico has the same number of Black Mesas and Black Mountains, and the number of Black Mesas or Mountains (the sum of the two) in the state is the same as the number of Devils. (Thanks to Dave for pointing that out.)

I suppose this still counts as data geekery. But it was a fun and easy exploration on a topic I've been curious about for a while!

Tags: , , ,
[ 16:30 Mar 30, 2020    More linux/cmdline | permalink to this entry | comments ]

Thu, 26 Mar 2020

C is for Cabezon (and the Census too)

... You thought C would be coronavirus or COVID-19, I bet!

Well, I won't pretend I'm not as obsessed with it as everybody else. Of course I am. But, house-bound as we all are now, let's try to think about other things at least now and then. It's healthier.

[Cabezon Peak] One of the distinctive peaks here in northern New Mexico is a butte called Cabezón, west of the Jemez near Cuba.

It's a volcanic neck: the core of an old volcano, part of the Mt Taylor volcanic field. Once a basalt volcano stops erupting, the lava sitting inside it slowly cools and solidifies. Then, over time, the outside of the volcano erodes away, leaving the hard basalt that used to be lava in the throat of the volcano. It's the same process that made Tunyo or Black Mesa, the butte between Los Alamos and Española that's been featured in so many movies, and the same process that made the spectacular Shiprock.

Dave and I have driven past Cabezón peak several times, but haven't yet actually explored it. Supposedly there's a trail and you can climb to the top (reports vary on how difficult the climb is). One of these days.

Last week, Dave was poking around in a Spanish dictionary and discovered that -ón in Spanish is a suffix that denotes something larger. So, since cabeza means head, cabezón means big head. (Looking for confirmation on that, I found this useful page on 18 Spanish Suffixes You’ll Never Want to Let Go Of.) Apparently it can also mean stubborn, ditzy, or just having big hair.

But hearing that cabezón meant big head took me back to my childhood, and another meaning of cabezón.

When I was maybe ten, my father decided to take up fishing. He bought a rod and reel, and brought me along as we headed out to the docks (I don't remember where, but we were in Los Angeles, so it was probably somewhere around Santa Monica or San Pedro).

This didn't last long as a hobby; I don't think dad was cut out for fishing. And mostly he didn't catch anything. But on one of our last fishing trips, he caught a fish. An amazing fish. It wasn't especially big, maybe fourteen inches or so. It had a big head and a triangular body, with a flat belly as the base of the triangle. It had weird fins. It was dark olive green on two sides of the triangle, with a dull yellow belly. It looked prehistoric, and sent me running off to the books when we got home to make sure we hadn't caught a coelocanth.

[Cabezon, Scorpaenichthys marmoratus] After some research at the library (this was way pre internet), my father concluded that he'd caught something called, you guessed it, a cabezón.

Searching for photos now, I'm not so sure that's right. None of the photos I've found look that much like the fish I remember. But I can't find anything more likely candidates, either (though I'm wondering about the Pacific staghorn sculpin as a possibility). I guess fish identification even now in the age of Google isn't all that much easier than it was in the seventies.

I don't think we ever ate the fish. It sat in his freezer for quite a while while he tried to identify it, and I'm not sure what happened after that.

So maybe I've seen a cabezón fish, and maybe I haven't. But it was fun to learn about the -ón suffix in Spanish, to find out the meaning of the name for that distinctive butte out near Cuba. One of these days Dave and I will go hike it. And if we make it to the top, we'll try not to get big heads about it.

Tags: ,
[ 19:17 Mar 26, 2020    More nature | permalink to this entry | comments ]

Sun, 22 Mar 2020

B is for Badlands

[hiking in Nambe Badlands] The idea of blogging the alphabet came from a conversation during a hike in Nambe Badlands. It's beautiful a hike that we don't do very often, about 40 minutes from Los Alamos.

"Badlands" is a term for any sort of soft, dry, eroded terrain: a place of mostly dirt and loosely consolodated sandstone, where the terrain erodes into a maze of rounded hills, steep gullies and arroyos, with occasional pillars where harder rocks emerge.

Badlands are often fairly colorful due to the mixture of different rock and soil types. Arizona's Painted Desert, with its stripes of red, white and green, is a famous example. The colors around Nambe and the rest of the Española valley is more subtle: mostly reds, tans, yellows with a few bright white veins running through.

[Nambe Badlands white rim layer; Los Alamos in the background] One thing you get in the badlands is views. In the image at left, we're looking southwest past the "barrancas" of Pojoaque. You can see the Pajarito plateau -- the line of white buildings is part of LANL, fairly near my house in White Rock -- and beyond it, the Jemez mountains, Out of the photo behind us are the Sangre de Cristos, running up toward Taos and eventually Colorado.

[Nambe Badlands white rim gleams in the distance] The badlands themselves are interesting too. They're mostly Santa Fe Group sediments, eroded primarily from the Sangres with a little contribution from the Jemez. In this area, there's a prominent white layer running through. Since it's harder than the dirt on either side of it, it tends to make a "white rim" reminiscent of the famous Canyonlands White Rim, but of course the rock itself is very different. This white rim, while harder than the normal badlands dirt, is still relatively soft, flaky; it erodes to a powder anywhere where it's exposed.

Geology books don't cover this area, but as best I can determine, from papers online, the white layer is probably an ash layer that's part of the Skull Ridge group of the Tesuque formation (those are all finer gradations of the Santa Fe Group). There are four white ash layers, probably erupted from 13-16 million years ago (estimates vary quite a bit, but middle Miocene), possibly from Nevada. So although the white ash is volcanic, it's apparently quite a bit older than most of the Jemez and comes from somewhere else entirely.

It's hard to be sure: I wish geological papers included better maps. In the one Field Geology class I had the opportunity to take, we spent most of our time making maps, and I suspect maps are a big part of what most professional geologists do; but somehow, the geology papers online seem remarkably lacking in maps. Oh, well.

[Nambe Badlands Owl Tower] We climbed up to a high lookout for lunch, during which Charlie, our best birder, was scanning with binoculars and discovered an owl sitting in the tower across from our lunch spot. Alas, due to coronavirus "social distancing" concerns, she couldn't pass her binoculars around, but I was able to see the owl, just barely, with the little monocular I keep in my pack. After some debate over its size, and scrutinizing the photos (not good enough to be worth sharing) afterward, Charlie concluded (and I agree) it was a great horned owl.

[Ken inspects a Nambe Badlands formation] Badlands exploring is fun; aside from spectacular views, there are always interesting hoodooes and other rock formations to inspect. We did a relatively easy 5.5-mile loop, but there are plenty of other trails in the badlands that I'd like to explore some day.

A few relevant papers I found:

Tags: ,
[ 12:02 Mar 22, 2020    More nature | permalink to this entry | comments ]

Wed, 18 Mar 2020

A is for Absentee Ballot

We're "praticing social distancing" with the COVID-19 virus active in New Mexico ... but fortunately, that doesn't mean we can't hike. It might be the most healthy thing we can do, as long as we all keep our distance from each other and don't carpool.

On this week's hike, someone told me about a fun activity: since a lot of her friends are stuck at home, they're trading emails where each day, everybody writes about something starting with a new letter of the alphabet.

Sounds like fun! So I'm going to join the game here on my blog. I'm not going to try for daily posts; I expect to post roughly twice a week, usually on light topics, not geeky tech articles.

I'll lead off today with a short note: a reminder to everyone to sign up for an absentee ballot, if your state allows that, so you can vote by mail rather than going to a polling place in person.

In this time of social distancing, you don't want to be at a crowded polling place touching the same screens or pens that everyone else has touched before you; and it would be better if poll workers weren't required to be there either. It would be so much better if we all voted by mail.

When Dave and I lived in California, the state had just switched to what they called "permanent absentee ballots": at least in the bay area, ballots were automatically sent to all voters. You could fill the ballot out at home, and then you had the choice of mailing them in or dropping them off at the nearest polling place. (This was thanks to our excellent then-Secretary of State Debra Bowen, who also fought against no-paper-trail voting machines and for increased ballot access.)

New Mexico still uses in-person voting, though I'm happy to say we use paper ballots and allow absentee voting without requiring any excuse. But this year, it looks like New Mexico will be encouraging voting by mail; our Secretary of State has a FAQ | ABSENTEE VOTING FOR THE 2020 PRIMARY ELECTION. page with details on how to sign up, and you must request your ballot for the primary by May 28.

Check the rules for your state (assuming you're in the US). If you haven't voted in the primary yet, check now, since time may be running out! For the November general election, you probably have plenty of time.

And if your state doesn't allow no-excuse voting by mail / absentee ballots, this might be time to call your governor or lobby your state legislators asking for an exception. It's a critical health matter, this year.

[ 20:58 Mar 18, 2020    More politics | permalink to this entry | comments ]

Sun, 01 Mar 2020

Plotting Epicycles

Galen Gisler, our master of Planetarium Tricks, presented something strange and cool in his planetarium show last Friday.

[inner planet orbits from north ecliptic pole, with Venus pentagram] He'd been looking for a way to visualize the "Venus Pentagram", a regularity where Venus' inferior conjunctions -- the point where Venus is approximately between Earth and the Sun -- follow a cycle of five. If you plot the conjunction positions, you'll see a pentagram, and the sixth conjunction will be almost (but not quite) in the same place where the first one was. Supposedly many ancient civilizations supposedly knew about this pattern, though as Galen noted (and I'd also noticed when researching my Stonehenge talk), the evidence is sometimes spotty.

Galen's latest trick: he moved the planetarium's observer location up above the Earth's north ecliptic pole. Then he told the planetarium to looked back at the Earth and lock the observer's position so it moves along with the Earth; then he let the planets move in fast-forward, leaving trails so their motions were plotted.

The result was fascinating to watch. You could see the Venus pentagram easily as it made its five loops toward Earth, and the loops of all the other planets as their distance from Earth changed over the course of both Earth's orbits and theirs.

You can see the patterns they make at right, with the Venus pentagram marked (click on the image for a larger version). Venus' orbit is white, Mercury is yellow, Mars is red. If you're wondering why Venus' orbit seems to go inside Mercury's, remember: this is a geocentric model, so it's plotting distance from Earth, and Venus gets both closer to and farther from Earth than Mercury does.

He said he'd shown this to the high school astronomy club and their reaction was, "My, this is complicated." Indeed. It gives insight into what a difficult problem geocentric astronomers had in trying to model planetary motion, with their epicycles and other corrections.

Of course that made me want one of my own. It's neat to watch it in the planetarium, but you can't do that every day.

So: Python, Gtk/Cairo, and PyEphem. It's pretty simple, really. The goal is to plot planet positions as viewed from high above the north ecliptic pole: so for each time step, for each planet, compute its right ascension and distance (declination doesn't matter) and convert that to rectangular coordinates. Then draw a colored line from the planet's last X, Y position to the new one. Save all the coordinates in case the window needs to redraw.

[planet orbits from north ecliptic pole] At first I tried using Skyfield, the Python library which is supposed to replace PyEphem (written by the same author). But Skyfield, while it's probably more accurate, is much harder to use than PyEphem. It uses SPICE kernels (my blog post on SPICE, some SPICE examples and notes), which means there's no clear documentation or list of which kernels cover what. I tried the kernels mentioned in the Skyfield documentation, and after running for a while the program died with an error saying its model for Jupiter in the de421.bsp kernel wasn't good beyond 2471184.5 (October 9 2053).

Rather than spend half a day searching for other SPICE kernels, I gave up on Skyfield and rewrote the program to use PyEphem, which worked beautifully and amazed me with how much faster it was: I had to rewrite my GTK code to use a timer just to slow it down to where I could see the orbits as they developed!

It's fun to watch; maybe not quite as spacey as Galen's full-dome view in the planetarium, but a lot more convenient. You need Python 3, PyEphem and the usual GTK3 introspection modules; on Debian-based systems I think the python3-gi-cairo package will pull in most of them as dependencies.

Plot your own epicycles:

Tags: , , ,
[ 13:04 Mar 01, 2020    More science/astro | permalink to this entry | comments ]

Thu, 27 Feb 2020

Automatic Plant Watering with a Raspberry Pi

[Raspberry Pi automatic plant waterer] An automatic plant watering system is a project that's been on my back burner for years. I'd like to be able to go on vacation and not worry about whatever houseplant I'm fruitlessly nursing at the moment. (I have the opposite of a green thumb -- I have very little luck growing plants -- but I keep trying, and if nothing else, I can make sure lack of watering isn't the problem.)

I've had all the parts sitting around for quite some time, and had tried them all individually, but never seemed to make the time to put them all together. Today's "Raspberry Pi Jam" at Los Alamos Makers seemed like the ideal excuse.

Sensing Soil Moisture

First step: the moisture sensor. I used a little moisture sensor that I found on eBay. It says "YL-38" on it. It has the typical forked thingie you stick into the soil, connected to a little sensor board.

The board has four pins: power, ground, analog and digital outputs. The digital output would be the easiest: there's a potentiometer on the board that you can turn to adjust sensitivity, then you can read the digital output pin directly from the Raspberry Pi.

But I had bigger plans: in addition to watering, I wanted to keep track of how fast the soil dries out, and update a web page so that I could check my plant's status from anywhere. For that, I needed to read the analog pin.

Raspberry Pis don't have a way to read an analog input. (An Arduino would have made this easier, but then reporting to a web page would have been much more difficult.) So I used an ADS1115 16-bit I2sup>C Analog to Digital Converter board from Adafruit, along with Adafruit's ADS1x15 library. It's written for CircuitPython, but it works fine in normal Python on Raspbian.

It's simple to use. Wire power, ground, SDA and SDC to the appropriate Raspberry Pi pins (1, 6, 3 and 5 respectively). Connect the soil sensor's analog output pin with A0 on the ADC. Then

# Initialize the ADC
i2c = busio.I2C(board.SCL, board.SDA)
ads = ADS.ADS1015(i2c)
adc0 = AnalogIn(ads, ADS.P0)

# Read a value
value = adc0.value
voltage = adc0.voltage

With the probe stuck into dry soil, it read around 26,500 value, 3.3 volts. Damp soil was more like 14528, 1.816V. Suspended in water, it was more like 11,000 value, 1.3V.

Driving a Water Pump

The pump also came from eBay. They're under $5; search for terms like "Mini Submersible Water Pump 5V to 12V DC Aquarium Fountain Pump Micro Pump". As far as driving it is concerned, treat it as a motor. Which means you can't drive it directly from a Raspberry Pi pin: they don't generate enough current to run a motor, and you risk damaging the Pi with back-EMF when the motor stops.

[Raspberry Pi automatic plant waterer wiring] Instead, my go-to motor driver for small microcontroller projects is a SN754410 SN754410 H-bridge chip. I've used them before for driving little cars with a Raspberry Pi or with an Arduino. In this case the wiring would be much simpler, because there's only one motor and I only need to drive it in one direction. That means I could hardwire the two motor direction pins, and the only pin I needed to control from the Pi was the PWM motor speed pin. The chip also needs a bunch of ground wires (which it uses as heat sinks), a line to logic voltage (the Pi's 3.3V pin) and motor voltage (since it's such a tiny motor, I'm driving it from the Pi's 5v power pin).

Here's the full wiring diagram.

Driving a single PWM pin is a lot simpler than the dual bidirectional motor controllers I've used in other motor projects.

GPIO.setup(23, GPIO.OUT)
pump = GPIO.PWM(PUMP_PIN, 50)

# Run the motor at 30% for 2 seconds, then stop.

The rest was just putting together some logic: check the sensor, and if it's too dry, pump some water -- but only a little, then wait a while for the water to soak in -- and repeat. Here's the full script. I haven't added the website part yet, but the basic plant waterer is ready to use -- and ready to demo at tonight's Raspberry Pi Jam.

Tags: , ,
[ 13:50 Feb 27, 2020    More hardware | permalink to this entry | comments ]

Mon, 17 Feb 2020

A Couple of Nice Hikes

[The lunch spot on Lion Cave Mesa] We've had some wild weather recently. Two weeks ago, our weekly hiking group was sscheduled to go on a hike in sunny White Rock that Dave and I had proposed, a few miles from home. Then the night before the hike, we got our heaviest snowstorm of the year so far.

Sounded like a great opportunity to test those new ice spikes (for shoes) I'd ordered on eBay. We went down Lion Cave Canyon, around the mesa and up Water Canyon, then climbed up to the top of the mesa and went out to the end to a lunch spot with a panoramic view of Water Canyon and the Sangre de Cristos.

[Walking the Neck] Then back across the narrow neck of the mesa. The temperature was just about perfect for hiking with the sun and the snow. The ice spikes worked perfectly -- the snow wasn't deep enough to need snowshoes, but there were plenty of places where it would have been slippery without the spikes.

[Snow Bumps] We also had fun speculating on the cause of the "snow bumps" that formed around the grama grass stems.

[Dramatic light in Pueblo Canyoo] Now, two weeks later, most of the snow is gone and it's a beautiful day with a high of 60. We headed out for a short exploration in Pueblo Canyon, looking for the old airport that some folks in the R/C flying club thought might make a good flying site.

Some clouds moved in while we were walking, making for dramatic views of the cliffs. I just never get tired of the way the changing light plays on the mesas and canyons.

[Dramatic light in Pueblo Canyoo] We didn't find the old airport -- more exploration needed! -- but we did find the new connector to the Tent Rocks Trail, where the Youth Conservation Corps has been busy with trailwork in Pueblo Canyon. And we explored the remains of an old road -- below Anderson Overlook: possibly the original horse/mule road that they used in the Ranch School days before the Manhattan Project.

Another beautiful day in Los Alamos.

Tags: ,
[ 19:58 Feb 17, 2020    More nature | permalink to this entry | comments ]

Wed, 12 Feb 2020

A Raspberry Pi Kiosk

After writing a simple kiosk of rotating quotes and images, I wanted to set up a Raspberry Pi to run the kiosk automatically, without needing a keyboard or any on-site configuration.

The Raspbian Desktop: Too Hard to Configure

Unlike my usual Raspberry Pi hacks, the kiosk would need a monitor and a window system. So instead of my usual Raspbian Lite install, I opted for a full Raspbian desktop image.

Mistake. First, the Raspbian desktop is very slow. I intended to use a Pi Zero W for the kiosk, but even on a Pi 3 the desktop was sluggish.

More important, the desktop is difficult to configure. For instance, a kiosk needs to keep the screen on, so I needed to disable the automatic screen blanking. There are threads all over the web asking how to disable screen blanking, with lots of solutions that no longer apply because Raspbian keeps changing where desktop configuration files are stored.

Incredibly, the official Raspbian answer for how to disable screen blanking in the desktop — I can hardly type, I'm laughing so hard — is: install xscreensaver, which will then add a configuration option to turn off the screensaver. (I actually tried that just to see if it would work, but changed my mind when I saw the long list of dependencies xscreensaver was going to pull in.)

I never did find a way to disable screen blanking, and after a few hours of fighting with it, I decided it wasn't worth it. Setting up Raspbian Lite is so much easier and I already knew how to do it. If I didn't, Die Antwort has a nice guide, Setup a Raspberry Pi to run a Web Browser in Kiosk Mode, that uses my preferred window manager, Openbox. Here are my steps, starting with a freshly burned Raspbian Lite SD card.

Set Up Raspbian Lite with Network and SSH

I wanted to use ssh on my home network while debugging, even though the final kiosk won't need a network. The easiest way to do that is to mount the first partition:

sudo mount /dev/sdX1 /mnt
(sdX is wherever the card shows up on your machine, e.g. sdB) and create two files. First, an empty file named ssh
touch /mnt/ssh

Second, create a file named wpa_supplicant.conf with the settings for your local network:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev


Then unmount that partition:

sudo umount /mnt

Copy the Kiosk Files into /home/pi

The second partition on a Raspbian card is the root filesystem, including /home/pi, the pi user's home dictory. Mount /dev/sdX2, copy your kiosk code into /home/pi, and chown the code to the pi user. If you don't know what that means or how to do that, you can skip this step and load the code onto the Pi later once it's up and running, over the network or via a USB stick.

Unmount the SD card and move it to the Raspberry Pi.

Raspbian First-boot Configuration

Boot the Pi with a monitor attached, log in as the pi user, run sudo raspi-config, and:

So the installation won't become too bloated, I like to create the file /etc/apt/apt.conf containing:

APT::Install-Recommends "false";
APT::Install-Suggests "false";
(That's the equivalent of the --no-install-recommends in the Die Antwort guide.)

Update the OS, and install the packages needed to run X, the Openbox window manager, a terminal (I used xterm), and a text editor (I used vim; if you're not familiar with Linux text editors, pico is more beginner-friendly). If you're in a hurry, you can skip the update and dist-upgrade steps.

$ sudo apt update
$ sudo apt dist-upgrade
$ sudo apt install xserver-xorg x11-xserver-utils xinit openbox xterm vim

I was surprised how little time this took: even with all of the X dependencies, the whole thing took less than twenty minutes, compared to the several hours it had taken to dist-upgrade all the packages on the full Raspbian desktop.

Install any Kiosk-specific Packages

Install any packages you need to run your kiosk. My kiosk was based on Python 3 and GTK 3:

sudo apt install python3-cairo python3-gi python3-gi-cairo \
         libgirepository-1.0-1 gir1.2-glib-2.0 python3-html2text
(This also pulled in gir1.2-atk-1.0, gir1.2-freedesktop, gir1.2-gdkpixbuf-2.0, gir1.2-pango-1.0, and gir1.2-gtk-3.0, but I don't think I had to specify any of them explicitly.)

Configure Openbox

Create the Openbox configuration directory:

mkdir -p .config/openbox
Create .config/openbox/autostart containing:
# Disable screen saver/screen blanking/power management
xset s off
xset s noblank
xset -dpms

# Start a terminal
xterm &

Save the file, and test to make sure you can run X:

$ startx

You should see a black screen, a mouse pointer, and after a few seconds, a small xterm window in the center of the screen. You can use the xterm to fiddle with things you want to change, or you can right-click anywhere outside the xterm window to get a menu that will let you exit X and go back to the bare console.

Test Your Kiosk

With X running, you can run your kiosk command. Don't change directories first; the pi user will be /home/pi ($HOME) after automatically logging in, so make sure you can run from there. For instance, I can run my kiosk with:

$HOME/src/scripts/ $HOME/100-min-kiosk/slideshow/* $HOME/100-min-kiosk/quotes/*.html

Once the command works, edit .config/openbox/autostart and add your command at the end, after the xterm line, with an ampersand (&) after it. Keep the xterm line in place so you'll have a way to recover if things go wrong.

Configure X to Start When the Pi User Logs In

You've already set up the Pi user to be logged in automatically when the machine boots, but pi needs to start X upon login. Create the file .bash_profile containing:

[[ -z $DISPLAY && $XDG_VTNR -eq 1 ]] && startx

You should be ready to go. Reboot, and the Pi should boot up in kiosk mode.

Run in a Loop

Everything working? For extra security, you might want to tweak the autostart file to run your kiosk in a loop. That way, even if the kiosk code crashes for some reason, it will be restarted.

while :
    $HOME/src/scripts/ $HOME/100-min-kiosk/slideshow/* $HOME/100-min-kiosk/quotes/*.html

Don't do this until after you've tested everything else; it's hard to debug with the kiosk constantly popping up on top of other windows.

Get Rid of that Pesky Cursor

You might also want to remove that annoying mouse pointer arrow in the middle of the screen. Editing that startx line you just added to .bash_profile:

[[ -z $DISPLAY && $XDG_VTNR -eq 1 ]] && startx -- -nocursor

This step comes last — because once you've disabled the cursor, it will be difficult to use the machine interactively since you won't be able to see where your mouse is. (If you need to make changes later, you can ssh in from another machine, mount the Raspbian SD card on another machine, or use Ctrl-Alt-F2 to switch to a console window where you can edit files.)

... But It's Still Not Quite Hands-Off

The Pi is now set up to work automatically: just plug it in. The problem was the monitor. Someone contributed a TV, but it turned out to be a "smart TV", and it had its own ideas about what it would connect to. Sometimes the HDMI ports worked, sometimes it refused to display anything, and even when it worked, it randomly brightened and dimmed so that the screen was often too dim to see.

So I contributed my old 20" monitor. Everything worked fine at the demo the night before, and I handed it off to the people who were going to be there early for setup. When I arrived at the Roundhouse the next day, there was my monitor, displaying "No Signal". Apparently, while setting it up, someone had bumped the monitor's "Input Source" button; and of course no one there was up to the task of diagnosing that difficult problem. And no one bothered to call me and ask.

Once I arrived, I pressed the Source button a couple of times and the kiosk display was up and running for the rest of the day. Sigh. I can write kiosk software and set up Raspberry Pis; but predicting potential issues non-technical users might encounter is still beyond me.

[ 11:08 Feb 12, 2020    More tech | permalink to this entry | comments ]