Category Archives: computers suck

Everybody needs a Level 43 Tickle-Mimic

ProgressQuest!The display gets a bit mixed up under Linux, but Progress Quest is still delightful.

It also has some of the best Release Notes ever:

  Changes for version 6.1:

     * I really just don't remember.
     * I also don't see how it could matter much.

Fetch me a teratoma!

Log your electricity consumption with Powermon433

NB: this is in the  early stages of development, but does work. It’s by no means a plug-and-play solution. You’re going to have to do some coding, and perhaps some soldering. Undaunted? Read on …

I really like the Blue Line Innovations PowerCost Monitor™ (aka the Black & Decker Power Monitor EM100B). I bought one long before the OPA started to give them away free to Ontario households as part of their peaksaver PLUS program. It’s a little device that clamps to your hydro meter and sends instantaneous power readings to a display.

PowerMonitor-displays
Power Monitor displays — Black & Decker on the left, Blueline on the right

Wouldn’t it be so much better if you could log and analyze these data? So a day’s power consumption might graph to something like this:

PowerMonitor-20140929Yup, this is my real electricity consumption, as logged from the PowerCost Monitor. You can see the fridge cycling on and off, and I think the big mid-day spike was either the AC or the dryer; someone was home on that Monday. The rather blocky green line is Toronto Hydro’s hourly smart meter data. It really hasn’t got the resolution to show really detailed power use.

That spike at 06:30; what’s that? Let’s take a look:

PowerMonitor-20140929-kettleThat’s me boiling the kettle. You can see that the time resolution is better than a minute, and the power is to the watt. Mmm, coffee …

All of this is recorded using a simple Arduino-based solution, originally cooked up by Bryan Mayland. I’ve forked his code and added some instructions: scruss/Powermon433. Here’s the rig I’ve been using to log data over a USB serial link:

Arduino FIO compatible + RFM69W board + FTDI serial
Arduino FIO compatible + RFM69W board + FTDI serial

That’s a particularly ugly rig, due to the limitations of the 3.3 V receiver board I was using. There are other options that work with more normal Arduino boards up on github.

Here’s a sample of the data I’m logging, including the kettle incident:

Datetime Elapsed_s Energy_Wh Power_W Temp_C
2014-09-29T06:27:44 23241.7 25876 289 15
2014-09-29T06:28:16 23273.6 25876 290 15
2014-09-29T06:28:48 23305.5 25876 291 15
2014-09-29T06:29:20 23337.4 25892 294 15
2014-09-29T06:29:52 23369.2 25892 286 15
2014-09-29T06:30:24 23401.1 25892 277 15
2014-09-29T06:30:56 23433.0 25892 357 15
2014-09-29T06:31:28 23464.9 25892 1844 15
2014-09-29T06:32:00 23496.8 25892 1836 15
2014-09-29T06:32:31 23528.5 25952 1829 15
2014-09-29T06:33:03 23560.2 25952 1818 15
2014-09-29T06:33:35 23592.1 25952 1836 15
2014-09-29T06:34:07 23624.0 25952 1836 15
2014-09-29T06:34:39 23655.8 25952 1836 15
2014-09-29T06:35:11 23687.7 25952 1848 15
2014-09-29T06:35:43 23719.6 26048 1832 15
2014-09-29T06:36:15 23751.5 26048 2000 15
2014-09-29T06:36:46 23783.4 26048 2000 15
2014-09-29T06:37:18 23815.2 26048 2000 15
2014-09-29T06:37:50 23846.9 26048 368 15

You’ll see that I’m recording:

  • a system timestamp
  • the elapsed logging time, from the Arduino’s clock
  • instantaneous meter readings in watt-hours. Note that not every row has an update
  • the average power since the last record. The product of this and the time between records adds up to the energy consumption
  • the outside temperature in °C. This is not very accurate (in full sun it over-reads vastly) but better than nothing.

Compare that to the smart meter data:

DateTime Hour KwhUsage Cost Rate
2014-09-29 05:00:00 5 0.29 $0.02 $0.075
2014-09-29 06:00:00 6 0.31 $0.02 $0.075
2014-09-29 07:00:00 7 0.59 $0.04 $0.075

Not much data there, is there? Certainly not enough resolution to tell if a kettle has been running.

Even though this interface is homebrew and cheap, it is accurate. Here’s how four days of continuous readings stack up against Toronto Hydro’s meter:

  Power Monitor ndToronto Hydro Smart Meter
