Some Bits: Nelson's log

8 posts in January 2013

Installing CHDK on a Canon S100 on a Mac

I wanted to install custom camera firmware CHDK on my Canon S100, using my Mac. It’s a bit tricky; basically you format the SD card with some funky proprietary byte set, then put a special DISKBOOT.BIN file on the card and the camera will load it on top of the baked in firmware. But setting up the card that way is tricky, you have to get the exact right CHDK version for your firmware, and there’s a bunch of conflicting instructions for the Mac. Here’s what worked for me. These are Java programs, they may work on any OS?

  1. Get ACID, a program to identify your camera firmware version by looking at any JPEG file. Run it and drag over a JPEG from your camera to identify the firmware. Then check “download stable CHDK fill build” and press “Download stable CHDK” to get the right CHDK version for your firmware. (There’s other ways to identify firmware version, but they didn’t work for me. It is essential you get the exact right CHDK version for your firmware. My camera is apparently 1.00E).
  2. Download SDMInst. If you’re on Mountain Lion get the special zip that runs sudo first.
  3. Run SDMInst. Drag over the “Stable CHDK” and select “Copy all files from”. Turn on “Make FAT32 bootable”, turn “debug on”.
  4. Press “Prepare Card”. Double check the volume name, then do the format and copy.
  5. Eject the card, flip the write protect switch on the card on, put in camera.
  6. Turn on camera. Be patient; hold down the on button for awhile. You should see the CHDK boot splash.
  7. Press Play and then Menu to see the CHDK menu. 

Having done all this, CHDK doesn’t do the one thing I really want; override Canon’s obnoxious requirement that any exposure over 1s is at ISO 80. Actually you can override it using the CHDK menus to set an exposure override but it’s a PITA; I just want my firmware patched so it doesn’t have that restriction.

I may still use CHDK just to set the camera up with a script to take continuous photos. (“Interval shooting”, I think they call it?)

OpenStreetMap iD editor

The new Javascript OSM editor iD is working on live data now. So I made an edit, adding a pond I know is there by tracing it on Bing. Works pretty well, it’s an impressive JS app. Interactivity is not great, need 30fps+ responsive user feedback to really feel right. But it’s an early alpha, I’m sure they’ll get there.

The CSS looks home rolled other than a stock reset. Here’s the third party JS libraries they use:

<script src=’js/lib/lodash.js’></script>
<script src=’js/lib/d3.v3.js’></script>
<script src=’js/lib/sha.js’></script>
<script src=’js/lib/ohauth.js’></script>
<script src=’js/lib/jxon.js’></script>
<script src=’js/lib/d3.typeahead.js’></script>
<script src=’js/lib/d3.geo.tile.js’></script>
<script src=’js/lib/d3.size.js’></script>
<script src=’js/lib/d3.trigger.js’></script>
<script src=’js/lib/d3.keybinding.js’></script>
<script src=’js/lib/d3.tail.js’></script>
<script src=’js/lib/d3-compat.js’></script>
<script src=’js/lib/queue.js’></script>
<script src=’js/lib/bootstrap-tooltip.js’></script>
<script src=’js/lib/rtree.js’></script>

 

Notice what’s missing? A typical slippy map library like Leaflet or OpenLayers. He’s using D3 instead. I hadn’t realized how far along d3.geo.tile has come. Works pretty well on iOS too!

In addition to D3 there’s Lo-Dash (an Underscore alternative), SHA and OAuth (for login), JXON (for XML parsing?), Queue (for async), Bootstrap tooltips, and the RTree data structure for spatial lookups.

CGI and ISO-8859-1

Oh, the shame, look at the mojibake that showed up in the Atom feed for my real blog:

In detail, what happened… I get

From⎵ SMTP envelope

 

As opposed to

In detail, what happened… I get

From⎵ SMTP envelope

 

A quick wget -S ‘http://www.somebits.com/weblog/index.atom’ and I found the Atom feed was setting “Content-Type: application/atom+xml; charset=ISO-8859-1”. Like some cretin.

I have no idea why this charset was getting set. My ancient blog software (Blosxom, with a third party Atom plugin) doesn’t seem to be setting the charset explicitly. My best guess is that either Perl or Apache’s CGI helpfully inserts ISO-8859-1 as a default if nothing was explicitly said. Anyway I kludged the problem away by creating blosxom/entries/content_type.atom with the contents “application/atom+xml; charset=UTF-8”.

The Atom document itself specifies <?xml version=”1.0″ encoding=”utf-8″?>. Annoyingly Google Reader seems to believe the HTTP transport charset over the document itself. I have no idea what the spec says you’re supposed to do in this scenario, but I bet 9 times out of 10 the document is more correct than the server.

