Blinking on and off with the 74LS42

I want to make an edge-lit numeric display. These were a common technology before numeric LEDs were available. They use 10 illuminated slides to display individual numbers.

The 74LS42 logic chip (4-Line BCD to 10-Line Decimal Decoder) seems a likely candidate to drive such a display. You feed it a 4-bit binary-coded decimal input, and the chip activates one of ten outputs. Here’s what I got working as a demo driven by an Arduino:

(Video link for the iframe-averse: https://www.youtube.com/watch?v=cETGB2M8iUw)

From the video you can see that:

  1. The 7442 only passes inputs from 0 (0000b) to 9 (1001b). All other inputs result in no output.
  2. The outputs are really more like 1–10 than 0–9, as a zero input activates the first output.

Making a clean breadboard layout for this circuit was a little more work than I’d anticipated. It just fits on a half-sized breadboard:

Simple 7442 demo circuit, showing BCD inputs (green) and decimal outputs (orange)
Simple 7442 demo circuit, showing BCD inputs (green) and decimal outputs (orange)

Because the 7442 will only activate one output at a time, it’s okay to use a single current-limiting resistor for all ten output LEDs. The chip also uses active low outputs: the outputs go from high to low when activated. The negative side of each LED goes to an output pin, and the chip sinks current when an output is selected, lighting the LED.

The components get in the way of seeing the wiring, so here’s another picture from Fritzing with just the wires and the breadboard:

7442-no_componentsApart from the 74LS42 chip itself, the components I used were 10× 3mm orange LEDs on the outputs and 4× 3mm green LEDs on the inputs. I don’t have a spec for them (they were from a bargain selection box from PCBoard.ca) so my use of ridiculously precise 332 Ω 1% resistors to limit current is a little unnecessary. (I have a bunch of these precision resistors from a project that didn’t go ahead, so using them is cheaper for me than digging about for a 5% one.)

Finally, here’s the Arduino sketch I wrote to drive the chip for the demo video. All it does is cycle through digital outputs 4–7, incrementing a bit every half second.

/*
   SeventyfourFortytwo - Arduino demo of a
   74LS42 - 4-line BCD to 10-line decimal decoder
   Steps through 0-15, two steps per second
   Shows the 74LS42's blocking of values 10-15 as invalid

   Wiring:
   Arduino  74LS42
   ======== =======
    4      - 15  Input A (bit 0)
    5      - 14  Input B (bit 1)
    6      - 13  Input C (bit 2)
    7      - 12  Input D (bit 3)

   scruss - 2016-09-23
*/

int n = 0;

void setup() {
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  digitalWrite(4, LOW);
  digitalWrite(5, LOW);
  digitalWrite(6, LOW);
  digitalWrite(7, LOW);
}

void loop() {
  digitalWrite(4, n & 1);
  digitalWrite(5, n & 2);
  digitalWrite(6, n & 4);
  digitalWrite(7, n & 8);
  n++;
  if (n > 15) n = 0;
  delay(500);
}

ESP8266 BASIC is seriously neat!

screenshot-from-2016-09-19-22-27-57That picture might not look much, but it’s doing something rather wonderful. It’s a tiny ESP8266 BASIC script running on a super-cheap ESP8266 wifi module. The code draws a clock that’s synced to an NTP server. ESP8266 BASIC graphic commands are built from SVG, so anything you can draw on the screen can also be saved as a vector graphic:

The runtime includes a simple textarea editor that saves code to the board’s flash:

screenshot-from-2016-09-19-22-28-53(and yes, that first line is all you need to set up NTP sync)

Among other features, ESP8266 BASIC has a simple but useful variable display:

screenshot-from-2016-09-19-22-30-17I’d picked up a (possible knock-off of a) WeMos D1 ESP8266 board in Arduino form factor a few months ago. The Arduino.cc Software now supports ESP8266 directly, so it’s much easier to program. Flashing the BASIC code to the board was very simple, as I’d noticed that the Arduino IDE printed all of its commands to the console. All I needed to do was download an ESP8266 BASIC Binary, and then run a modified Arduino upload line from the terminal:

~/.arduino15/packages/esp8266/tools/esptool/0.4.9/esptool -vv -cd nodemcu -cb 921600 -cp /dev/ttyUSB2 -ca 0x00000 -cf ESP8266Basic.cpp.bin

ESP8266 BASIC starts in wireless access point mode, so you’ll have to connect to the network it provides initially. Under Settings you can enter your normal network details, and it will join your wifi network on next reboot. I just hope it doesn’t wander around my network looking for things to steal …

micro, a nice little text editor

screenshot-from-2016-09-18-15-24-13

micro – https://github.com/zyedidia/micro – is a terminal-based text editor. Unlike vi, emacs and nano, it has sensible default command keys: Ctrl+S saves, Ctrl+Q quits, Ctrl+X/C/V cuts/copies/pastes, etc. micro also supports full mouse control (even over ssh), Unicode and colour syntax highlighting.

micro is written in Go – https://golang.org – so is very easy to install:

go get -u github.com/zyedidia/micro/...

If you don’t already have Go installed, it’s pretty simple, even on a Raspberry Pi: https://golang.org/doc/install

If your running under Linux, you probably want to have xclip installed for better cut/paste support.

Overall, I really like micro. It’s much easier to use than any of the standard Linux text editors. It uses key commands that most people expect. Creating code should not be made harder than it needs to be.

(I was about to suggest FTE, as it appears to be the closest thing to the old MS-DOS 6 editor that I’ve seen under Linux. While it’s a great plain text editor, its Unicode support isn’t where it needs to be in 2016.
micro suggestion came via MetaFilter’s Ctrl + Q to quit. Need I say more?
)

ThreeFourTwoTwo

sampleYup, another highly impractical monospaced font. This one is based on a short-lived 22 segment display made in the early 1980s by Litronix (datasheet).

It’s also on Fontlibrary: ThreeFourTwoTwo.

Local download: ThreeFourTwoTwo .

If you use this font red on a dark background and under-print the ¤ character in a faint colour, you get an approximation of the LED segment mask:

led

File under “because I can”

Some ideas are truly brilliant:
they resonate immediately with
all of humanity. Some ideas
are merely great: in time,
their value becomes clear
to all. Some ideas, however,
are like this one ...

All the Colours We Have (for Paul Carter)

It’s hard to believe that Paul Carter has been gone ten years. I realized that my original ZX Spectrum BASIC memorial to him had got a bit dusty, in that it ran as an outdated Java applet. So I rewrote the code, and put it here: All the Colours We Have (for Paul Carter).

nerrrdy Bourgoin mini-zine

All fired up by Natalie Draz‘s presentation about The Transmitting Library at Make Change Conference last Sunday, I made a tiny zine using Natalie’s template:

patterns_from_bourgoin-zine_smallJust fold it, cut across the broken line in the middle, then re-fold so the front and back cover are on the outside. Colour it in!

I’ve supplied it in a couple of formats:

  1. PDF: all vector, no jaggies — patterns_from_bourgoin-zine.pdf.
  2. PNG: if you’re still all about the pixels — patterns_from_bourgoin-zine.png.

all your centroids

As Side Door sign v3 seemed to have fallen off, I needed to make a new one. With access to a laser cutter, I can make really permanent things now, so I designed this:

side_door-cut-lcYes, that’s a pointy thing filled with pointy things (all without thumbs, you’ll notice) and labelled with Cooper Black. Irony, much? Fe!

In order to get the sign to hang correctly, I needed to work out the centroid of the pointy outline. thedatachef/inkscape-centroid: Centroids for Inkscape paths and shapes to the rescue! Well, kinda. First off, the installer had a bug that said a Ruby file was a dependency when the plugin was in Python. So I forked the repo, made the change, tested it, and issued a pull request. So yay, working centroid calculations in Inkscape!

Secondly, the plugin only works well for simple shapes, like these:

Screenshot from 2016-07-13 17-15-54But compound shapes? Not so well:

Screenshot from 2016-07-13 17-42-31I guess it doesn’t like the negative moments generated by the holes, and does its own thing. Oh well.

Spectrum is Green!

My previous adventures with my Sinclair ZX Spectrum 48K in Canada were not resounding successes. I couldn’t get the display to work, and tapes wouldn’t load well, so I’d been using Fuse while the hardware sulked in a cupboard.

I’d previously got a proper power supply (9 V DC, ≥ 1.4 A, centre negative) and bypassed the PAL UHF modulator to give composite video. No television, monitor or converter box that I had tried seemed to give a useful display.

Back in May, Walter Miraglia brought a tiny 7″ composite colour monitor to TPUG‘s Retrocomputing Night. He let me try it with the Spectrum, and it worked very well. Walter said it was an extension monitor for a car DVD player.

I dug around, and found that local surplus clearout store Tech Source Canada had the Philips 7″ portable DVD Player PD7016/37 for $60. This gives you two identical DVD players with composite input. I think my other one will be destined for a Raspberry Pi project somewhere.

To get these monitors running, you’ll need:

  • a 9–12 V DC power supply able to give ≥ 1 A. I use a regulated supply that gives 9.1 V open circuit and is rated at 2 A. Note that the power connector is slightly smaller than the common 2.1 mm barrel, so you may have to order this one, unless you can solder something up.
  • A cable like this 3.5mm Stereo to Composite Video + Audio Cable (3 RCA). These are sometimes just called camcorder cables. They use a 3½ mm TRRS jack, and can also — if you don’t mind not quite having the connectors in the right order — work with the composite/audio output of more recent Raspberry Pis. Tech Source had these for under $5.

Connect it up , and — success! Well, slightly qualified success. The screens do not have the greatest resolution, so pixels are slightly smeared together. The screens do have a decently fast refresh, and the whole look is just right. With its colour clash and dot crawl, nobody ever expected great video from the Speccy anyway.

Here are some screen shots taken with my phone, and a couple of pixel-sharp screenshots from Fuse to compare:

Moon Cresta - complete with authentic weird language
Moon Cresta – complete with authentic weird language
Moon Cresta — the same screen from Fuse
Moon Cresta — the same screen from Fuse
Moon Cresta - nice loading screen
Moon Cresta – nice loading screen
Manic Miner — a game I am not good at
Manic Miner — a game I am not good at
Manic Miner - perhaps the (deliberately?) worst game music ever
Manic Miner – perhaps the (deliberately?) worst game music ever
3D Death Chase — OH NOES A TREE!!!!1!!
Deathchase — OH NOES A TREE!!!!1!! Looks like the Riders of the Big Bikes just lost another member
Knight Lore
Knight Lore
Chuckie Egg
Chuckie Egg
Chuckie Egg from Fuse. We can't do anything about the attribute clash
Chuckie Egg from Fuse. We can’t do anything about the attribute clash

So I can now definitely view the screens. Huge thanks to Walter for tipping me off to these DVD players.

[Incidentally, the screens are designed for car use, so don’t stand up properly unless you get creative with some supports. I laser-cut these out of 3 mm plywood:

mini screen feet for 3 mm ply
mini screen feet for 3 mm ply. Cutting template PDF is linked underneath this image

Glue the little sticks on to the flat ends, and they’ll fit into the slots in the back of the monitor. Here are the feet with the sticks fitted:

screen feet with sticks glued in place
screen feet with sticks glued in place

There are better-designed feet than these, but they work, mostly.]

I was still having game loading problems. Try as I might, I couldn’t get anything to load reliably. Retrocomputing Stack Exchange came to the rescue, in the shape of mcleod_ideafix’s very helpful answer.  If your audio player is running from batteries and you can use a stereo cable, you can convert the normal mono loading audio into stereo with one channel inverted. This gives you effectively double the volume, and works quite well with my audio player, an old Edirol R-1*.

Inverted stereo loading data, showing 4000/8000 Hz speedload tones
Inverted stereo (or differential) loading data, showing 4000/8000 Hz speed-load tones

This audio will not load into an emulator, or work with a mono cable. Some audio players even render it as silence.

Here’s a script to take monophonic loading data and convert it to this faux-differential stereo format using Sox:

#!/bin/bash
# wav2differential.sh - convert mono game tape audio to 2× stereo
# usage:   wav2differential.sh infile.wav
#          (creates  infile-differential.wav)
# scruss - 2016-06-07
# method by ‘mcleod_ideafix’; many thanks / greetz
#   — https://retrocomputing.stackexchange.com/a/774/439

base="${1%.wav}"
sox -q --norm=-3 "$1" -b 16 "${base}-n.wav"
sox -q  "${base}-n.wav" "${base}-ni.wav" vol -1.0
sox -q  --norm=-0.1 -M -c 1 "${base}-n.wav" -c 1 "${base}-ni.wav" -c 2 -b 8 "${base}-differential.wav"
rm -f  "${base}-n.wav" "${base}-ni.wav"

If you want to check your audio levels, sox can also create the 800 Hz header tone used by the Spectrum. Run the output of the command below through the script above, load it onto your audio player and fiddle with the volume until the border flickers steadily:

sox -n -b 8 -r 8000 800hz-header.wav synth 30 square 800
Lovely loading bars ...
Lovely loading bars …

I was also looking for the games to load fairly quickly. Tapes used to take over three minutes to load, and while retrogaming all is about the experience, I haven’t got time for that. Fuse has some utility programs which will convert a .Z80 game snapshot into an audio file that loads in about 1¼ minutes.

To convert the snapshot to a speed-load TZX tape image:

snap2tzx -o game.tzx -s 3 game.z80

To convert that virtual tape image into audio:

tape2wav -r 16000 game.tzx game.wav

You can then run that WAV file through the stereo/differential script I listed above. Have fun!

The “Coo~Coo” Raspberry Pi Zero Case

Coo~Coo Raspberry Pi Zero Case - built
Coo~Coo Raspberry Pi Zero Case

I’d tried making several Raspberry Pi Zero enclosures, but none of them quite worked. My needs are pretty simple, but I do need to be able to fit a full 40 pin strain-relieved (possibly keyed) header into the device while keeping questing fingers and dropped conductors off the circuit board.

Coo~Coo case in fluo acrylic
Coo~Coo case in fluo acrylic

So working from a (scaled) version of the Raspberry Pi Zero Mechanical Drawing, I made a case that meets some very basic requirements:

  1. Conserves material: The Coo~Coo uses just under 80 × 80 mm of 3 mm ply or acrylic, plus four nylon machine screws, nuts and washers.
  2. Takes a full-sized GPIO header with a little headroom.
  3. Provides edge protection for the µSD and connectors.
  4. Has only a single cut layer, with no time-wasting engraved rasters.
  5. Needs only simple tools to make: really only needs diagonal cutters to snip off half of the nylon screw heads. Needle-nose pliers might help too, as there are some fiddly small parts.
  6. Free as in CC0. Yup, since this is derived from the Raspberry Pi Foundation’s copyrighted drawing, my modifications didn’t really add anything of value. Thus I waive all copyright and related or neighbouring rights on my additions:


    CC0

    To the extent possible under law, Stewart C. Russell has waived all copyright and related or neighbouring rights to the “Coo~Coo” Raspberry Pi Zero Case. This work is published from: Canada.

Why the odd “Coo~Coo” name? Well, look at the pattern of spacer washers and half-spacer washers:

Coo~Coo in the cutter

To save material, I arranged these washers inside the GPIO cutout. I realised that I could spell COO~COO. It’s even clearer on the cutting document:

Coo~Coo — PDF for cutting is linked under the image

Update: here’s a revised path that cut well with acrylic and probably will work slightly better on plywood, too: coo-coo-rpi_zero-acryl.zip
(If you do use acrylic, let me introduce you to one of the marvels of backing-paper removal: d-limonene. This fruity solvent — present in products like Goo Gone — causes backing paper to slough off with only a few minutes’ soaking. It washes off to a clean shine with water and dish soap/washing up liquid. I have just saved you fingernails from certain damage!)

The cutting path in the PDF could use a little clean up if you want to try this design in acrylic. The base of the design has been flipped so that any laser flare will be hidden inside the case.

You’ll need four M2.5 or M3 nylon screws of 20 mm length, plus 8 washers and 4 nuts. M3 screws of this length are easier to get, but the mounting holes in the Raspberry Pi Zero are only 2¾ mm in diameter. You can thin the M3 screws down slightly by lightly twisting them inside a piece of folded fine sandpaper. You’ll still have to push them through the Raspberry Pi Zero circuit board with a little force, though.

Cutting & Assembly Instructions

  1. If you have it, place some fine wire mesh or sacrificial heavy card-stock between the laser cutter honeycomb bed and the plywood. The spacer washers are just the right size to fall through the cutter bed and be lost inside the discard hopper.
  2. Cut the piece as normal.
  3. Remove the work from the laser cutter. Masking tape applied over the washers will stop them falling out.
  4. Take the top piece, and thread the other two screws through the holes by the HDMI and PWR labels.
    (It may be easier to do these one at a time)
  5. Place two of the full spacer washers over each screw.
  6. Push the screws through the Raspberry Pi Zero board. M2.5 screws won’t need any force, but M3 will need some coaxing, possibly even cajoling.
  7. Place a nylon washer on each of the two screws under the Raspberry Pi Zero board.
  8. Take the base and flip it horizontally so the screw holes match the top.
  9. Very loosely attach the nuts to each of the screws.
    (You’ll need the slack to fit the top two screws and their C-shaped spacers)
  10. Feed the top two screws through the half-holes by the GPIO cutout in the case and the Raspberry Pi Zero board. Again, coaxing and/or cajoling may be required if you used M3 ones.
  11. Put nylon washers over the screws between the Raspberry Pi Zero board and the base.
  12. Very loosely attach the nuts to the top two screws.
  13. (This is the fiddly bit) Stack two of the half spacers and put them on each screw. You need to get the screws tight enough to just grip the spacers against the case, but not too much or you won’t be able to align them to let the GPIO connector fit in the gap. Tightening the screws at the HDMI and PWR ports can help with this, too.
  14. Nip off half of the heads from two of the nylon screws. This will allow the GPIO connector to fit easily.
  15. Tighten all the screws (finger tight is fine) and make sure the trimmed heads align with the edge of the GPIO cutout.
Raspberry Pi Zero in Coo~Coo case showing GPIO and spacers
Raspberry Pi Zero in Coo~Coo case showing GPIO and spacers

The new Raspberry Pi Zero with camera connector should also fit, but I don’t have one to test it.

TwentyfourSixteen – a 17-segment alpha LCD font

2416-demo

Download: TwentyfourSixteen.zip.

Made in 2016 by Stewart C. Russell – scruss.com

A mono-spaced font family derived from the HP/Siemens/Litronix DL-2416 17-segment alphanumeric 17 segment LED display matrix.

Design size: appx 19 pt

For maximum fidelity, should be displayed/printed red to match the original’s ~640 nm wavelength. This corresponds to RGB #ff2100

Weights

Regular only.

Note that this has a very slight skew (5°) built in.

Coverage

ASCII only, upper case.

Author

Stewart C. Russell – http://scruss.com/blog/

Licence

Dual-licensed CC0/WTFPL (srsly)

All of the segments. I've stashed this glyph at character code U+007f so you can make up new ones.
All of the segments. I’ve stashed this glyph at character code U+007f so you can make up new ones.

also: numbers.zip — just 00-99 as PNG images, after this, made with Pango, like this:

for f in {00..99}
do
 pango-view --no-display --background=black --dpi=112 --align=right --foreground='#ff2100' --font='TwentyfourSixteen Regular 48' --hinting=full --output="$f.png" -t "$f"
done

Pen plotters: not just output devices …

Pen plotters were pretty expensive and complex pieces of electromechanical equipment. While they often earned their keep in the CAD office, they also had a function that’s almost forgotten: they could be used as input devices, too.

As a kid, we sometimes used to drive past the office of Ferranti-Cetec in Edinburgh. They specialized in digitizers: great big desk or wall mounted devices for capturing points from maps and drawings. Here’s one of their 1973 models:

Ferranti EP210 Freescan Digitiser. Source: Grace's Guide, http://www.gracesguide.co.uk/File:Im1973IME-Ferranti.jpg
Ferranti EP210 Freescan Digitiser. Source: Grace’s Guide, http://www.gracesguide.co.uk/File:Im1973IME-Ferranti.jpg

While the technology and size have changed a bit, these huge bits of engineering kit are the ancestors of today’s track pads and touch screens.

Realizing that their plotters had very precise X-Y indexing and that they had two-way communications to a computer, HP made a drafting sight that fitted in place of a pen on their plotters:

HP drafting sight, part no 09872-60066
HP drafting sight, part no 09872-60066

This is a very pleasing piece of kit, all metal, thick plastic and polished optical glass. They show up on eBay occasionally, and aren’t cheap. With a bit of coercion, it fits into my HP plotter like this:

Drafting sight in HP7470A plotter
Drafting sight in HP7470A plotter

The image is very bright and clear:

Drafting sight near an axis label
Drafting sight near an axis label
Drafting sight over a point
Drafting sight over a point, showing cursor dot

If one has a digitizing sight, one needs to find something to digitize post haste … I’m sure everyone can sense the urgency in that. So I found this, a scan from my undergraduate project writeup (centrifugal pump impeller design ftw, or something), which was probably made on an Amiga or Atari ST:

It's a graph, with pointy bits on it
It’s a graph, with pointy bits on it

I printed this as large as I could on Letter paper, as it’s the only size my HP7470A plotter can take. Now all it needed was a small matter of programming to get the data from the plotter. Here’s a minimally-useful digitizer for HP and compatible serial plotters. Although I ran it on my little HP grit wheel plotter attached to a Raspberry Pi, I developed it with my larger Roland plotter. The only fancy module it needs is pySerial.

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# a really crap HP-GL point digitizer
#  scruss - 2016

from time import sleep
from string import strip
import serial

ser = serial.Serial(port='/dev/ttyUSB1', baudrate=9600, timeout=0.5)
lbl = ''
points = []
labels = []
k = 0
retval = 0

ser.write('DP;')                # put in digitizing mode
while lbl != 'quit':
    ser.write('OS;')
    ret = strip(ser.read(size=5), chr(13))
    print ('Retval: ', ret)
    if ret != '':
        retval = int(ret)
    if retval & 4:              # bit 2 is set; we have a point!
        print ('Have Point! Retval: ', retval)
        retval = 0
        ser.write('OD;')
        pt = strip(ser.read(size=20), chr(13))
        print ('OD point: ', pt)
        lbl = raw_input('Input label [quit to end]: ')
        points.append(pt)
        labels.append(lbl)
        k = k + 1
        ser.write('DP;')        # put in digitizing mode again
    sleep(1)
ser.close()

f = open('digit.dat', 'w')
for i in range(k):
    f.write(points[i])
    f.write(',')
    f.write(labels[i])
    f.write('\n')
f.close()

In the unlikely event that anyone actually uses this, they’ll need to change the serial port details near the top of the program.

The program works like this:

  1. Move the drafting sight to the point you want to capture using the plotter’s cursor keys, and hit the plotter’s ENTER key
  2. Your computer will prompt you for a label. This can be anything except quit, that ends the program
  3. When you have digitized all the points you want and entered quit as the last label, the program writes the points to the file digit.dat

I didn’t implement any flow control or other buffer management, so it can crash in a variety of hilarious ways. I did manage to get it to work on the lower trace of that graph, and got these data:

9649,2428,1,300,0
357,2428,1,0,0
357,7217,1,0,0.60
733,3112,1,first
826,3167,1,
968,3256,1,
1122,3334,1,
1290,3405,1,
1588,3583,1,
1891,3725,1,
2215,3880,1,
2526,4051,1,
2830,4194,1,
3143,4280,1,
3455,4516,1,
4077,4767,1,
5008,5229,1,
6543,5954,1,
8067,6548,1,
8740,7195,1,
8740,7195,1,last
8740,7195,1,quit

The first two columns are X and Y, in HP-GL units — that’s 1/40 mm, or 1/1016 inches. The third column will always be 1 if you have the sight down. The last columns are the label; if you put commas in them, opening the file as CSV will split the label into columns. I used it to fudge axis points. You’ll also note that the last three lines of data are my valiant attempts to quit the program …

Assuming the axes are not skewed (they are, very slightly, but shhh) some simple linear interpolation gives you the results below:

 12.1    0.086
 15.1    0.093
 19.7    0.104
 24.7    0.114
 30.1    0.122
 39.7    0.145
 49.5    0.162
 60.0    0.182
 70.0    0.203
 79.8    0.221
 89.9    0.232
100.0    0.262
120.1    0.293
150.2    0.351
199.7    0.442
248.9    0.516
270.7    0.597

Good enough for a demo.

(For prettier things to do with plotter digitizing commands, Ed Nisley KE4ZNU has made some rather lovely Superformula patterns)

If you don’t have a plotter, or even if you do and you don’t have hours to waste mucking about with Python, obsolete optics and serial connections, Ankit Rohatgi’s excellent WebPlotDigitizer gets numbers out of graphs quickly. It handles all sorts of graphs rather well.

Scripting Inkscape – kinda

A couple of months back at the GTALUG Graphics session, someone asked if Inkscape – the 2D vector graphics workhorse that everyone seems to use – could be scripted. We pretty much said that it couldn’t. Recently, I found out that it does support a limited form of scripting, and wish to pass this on.

The key to it is understanding Inkscape’s command verbs. These can be listed using:

inkscape --verb-list

These verbs map to Inkscape commands, and often have names linked to the menu they live in (such as “FileQuit” doing what you’d expect).

I had a task I had to repeat on many files: convert all the stroked lines to filled paths. You’d need to do this if you are laser engraving a simple drawing, but there are other applications for this too. Here’s a command that would do this for all objects in a drawing, and overwrite the input file:

inkscape --verb EditSelectAll --verb SelectionUnGroup \
        --verb EditSelectAll --verb SelectionUnGroup \
        --verb EditSelectAll --verb SelectionUnGroup \
        --verb EditSelectAll --verb ObjectToPath \
        --verb EditSelectAll --verb SelectionCombine \
        --verb EditSelectAll --verb StrokeToPath \
        --verb FileSave --verb FileClose \
        --verb FileQuit input.svg

What this does:

  1. Selects everything, and ungroups all objects (×3, to break up most nested groups);
  2. Selects everything, and converts all objects to paths (so text, circles, polygons, spirals become paths, the lowest-level SVG object);
  3. Selects everything, and combines everything into one path;
  4. Selects everything, and converts all strokes to filled paths (so a two node straight line 1 mm wide would become a four node filled rectangle 1 mm thick);
  5. Overwrite the input file, close it, and quit.

The process has some disadvantages:

  1. It opens a window every time. You can’t execute verbs without the GUI opening.
  2. You can’t have another copy of Inkscape open while you do this.
  3. Realistically, you can’t really do anything at your computer until this is done, as it’s popping up windows and shifting focus like crazy. (ssh types can say “heh!” in a smug manner now)
  4. You can’t set parameters to verbs.
  5. It will overwrite the input file.
  6. It clogs up your “File / Recent” menu with all of the files you scripted.

FifteenTwenty: now on Fontlibrary and github

FifteenTwenty-demo

Use it / download it here: FifteenTwenty on fontlibrary.org
Download it / fork it here: scruss/FifteenTwenty on github
Local copy: FifteenTwenty-master.zip (268K; includes FontForge sources)

FifteenTwenty UltraLight: single-stroke OTF for CNC/plotting

Screenshot from 2016-05-08 17-18-31Following on from FifteenTwenty, I made a hairline/single stroke version of the font especially for CNC use. This is a slight misuse of the OpenType format, but if you’re plotting/CNCing/laser cutting, the filled paths of standard fonts don’t work so well. Single-line (or stroke) fonts used to be possible in PostScript — the version of Courier shipped with early Apple LaserWriter printers was composed of strokes, rather than filled paths — but have fallen out of favour. If you have a device with a defined tool width, it’s better to let the tool make the width of the mark/cut. Here’s the hairline font plotted with a 0.7 mm pen to illustrate what I mean:

1520hairlineThis font is almost invisible on screen or on a regular printer, so I don’t recommend installing it unless you have specific CNC/plotting needs. Please note that the font will cause your device to follow the tool path of each letter twice.

Download: FifteenTwenty-master.zip FifteenTwenty-UltraLight.zip (or more options …)

FifteenTwenty: Commodore 1520 plotter font

FifteenTwentyFor the impatient: download FifteenTwenty-master.zip FifteenTwenty-Regular-OTF.zip (or more options …)
Updated: now with all ASCII glyphs!

Update, September 2016: this font was officially squee‘d over by Josh “cortex” Millard on the Metafilter Podcast #120: Hard Out There For A Nerd. I had the great pleasure of meeting Josh at XOXO 2016, too.

The Commodore 1520 was a tiny pen plotter sold for the Commodore 64 home computer. It looked like this:

Commodore 1520 printer plotter (adjusted).jpg
Commodore 1520 printer plotter — by Oguenther (Dr.Guenther). – This file was derived from Cbm1520-2.jpg: , Public Domain, https://commons.wikimedia.org/w/index.php?curid=39145769

I never owned one, but it seems it was more of a curiosity than a useful product.

From a nerdy point of view, however, this device was rather clever in that it packed a whole plotter command language, including a usable font, into 2048 bytes of ROM. Nothing is that small any more.

Thanks to the epic efforts of Jim Brain and others, this ROM is now archived on Project 64 Reloaded. Looking at the code, I was struck by the elegance of the encoding: it packs a full X-Y plot instruction in one byte.

Based on my work with the Hershey font collection, I thought it would be fun to extract the coordinates and make a real OpenType font from these data. I’m sure others would sense the urgency in this task, too.

Since Commodore computers used a subset of ASCII, there’s a barely-usable set of characters in this first release. Notable missing characters include:

U+005C    \    REVERSE SOLIDUS
U+005E    ^    CIRCUMFLEX ACCENT
U+0060    `    GRAVE ACCENT
U+007B    {    LEFT CURLY BRACKET
U+007C    |    VERTICAL LINE
U+007D    }    RIGHT CURLY BRACKET
U+007E    ~    TILDE

I’ll get to those later, perhaps.

Huge thanks to all who helped get the data, and make the bits of software I used to make this outline font.

(Note: although the Project 64 Reloaded contains some extraction code to nominally produce an SVG font, it doesn’t work properly — and SVG fonts are pretty much dead anyway. I didn’t base any of my work on their Ruby code.)

Work-in-progress: Sayso Globord audio decoding

You may still be able to get surplus Sayso Globord programmable LED signs in surplus stores. It’s a 7×24 LED scrolling sign that you can program with a lightpen or with audio input.

sayso-001The unit comes with no software, but has a link to https://www.dropbox.com/sh/q1q9yhahwtblb23/AACpMeXQjYyD8ZWC-65vNgcxa printed on the box. It’s an archive of the programming software, manual, and canned audio files for a whole bunch of standard messages. Here’s an archive if the dropbox link goes away: SaySo.zip

The audio files used for programming the display are clearly FSK-encoded, but I haven’t quite worked out the relationship between the tones and the display bits. Here’s what I’ve worked out so far:

  • Files are made up of 12 audio blocks, each about 0.9 seconds long. Each block appears to correspond to one 7×24 display screen.
  • Mark (1 bit): Three cycles, 96 samples at 44100 Hz: 1378.125 Hz
  • Space (0 bit): Four cycles, 256 samples at 44100 Hz:  689.0625 Hz

The editor runs nicely under DOSBox, so you can experiment and save samples as WAV files. Here’s a sample display with its corresponding audio linked underneath:

sayed1_0_003I’m not sure how much extra work I have time or inclination to put in on getting this working, but I hope that my preliminary work will be useful to someone (maybe this person).

Building the Stick of Joy

Not-even-remotely over-engineered retrogaming joystick

 

Tracking down old Atari-style joysticks is expensive, and you don’t know if you’ll get something reliable. So I built one, using Protolab‘s laser cutter.

The guts of the unit comprise:

The case is made from 6.4 mm high quality plywood, using a template generated by BoxMaker.  The external dimensions of the box are 163.05 mm x 143.05 mm x 83.05 mm, including kerf.

joystick-box

I might recommend just nabbing the top plate dimensions from the above drawing, as I made a couple of rookie mistakes in the design:

  1. I overcompensated for the laser kerf, so had to spend several hours sanding the box down to size to make it fit together. You might want to set it to zero to leave room for glue.
  2. I flipped one of the box sides to compact the cutting job. While this might’ve saved a small amount of wood, it means that the grain matches on three of the sides, but not for the fourth.

You’ll also need M4 screws to secure the joystick and stacks of washers to space the dust washer correctly. The connection is made with a couple of metres of 8-core stranded signal cable and a 9-pin female D plug. You should refer to digital joystick connector pinouts for the wiring.

Parts and materials for this joystick cost less than a used stick shipped from eBay.  It works well, and its probably the only gaming device ever to have a logo written in Akzidenz-Grotesk.

Broken Pen Girih

broken_pen_girihWell, I didn’t expect that to happen. I was plotting this simple girih frame when something went wrong, and the plotter slammed the (new-old stock, almost unused … sniff) HP drafting pen into the side of the thick watercolour paper, breaking off the tip.

I didn’t notice the damage, so I restarted the plot, and the above smeary and uncertain lines came out. It’s certainly more organic than a mechanical plot would tend to be …

[tɒk bɒks] — a tiny hardware speech synthesizer/TTS

[tɒk bɒks]: case
[tɒk bɒks]: case
[tɒk bɒks]: inside
[tɒk bɒks]: inside. The observant amongst you will notice that the speech board is 1/10″ further in than it should be for ideal alignment with the USB serial adapter.
Back in the 1980s, the now-defunct Digital Equipment Corporation (“DEC”) sold a hardware speech synthesizer based on Dennis Klatt’s research at MIT.  These DECTalk boxes were compact and robust, and — despite not having the greatest speech quality — gave valuable speech, telephone and reading accessibility to many people. Stephen Hawking’s distinctive voice is from a pre-DEC version of the MIT hardware.

DEC is long gone, and the licensing of DECTalk has wandered off into mostly software. Much to the annoyance of those in earshot, I’ve always enjoyed dabbling in speech synthesis. DECTalk hardware remains expensive, partly because of demand from electronic music producers (its vocoder-like burr is on countless tracks), but also because there are still many people who rely on it for daily life. I couldn’t justify buying a real DECTalk, but I found this: the Parallax Emic 2 Text-to-Speech Module.  For about $80, this stamp-sized board brings a hardware DECTalk implementation to embedded projects.

The Emic 2 is really marketed to microcontroller hobbyists: Make Your Arduino Speak! sorta thing. But I wanted to make a DECTalk-ish hardware box, with serial input, a speaker, and switchable headphone/line jack.  [tɒk bɒks] (a fair approximation of how I pronounce “Talk Box”) is the result.

Hardware

  • Parallax Emic 2 Text-to-Speech Module
  • OSEPP FTDI USB-Serial Breakout — there are many USB-Serial boards that would do this, but two points in this one’s favour are: i) it has header pins for breadboard use, and ii) I had a spare one.
  • Small 8Ω speaker element — the one I used is most likely a headphone element, bought from Active Surplus (RIP). This should be as small as you can get away with (and still hear) as the USB-Serial connection isn’t designed to supply audio power.
  • Header pins and sockets
  • Toggle switch
  • Small project box with perfboard
  • Jumper wires and solder

Connections

Emic 2             Serial
======             ======
 GND                GND
 5V                 Vcc
 SOUT               RXD
 SIN                TXD

Emic 2             Speaker
======             =======
 SP-                -
 SP+  (via switch)  +

Using it

You’ll need some kind of serial terminal connection. In a pinch, you can use the serial monitor that is in the Arduino development environment. Either way, identify your serial port (/dev/ttyUSBN, COMN:, or /dev/tty-usbserialNNNN) and find a way to send 9600 baud, 8N1 characters to it. Hit Return, and you should be greeted by the Emic 2’s : prompt (or a ?, followed by :). Whether you get the prompt or not depends on whether local echo is set or not. Either way, try sending this line:

SAll watched over by machines of loving grace.

You should hear a voice say the title of Richard Brautigan’s lovely poem All Watched Over by Machines of Loving Grace (caution: video link contains nekkid hippies). You should get the : prompt back once the the speech has stopped. And that’s all there is to it: send an S, followed by up to 1023 bytes of (basically ASCII) text, followed by a newline, and it will be spoken. There’s more detail, of course, in the Emic 2 documentation and the Emic 2 Epson/Fonix DECTalk 501 User’s Guide for changing voices, etc. Yes, you can make it sing. No, you probably shouldn’t, though.

Notes

  1. The Emic 2 has no serial flow control, so you have to wait until the module stops speaking (or you send it the stop command) before you can send more. The easiest way is to poll the serial port and see if there’s the : prompt waiting. Until you see the prompt, any text you send it may be lost.
  2. The Emic 2 is an embedded device; Unicode is a bit of a stretch. It’s supposed to accept ISO Latin-1 8-bit characters (handy for Spanish mode), though.
  3. Starting every speech line with S may make this board incompatible with assistive technology software such as the JAWS screen reader. I don’t think that this was the goal for Emic 2’s designers (Grand Idea Studio), however.
  4. The output from the audio jack has a fair bit of noise on it, and you need to set the volume quite low to avoid hiss and hum. Your experience may be different, as I may have accidentally made a ground loop. There is a faintly  audible click at the start and end of the text, too.
  5. The Emic 2 uses DECTalk v5 commands and phonemes. Many DECTalk resources on the web (like these songs) use v4 or older, which are subtly incompatible. I haven’t found a reliable conversion protocol yet.

To end, here’s the Emic 2’s “Dennis” voice reading all of Brautigan’s All Watched Over By Machines of Loving Grace:


(plain link: molg-dennis-140wpm-16khz.mp3)

(even plainer link if you can’t decode MP2 files: molg-dennis-140wpm.mp3)

(recorded and edited for length with Audacity. No hippies — nekkid, or otherwise — were harmed in the making of this recording.)