Day First Reading / Wh Last Reading / Wh Total Consumption / kWh No of readings Daily Total / kWh No of readings
2014-09-29 23896 43668 19.772 2711 19.77 24
2014-09-30 43668 52500 8.832 2710 8.82 24
2014-10-01 52500 68004 15.504 2711 15.51 24
2014-10-02 68004 81996 13.992 2712 13.99 24

The difference looks to me like aliasing; THES’s reporting is much more granular.

I’m going to develop this further to turn it into an easy (or at least, easier) to use logging platform. It’s taken us a few years to get here, but there’s nothing quite like a project finally working!

fun with darktable

LiquidI’m really impressed with darktable, a raw photo workflow for Linux.  Unlike Gimp, it uses floating point for all image processes, so it doesn’t get caught up in quantization error. It’s a non-destructive editor, too: it assumes your source images are like negatives, and any changes you make are only applied to the exported images. Darktable also has a very intuitive black and white filtering mode (where you apply a virtual colour filter to the front of the lens, and see the results in real time) and some very powerful geotagging features. I’m sold.

darktable-uiIt’s not immediately obvious how some of the features work, and it took me a few hours (and some reading of the manual — eek!) to get files to export as I wanted them. It’s not quite perfect yet — the map feature can become unresponsive if you click too much on image icons — but it’s definitely solid enough for my purposes.

More of my initial darktable attempts on flickr: A Day by the Lake.

Notes on mini-printers and Linux

miniprinter galleryOver the last few weeks, I’ve been playing with a few small thermal printers. Meant as POS or information booth printers, they make a diverting project for the lo-fi printing enthusiast. While they all have common features — 58 mm/2¼” paper width, 8 pixel/mm resolution, 48 mm print width, serial connection — they all have their quirks. You may have seen these sold as the Adafruit Mini Thermal Receipt Printer or Sparkfun’s Thermal Printer, but there are many others. I’m going to write more on interfacing these directly to Raspberry Pi, Arduino, and (if I can navigate the documentation) a CUPs driver.

For now, I’m just leaving you a list of things I’ve found helpful for the DP-EH600 and 701 printers. Note that the similar-looking BTHT-v6 printer uses a completely different command set.

  • Replacement paper is sold as 2¼” × 30′. Staples have a box of 30 rolls for under $25 (item 279096, not on their website). Longer rolls don’t fit.
  • You’ll need a USB→TTL Serial adaptor, preferably one with DTR control. I use one from JY-MCU. In a pinch, you can use a simpler  Debug / Console Cable for Raspberry Pi, but you risk serial overruns and dodgy results. Remember that RX on the adaptor goes to TX on the printer, and vice versa.
  • A good solid power supply is needed; these printers draw ~8 W when printing. Some printers only support 5 V (for which a 3 amp adaptor would be ideal), others 5-9 V. The higher voltage makes text printing faster. You can’t drive these directly from your Raspberry Pi/Arduino power supply.
  • Linux serial ports are set to some defaults which may have been historically useful, but now corrupt 8-bit data. A trick I picked up here is to first issue the command
    stty -F /dev/ttyUSB1 0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0
    which clears all settings, then set the device up as you need it:
    stty -F /dev/ttyUSB1 speed 9600 raw cs8
    (Most of these printers default to 9600 baud. Your device may be called something different to ttyUSB1.)
  • I’ve written a couple of Python driver stubs which take an image and produce the relevant binary output:
    • scruss / esc-pos-image.py – prints an image as a single command. May not work on the SparkFun printer. Does not work on the BTHT-v6.
    • scruss / esc-pos-image-star.py – prints the image in 24 pixel deep bands. Can sometimes cause visible gaps in the printout, but will work on almost all printers, except the BTHT-v6.
  • These Python libraries also work, as long as you address the printer properly (right device, right speed):

Notes/Credits

  1. Reed Zhao (of Tangram Software) lent me a couple of different printers for testing after I bought a different one from him. He’s put a lot of work into sourcing these printers direct from the manufacturers. Thanks, Reed!
  2. Image credits for print samples:

JPEG 2000 on Ubuntu — without anyone getting stabbed

JPEG 2000 is a great image file format: well-defined, and able to store high quality photographic data in a very small space. It truly is the JPEG of the 2000s — except for its dismal support under Ubuntu.

The problem is the patents. An open library has been a long time coming, and lots of Linux software is built without JP2 support. This helped keep it away from my desktop.