UTF-8 only, ever, and always.

 

HTML5 template with D3 and Leaflet

I’m often making D3 pages, or Leaflet maps, or some fancy Javascript thing. I always start with a blank editor and then have to remember all the HTML 5 boilerplate. So here’s some boilerplate, a template for starting a D3 + Leaflet project. The browser window is filled with the map.

This validates HTML 5. I’m not confident I’m setting the viewport correctly but this looks right in Chrome, Firefox, and Mobile Safari so good enough for me. I hate that HTML has so much boilerplate associated with it. Update: Mike points out HTML 5 doesn’t require so much boilerplate; tags like head and body are now optional. I don’t know what that means for old browser compatibility though so I’ll stick with the extra words. (Useful reference.)

<!DOCTYPE html>
<html lang="en"><head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0"/>

<title>Leaflet template</title>

<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.5/leaflet.css" />
<!--[if lte IE 8]>
    <link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.5/leaflet.ie.css" />
<![endif]-->
<script src="http://cdn.leafletjs.com/leaflet-0.5/leaflet.js"></script>

<script src="http://d3js.org/d3.v3.min.js"></script>

<style type="text/css">
html, body { height: 100% }
#map { min-height: 100%; }
body {
    margin: 0;
    font-family: Helvetica, Arial, sans-serif; font-size: 12px;
    overflow: hidden;
    background-color: #f00;
}
</style>

</head><body>

<div id="map"></div>

<script type="text/javascript">
var map = L.map('map');
map.setView([37.7504, -122.4425], 13);
var basemap = L.tileLayer('http://{s}.tile.stamen.com/toner/{z}/{x}/{y}.png', {
        attribution: '<a href="http://content.stamen.com/dotspotting_toner_cartography_available_for_download">Stamen Toner</a>, <a href="http://www.openstreetmap.org/">OpenStreetMap</a>, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>',
        maxZoom: 17
});
basemap.addTo(map);
</script>
</body></html>

Raspberry Pi notes

Raffi gave me a Raspberry Pi, the $35 ARM based Linux system. Capable little beast: 256MB RAM, 700MHz ARM processor, a GPU that can drive 1080p and decode video, it’s an interesting device. Some notes:

Hardware

Batteries not included. In addition to the board itself, I needed:

Hilariously the whole machine reboots when I plug in the WiFi adapter; my guess is a power problem. It boots fine once it’s plugged in though.

RAM is shared with the GPU. The split is (now) configurable, so I have 192MB system RAM and 64MB GPU RAM. Newer boards have 512MB on board.

Software

The primary software distribution people use is Raspbian, a giant 1.5 gig full Debian system. It’s cool that you get a full normal Unix system but boy are we a long way from an embedded OS. The architecture is “armhf” with a change, using hardware floating point in the ABI. Apparently there’s several incompatible Debian ARM versions running around; armel, armhf (soft float), armhf (hard float), etc.

There is no BIOS on the board and no LILO or GRUB bootloader has been ported to the Pi yet. The bootstrap expects a FAT filesystem that it can execute a kernel off of. Raspbian has a small FAT partition with a kernel and then a big ext4 partition for the rest. There is an effort for a bootloader called Berryboot but it boots off of SquashFS filesystems which AFAIK are read only. Haven’t tried it.

Raspbian out of the box works well. Username: pi, password: raspberry. You’ll want to use rsapi-config to set the keyboard if you have a US keyboard.

The main thing I had to do was set up wifi, which uses wpa_supplicant. I found this example config file helpful. End of the day, all I needed to do to get wifi working was add the following little block to /etc/wpa_supplicant/wpa_supplicant.conf. (Note, both my SSID and password are wrapped in quotes for the config file.)

network={
  ssid="mySsid"
  psk="my password in quotes"
}

Voila! With all that set up I now have a working underpowered Linux box. So what is this thing actually good for? To me what’s most exciting is the HDMI output; it can drive a TV! To that end I found two possible end uses. OpenELEC, for viewing videos via XBMC. Or MAME/MESS for playing games.

MAME

So what about MAME? My first try was PiMAME 0.3, a full distribution that boots right into AdvanceMAME for a chooser. Looking at it, it’s basically Raspbian with some extra software installed and a login script to launch MAME. (An annoying one, I might add; it’s awkward to get a shell and virtual consoles don’t seem to work). Also the setup isn’t usable with just a USB joystick now, you really need a keyboard to drive both AdvanceMENU and AdvanceMAME itself. Full props to the PiMAME author for working on a convenient turnkey distro, but it’s not there yet. I think I’d rather use a plain Raspbian distribution and build up my own MAME environment, using his packages.