Under Ubuntu 14.04, here’s what does and doesn’t support JP2 files:

  • Gimp — not supported. It appears to have a non-functioning plugin that tries to read the file, then gives up. This is annoying, as Gimp is defined as the system default viewer for JPEG 2000.
  • Image Viewer — does support JP2, but occasionally mis-renders pages. To make this the default, right-click on a JP2 file, and select Open with → Other Application …, then choose Image Viewer. It should work from then onwards.
  • Document Viewer — a bit rough when looking at JPEG 2000-encoded PDFs. Very slow, too.
  • GraphicsMagick — seems to be the most painless way of converting graphics files to JPEG 2000. My preferred method of invoking it is:
    gm convert -define 'jp2:rate=0.008' in.png out.jp2
    The rate option should be a small number; the smaller, the greater the compression, and the worse the image quality.
  • OpenJPEG — provides the image_to_j2k and j2k_to_image tools. Far more picky about input formats than it should be, and often fails on seemingly perfect input.
  • img2pdf — (built from source)  is a tiny gem of a package. All it does is wrap various image formats into a PDF file. It doesn’t modify the image data in any way, so with a bit of ingenuity (and pdftk) you can use PDF as a true metafile archive. You can view the content on any platform, but get the source images out bit-for-bit perfect. We used to call files which could contain files metafiles, but that stopped being popular when TIFF started to be a baroque travesty of an image container back in the mid-1990s.
  • poppler — (for full features, build from source) has a tool, pdfimages, which can extract embedded image files from PDFs. Some of the metadata might get lost, but all of the image bits come through.

Since JPEG 2000 isn’t included in web browsers (grar), I’ve embedded a sample scanned JPEG into a PDF, and added a series of progressively more compressed JPEG 2000 versions: JPEG-2000Booklet [PDF].  The booklet has notes showing the byte size of each page. The image still looks pretty good at 8% of the original file size!

The cuddliest microfiche reader of 1968

wooster-cuddly_microfiche_reader

Remind you of anything?

(from Wooster, Harold. Towards a Uniform Federal Report Numbering System and a Cuddly Microfiche Reader, Two Modest Proposals, 1968, cited in Stevens, Mary Elizabeth. “Research and Development in the Computer and Information Sciences. Volume 2, Processing, Storage, and Output Requirements in Information Processing Systems: A Selective Literature Review.” (1970).)

Ⓗⓞⓦ ⓣⓞ ⓑⓔ ⓐⓝⓝⓞⓨⓘⓝⓖ ⓦⓘⓣⓗ Ⓟⓔⓡⓛ ⓐⓝⓓ Ⓤⓝⓘⓒⓞⓓⓔ

It’s been so long since I’ve programmed in Perl. Twelve years ago, it was my life, but what with the Raspberry Pi intervening, I hadn’t used it in a while. It’s been so long, in fact, that I wasn’t aware of the new language structures available since version 5.14. Perl’s Unicode support has got a lot more robust, and I’m sick of Python’s whining about codecs when processing anything other than ASCII anyway. So I thought I’d combine re-learning some modern Perl with some childish amusement.

What I came up with was a routine to convert ASCII alphanumerics ([0-9A-Za-z]) to Unicode Enclosed Alphanumerics ([⓪-⑨Ⓐ-Ⓩⓐ-ⓩ]) for advanced lulz purposes. Ⓘ ⓣⓗⓘⓝⓚ ⓘⓣ ⓦⓞⓡⓚⓢ ⓡⓐⓣⓗⓔⓡ ⓦⓔⓛⓛ:

#!/usr/bin/perl
# annoying.pl - ⓑⓔ ⓐⓝⓝⓞⓨⓘⓝⓖ ⓦⓘⓣⓗ ⓤⓝⓘⓒⓞⓓⓔ
# created by scruss on 2014-05-18

use v5.14;
# fun UTF8 tricks from http://stackoverflow.com/questions/6162484/
use strict;
use utf8;
use warnings;
use charnames qw( :full :short );
sub annoyify;

die "usage: $0 ", annoyify('string to print like this'), "\n" if ( $#ARGV < 0 );
say annoyify( join( ' ', @ARGV ) );
exit;

# 💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩

sub annoyify() {
    # convert ascii to chars in circles
    my $str = shift;
    my @out;
    foreach ( split( '', $str ) ) {
        my $c = ord($_);             # remember, can be > 127 for UTF8
        if ( $c == charnames::vianame("DIGIT ZERO") )
	{
            # 💩💩💩 sigh; this one's real special ... 💩💩💩
            $c = charnames::vianame("CIRCLED DIGIT ZERO");
        }
        elsif ($c >= charnames::vianame("DIGIT ONE")
            && $c <= charnames::vianame("DIGIT NINE") )
        {
            # numerals, 1-9 only (grr)
            $c =
              charnames::vianame("CIRCLED DIGIT ONE") +
              $c -
              charnames::vianame("DIGIT ONE");
        }
        elsif ($c >= charnames::vianame("LATIN CAPITAL LETTER A")
            && $c <= charnames::vianame("LATIN CAPITAL LETTER Z") )
        {
            # upper case
            $c =
              charnames::vianame("CIRCLED LATIN CAPITAL LETTER A") +
              $c -
              charnames::vianame("LATIN CAPITAL LETTER A");
        }
        elsif ($c >= charnames::vianame("LATIN SMALL LETTER A")
            && $c <= charnames::vianame("LATIN SMALL LETTER Z") )
        {
            # lower case
            $c =
              charnames::vianame("CIRCLED LATIN SMALL LETTER A") +
              $c -
              charnames::vianame("LATIN SMALL LETTER A");
        }
        else {
            # pass thru non-ascii chars
        }
        push @out, chr($c);
    }
    return join( '', @out );
}

Yes, I really did have to do that special case for ⓪; ⓪…⑨ are not contiguous like ASCII 0…9. ⓑⓞⓞ!

Precisely what nobody wanted — the Hershey fonts as a huge great PDF

HersheyNumberedOccidentalGrid-section

It’s impractically huge, but under the image link lives a table of all of the Hershey fonts (well, the Western ones, at least). It’s interesting to note Dr Hershey’s preferences in this pre-ASCII table: almost every variant has degree, minute and second symbols, but none of them have ‘\’. Many of them don’t have ‘@’, either, so no e-mail addresses in Hershey Fraktur for you …

Forgive me, A V Hershey …

I’ve been playing with the Hershey Fonts, vector data digitised by the US government in 1967. It’s in a bit of a bear of a format.

I hope to do more fun stuff with the data. For now, here’s an 120 page sample book showing all the characters:

hershey_sample_page

Making cheap HP plotter pens + yet another HP-GL viewer

If you’re running an old plotter, getting pens can be a worry. While there are some companies that might still make them (Graphic Controls/DIA-Nielsen, for one) they are expensive and limited in range. They’re also felt-tip, which means they’ll dry out if not carefully re-capped.

While eBay might supply all things (like these Roland DG plotter pens I scored a couple of days back; fine, black, new old-stock, or these German plotter pens), I also found this:

$_3It’s described as “11.5*28MM cutting plotter vinyl cutter pen holder 50mm for Roland holder Pcut”. I bought two, and eventually the slow boat from China came …

pens

The one on the left is an unmodified pen holder. Well, it’s really a ballpoint-refill holder, as it comes with a (random colour of blue) refill.  To modify these to fit into an HP desktop plotter, you will need to:

  1. Cut ~10 mm from the end of the holder. A Dremel + cutting disk is a satisfying way of doing this. The gap between the knurled bit and  the thread seems to be a decent place. Clean up the sharp edges
  2. As the knurled lock ring will stop the pen engaging in the carriage (my HP-7470A does a lovely little hesitant try… nope; try… nope; try… give up sequence), you’ll have to do without it. Find another way of jamming the threads of the threaded collar in the right place. I used electrical tape, and it’s held so far. Wiser users will use different colours of electrical tape for different pens, ahem …
  3. Stick the pen refill in and tighten down the collet lightly with pliers. ¡¡¡ Do not try to pull the refill out while it is in the collet !!! (The ballpoint insert will likely pop out, and viscous ink will start to blort out everywhere. Ask me how I know!)
  4. Snip the end of the refill flush with the end of the pen holder using diagonal cutters. Best to do this directly over a rubbish bin, as pen ink is nasty. Dab off excess ink from the end of the refill, and clean your cutters, too.
  5. The base of the threaded collar should be around 29 mm from the pen tip, otherwise nothing will plot (if it’s too short) or you’ll poke holes in the paper (if too long). This measurement doesn’t seem to be extremely critical: my Roland pens have it at 28.5 mm, the DIA-Nielsen pens are 28.9 mm. One of my homebrew pens is working at 30½ mm, but then, my basic plotter has no force control, so it may be more forgiving than more elegant beasts.

modified holders and cut/not-so-cut refills

My modified pens look like the above.

The dollar store is a good source of cheap ballpoint pens. I managed to snag 8 retractable red pens for $1.25, and 4 black pens for $1.

one of the donor red pens, plus the disassembled pen holder

(These retractable pens more often than not eject the whole internals across the room when you retract ‘em.)

It’s probably a good idea to scribble with the pens a bit before and after modifying them, as they take a while to flow freely. They plot very lightly; the black ink looks more like a faint pencil line.

Double-plotted nested bézier curves
Double-plotted nested bézier curves

If you look close up, not merely are the lines very faint, but something else important shows up:

double-plotted detail, showing off-centre effects (actual size 17 × 17 mm)
double-plotted detail, showing off-centre effects (actual size 17 × 17 mm)

The lines — which should be a constant(ish) distance apart, if the paper has stayed in registration — are showing a varying distance from each other. It looks like the pen points are a little off-centre, so when the pen is swapped out, it gets turned to a slightly different position. This would really only matter for precise work, and I find the effect interesting.

As for the HP-GL viewer? GhostPDL, by the makers of Ghostscript. You’ll have to build it from source, and its documentation isn’t quite where one might want it to be, but it implements a full HP PCL6  / HP-GL/2 interpreter than can output bitmaps, PostScript or PDF. The SVG graphic below was made using the tools/plot2pdf.sh script to convert HP-GL to PDF, then I used ghostscript to convert that to SVG. Nifty!

weave.pltAs a bonus, GhostPDL comes with one of the prettiest plotter fonts ever:
testlb

More fun with plotters: graphing, simplifying, and random noises …

  1. If you go to the Incompetech Multi-Color Graph Paper PDF Generator and set the grid spacing to 0.4, 0.8 and 4 lines/cm, you get a nifty HP-GL unit grid with major lines at 1000 units (25 mm), intermediate lines at 500 units (12½ mm) and minor lines at 100 units (2½ mm):
    hpgl-grid-web
  2. By a very roundabout route, I used GDAL’s simplify function to half the line count of my hypotrochoid plots with little visible degradation. The optimised page took far less time to plot:
    hypo1
    hypo2
    Next time, I’d definitely use Shapely instead of messing about with GIS formats. Who knows, I might even integrate it into Chiplotle. Eventually. (Update: though I have some code that does something …)
  3. Plotters are resolutely electromechanical devices. They turn digital command into analogue output, but my one never sounds too happy doing it. It grumbles, sighs and even moos as it plots. A recent plot sounded a bit like this: .

Pleasantly futile: Dogecoin digging on the Raspberry Pi

I don’t recommend this in any way, but cpuminer will run on the Raspberry Pi. It’s pretty easy to build:

sudo apt-get install build-essential libcurl4-openssl-dev automake git
git clone https://github.com/pooler/cpuminer.git
cd cpuminer/
./autogen.sh
./configure CFLAGS="-march=armv6 -mtune=arm1176jzf-s -mfloat-abi=hard -mfpu=vfp -ffast-math -ffast-math -O3"
make
sudo make install

I’m not convinced that the l33t funroll-l00pz CFLAGS are strictly necessary. Yes, you still only get 0.34 khash/s on a stock Raspberry Pi — which means it would take several days to earn 1Đ (or roughly 0.1¢).

I’m trying to find the most futile computer on which to dig Đ. My BeagleBone Black is (somewhat surprisingly) more than 2× as fast, once you replace the very limited Ångström distribution with Debian. I’m really disappointed that I can’t build cpuminer on my Intel Galileo. Its Yocto distribution is extremely small yet confusing. As the board runs burny hot under no load, I wonder how quickly it would glow white-hot under 100% CPU load.

For all your HP 7470a plotter manual needs

On the off chance you need to control a 30 year old graphics plotter, have I got something for you:

HP-7470A_Graphics_Plotter-Interfacing_and_Programming_Manual

The image links to a scanned copy of the HP 7470A Graphics Plotter: Interfacing and Programming Manual which I found on the web, and cleaned up. The pages have been OCR’d, so it should be searchable.

So that’s how the Raspberry Pi camera fits in the CamdenBoss housing …

 

The CamdenBoss Raspberry Pi Camera Enclosure (data sheet, suppliers: RPI CAMERA BOARD – RASPBERRY-PI – ADD-ON BRD, CAMERA MODULE, RASPBERRY PI | Newark element14 Canada, MCM Electronics Carbon Raspberry Pi Camera Case 83-15493 – Micro Center) comes with no instructions. Maybe the lighter coloured ones are easier to work out, but on the faux-carbon one I bought, the little guide slots the board has to slide into are very hard to see.

Given all the warnings about static, I was a little too careful trying to install the camera into the housing. Slip open the camera case, then put the board in at an angle with one side in one slot, then (with a bit more force than I’d like) spring or flex the housing so the other side of the board can click into place. You have to make sure that both sides are fully engaged in the slots before the cover will slide back on.

So here it is, all set up:

raspberry_pi_and_camera_agh_my_retinas

Oh, sorry;  should’ve warned you about the bright pink case and the awesome/appalling Lisa Frank sticker. The sticker is in no way to cover up where I cut the wrong place for the camera connector, nope nope nope …