So how to install by hand? I followed notes from this blog post, skipping over the “how to use Unix” parts and getting right to MAME. In a nutshell:

  • Install the AdvanceMAME .deb by hand, downloading from http://sheasilverman.com/rpi/raspbian/debs/
  • Create a MAME user strictly for running MAME. Put it in group video
  • Launch “mame mspacman” from a local console to play a totally legitimately acquired copy of the Ms. Pac-Man ROM.

It works! It’s very slow compared to PiMAME 0.3; I imagine I’m running into the same problem the PiMAME guy is having with the most recent raspbian distributions. Also I haven’t tried sound yet. And AdvanceMAME is some 7 years old; in theory the mainline MAME 0.147 should work on Raspberry Pi but the details of getting SDL and Sound working in this environment are rumored to be difficult.

Thoughts

The Raspberry Pi is an impressive little device. For the size, power (3W), and price it’s amazing to have a full real Unix distribution. I’m not sure what it’s actually for though. Its creators talk about education, about giving kids an affordable hackable platform. I think that’s awesome but is this really it? Maybe so, but I’d think a discarded PC would be just as good. Or something with a portable screen and input method.

As a general purpose hack thing it’s a lot of fun. What’s missing though is some sort of hardware bridge, say Arduinio.

As an embedded device it’s impressively capable. It’s nice to imagine building a whole Internet TV device on it, for instance, with a full real Unix behind it and not having to fart around with an embedded OS or iOS or something. I’m sure there’s drawbacks, but..

I’m trying to get my head around having a full Debian system on this. I’ve been conditioned to think of embedded devices as black boxes; you flash the firmware every six months and then run what’s there, no upgrading or changing. Raspbian feels more like a persistent OS to me, something I’m going to add and upgrade and change rather than wipe and start over regularly.

Uninstalling Evernote on a Mac

The official uninstall instructions for Evernote on a Mac are incomplete. They just say “trash the Application”. But that leaves behind a launchd entry that every 10 seconds tries to launch EvernoteHelper, now missing, and spams the syslog and creates lots of useless crash reports.

Anyway, the fix is to run launchctl remove com.evernote.EvernoteHelper as the user you installed Evernote as. (Not root!)

launchctl/launchd is a total mystery to me. It seems awfully complicated. “launchctl list” and “launchctl bstree” are helpful commands for inspecting the state of what’s trying to launch.

Not getting gigabit ethernet

I’m not getting gigabit ethernet at home between my Linux box and my iMac. Some previous notes suggested I got 30MB/s, at least once, so maybe this is a new problem?

I tested by running dd if=/dev/zero bs=16k count=10000 | nc -l 9999 on the Linux server and running time nc 192.168.0.65 9999 > /dev/null on the Mac. That took 13.9 seconds for the 164 megabytes, for a throughput of 11.7 megabytes = 93.6 megabits/second of useful data transfer. (MenuMeters measured 11.7MB/s as well; dd claimed 9.8MB/s, but there was a delay in starting the client). Figuring TCP overhead that’s clearly running at 100Mbps, not gigabit.

The server is my Linux box with the onboard Realtek chip (which has some issues). ethtool reports it’s running at 1000Mb/s, full duplex.

The client is my 2011 iMac with some Broadcom chip. WiFi totally turned off. MenuMeters and Network Utility both report Gigabit.

The switch is a Netgear GS116 gigabit switch. It’s unmanaged, so I don’t have much insight into what’s going on. Only one set of blinking lights on the switch indicates gigabit speed, so that’s my problem; either the Mac or the Linux box didn’t negotiate gigabit but is lying about it in the ethernet driver.

Come to think of it, this Mac has been flaky on the ethernet for awhile now, it sometimes takes minutes to come up after resume from sleep. I bet something’s gone wrong with the port or the cable and I’m only capable of 100 megabit now. Wish I had some way to diagnose it.

(the difference between 100mbps and 1000mbps is noticeable when transferring large files. The disk is capable of about 250mbps.)

Update looking at the blinking lights I figured out my Mac really has gigabit at the switch, but the Linux box didn’t. Then I looked closer and realized my Linux box had gigabit too, but only to the small gigabit switch sitting in the closet with it. The upstream link from that small switch to the main big switch was 100 megabit. Weird. Rebooting the small switch fixed it. Confounding issue: I have a 100mbps printer plugged in to the small switch. It doesn’t seem to be disrupting my gigabit right now.