Categories
audblog computers suck

PROTODOME’s wonderful chiptunes: how to play them on your own ATtiny85 chips

electronics breadbord with battery, speaker and sound generated by an 8-ping ATtiny85 mincrocontroller. Additional chips on the board are spares holding other tunes
Six whole tunes ready to play on this tiny chiptune player; a couple are included at the end of this article!

I love the ingenuity that goes into making very tiny projects do very big things. I also love chiptunes. So when I read the metafilter post about PROTODOME’s compositions for the ATtiny85, I was very much there for it.

The circuit to play this is no more than a $2 microcontroller, a lithium coin cell and a speaker or piezo buzzer. The microcontroller has 8 KB of program space and 512 bytes of RAM. The output is a single pin, but with very clever pulse width modulation tricks, sounds like three channels plus percussion.

The album is cool enough on its own, but Blake ‘PROTODOME’ Troise has not only published the source code, but also written an academic article on 1-bit music: “The 1-Bit Instrument: The Fundamentals of 1-Bit Synthesis, Their Implementational Implications, and Instrumental Possibilities.Journal of Sound and Music in Games 1.1 (2020): 44-74.

I remembered I had bought a tube of ATtiny microcontrollers a while back. I knew I had a coin cell and tiny speaker. “I can do this!”, I thought.

So what follows is tutorial on compiling embedded code for an ATtiny85 microcontroller on Linux. There are larger tutorials out there, there are better tutorials: but there are also many out-of-date and misleading tutorials. This isn’t a general ATtiny development tutorial, but one specialized on getting PROTODOME’s tunes playing on your microcontroller.

Hardware

The very minimum you will need to play the music is:

But that’s not all: you’ll need much more kit to program these tiny chips:

  • a computer running Linux. Yes, you can do this under Windows and Mac OS, but I don’t know how and there are search engines that care about that more than I do. I tested all of this on a Raspberry Pi 4. Tablets and phones are out, sorry
  • an AVR programmer. You can use an Arduino for this (either an official one or a cheaper clone) but you’ll need some additional fiddling and a 10 µF capacitor to get that going. I used a dedicated USBtinyISP programmer just because I had one, but it’s not really necessary. Whatever you use, you’ll need a USB cable for it
  • probably more jumper wires.

Software

There are two separate toolchains involved — one to build the mmml-compiler to convert PROTODOME’s compositions to µc embedded C code, and another to compile that to ATtiny85 instructions. We can install it all in one go:

sudo apt install avrdude gcc-avr binutils-avr avr-libc build-essential git

Building mmml-compiler is easy enough:

git clone https://github.com/protodomemusic/mmml.git
cd mmml/mmml-compiler
gcc -o mmml-compiler mmml-compiler.c

You can then run the compiler on each of the songs; the album title track, for example:

cd ../demo-songs/4000ad/
../../mmml-compiler/mmml-compiler 4000ad.mmml

⚠️ If you get [ERROR 14] Too few channels stated! instead of Successfully compiled! it seems that the compiler isn’t too happy running on some 64-bit systems. I did all my compilation on a Raspberry Pi 4 running Raspbian and all was well. If you can’t get them to compile, I’ve pre-compiled them for you and they’re at the end of this article.

You should now have a musicdata.h file that contains all the tune data. Copy it to the same folder as the mmml-player C code:

cp musicdata.h ../../mmml-player/
cd ../../mmml-player/

That folder now contains the player and one tune data file. Now you need to compile it into AVR instruction to write to your chip:

avr-gcc -g -Os -mmcu=attiny85 -DF_CPU=8000000 -o mmml.bin mmml.c
avr-objcopy -j .text -j .data -O ihex mmml.bin mmml.hex
rm mmml.bin

The end result of what that just did is create a single small file mmml.hex containing the ATtiny85 program instructions for the 8+ minute track 4000AD. If you’re compiling for a different µc, you’ll need a different avr-gcc line:

  • -mmcu=attiny85 will need to be changed for your µc. avr-gcc –target-help lists the supported targets in the ‘Known MCU names’ section way up at the top of its too-copious output. If you’re using the ATmega32P chip made popular by Arduinos, that option should be -mmcu=atmega328p
  • -DF_CPU=8000000 tells the compiler that the CPU frequency should be 8 MHz. The AVR µcs can run at a huge range of speeds, but PROTODOME’s music is timed to work at 8 MHz only.

→→→ aside

If you find yourself compiling a few simple AVR projects but want to stop short of a fine-but-overly-complex Makefile project for AVR development, this script to create a hex file from a single embedded C source file might be useful:

#!/bin/bash
# avrbuild.sh - build a simple AVR project - scruss, 2020-04
# usage: avrbuild.sh file.c mcutype freq
# eg: avrbuild.sh mmml.c attiny85 8000000

b="${1%.c}"
rm -f "$b.bin" "$b.hex"
avr-gcc -g -Os -mmcu="$2" -DF_CPU="$3" -o "$b.bin" "$b.c"
avr-objcopy -j .text -j .data -O ihex "$b.bin" "$b.hex"
avr-size --format=avr --mcu="$2" "$b.bin"
rm -f "$b.bin"

In addition to creating a hex file, it also runs the avr-size tool to show you much memory your program uses. The 4000AD tune uses 98% of the ATtiny85’s 8192 byte program space — not quite enough to include that 14 minute extra bass solo, sorry …

←←← end aside

Flashing the chip

So now we do some wiring. If you’re using a dedicated programmer, use jumpers to connect its ICSP port to the ATtiny 85 like this:

                        ________              
                       |o   A   |             
               Reset  -+ 1  T  8+-  VCC       
                       |    t   |             
                      -+ 2  i  7+-  SCK       
                       |    n   |             
                      -+ 3  y  6+-  MISO      
                       |    8   |             
               GND    -+ 4  5  5+-  MOSI      
                       |________|             
                                              

                 MISO    o1 2o   VCC   
                 SCK     o3 4o   MOSI     
                 Reset   o5 6o   GND 

                          ICSP
                        Connector

Wire VCC to VCC, MISO to MISO, MOSI to MOSI, SCK to SCK, Reset to Reset and GND to GND. If you’re using an Arduino, you want to do this:

This is ‘OLD_STYLE_WIRING’ for using ArduinoISP, apparently. But it works!

The wiring for that is:

  • Arduino D10 → ATtiny Pin 1 (Reset)
  • Arduino GND → ATtiny Pin 4 (GND)
  • Arduino D11 → ATtiny Pin 5 (MOSI)
  • Arduino D12 → ATtiny Pin 6 (MISO)
  • Arduino D13 → ATtiny Pin 7 (SCK)
  • Arduino 5V → ATtiny Pin 8 (VCC)
  • You’ll also need to put a 1-10 µF electrolytic capacitor between the Arduino’s Reset and GND pins, but only after you’ve programmed it with the ArduinoISP sketch.

You’re almost there!

Setting up the programmer: USBtinyISP

If you haven’t used one with your computer before, you need to do a little bit of prep so your computer recognizes it. These are modified from a gist:

  • do sudo vi /etc/udev/rules.d/41-usbtiny.rules
  • add the line SUBSYSTEM=="usb", ATTR{idVendor}=="1781", ATTR{idProduct}=="0c9f", GROUP="plugdev", MODE="0666"
  • save and exit
  • do sudo udevadm control --reload then sudo udevadm trigger

Your system should automatically recognize the device and give you permission to use it without sudo privileges.

Setting up the programmer: ArduinoISP

  • Load the ArduinoISP sketch (it’s in FileExamples)
  • Add (or find and uncomment) the line #define USE_OLD_STYLE_WIRING
  • Upload the code to your Arduino
  • Connect the 1-10 µF electrolytic capacitor between the Arduino’s Reset and GND pins

To program the mmml.hex you created earlier, you’ll need one of these avrdude commands:

For USBTinyISP:

avrdude -c usbtiny -p attiny85 -U lfuse:w:0xe2:m -U hfuse:w:0xdf:m -U efuse:w:0xff:m -U flash:w:mmml.hex:i

For ArduinoISP:

avrdude -c arduino -P /dev/ttyUSB0 -b 19200 -p attiny85 -U lfuse:w:0xe2:m -U hfuse:w:0xdf:m -U efuse:w:0xff:m -U flash:w:mmml.hex:i

What all that means:

  • -c usbtiny or -c arduino: programmer type. In addition, the arduino programmer takes additional parameters -P /dev/ttyUSB0 -b 19200 which specify the port (usually /dev/ttyUSB0 or /dev/ttyACM0) and the baud rate (always 19200, unless you changed it in the source of ArduinoISP)
  • -p attiny85: the chip type, as used in the avr-gcc compiler call way up the top
  • -U lfuse:w:0xe2:m -U hfuse:w:0xdf:m -U efuse:w:0xff:m: fuses are AVR’s confusing name for configuration bits. You might just have to take my word that this sets an ATtiny85 to use the internal 8 MHz oscillator (as opposed to an external crystal) we told the compiler to use further back. A guide to fuse settings is available at the Engbedded AVR Fuse Calculator
  • -U flash:w:mmml.hex:i: the hex file we prepared, mmml.hex.

If everything went right with your flashing process, you should see lots of “avrdude: verifying … done. Thank you”. If you don’t, likely you missed a connection somewhere.

♫ Playing the tunes! ♫

This circuit’s a lot simpler than it looks!

I already described all of the bits in the bill of materials in the Hardware section. If you want it in ASCII art, here’s all there is to it:

                        ________              
                       |o   A   |             
          VCC--(10kΩ)--+ 1  T  8+--VCC        
                       |    t   |             
                      -+ 2  i  7+-            
                       |    n   |             
                      -+ 3  y  6+-      (     
                       |    8   |      ((     
                  GND--+ 4  5  5+--(SPKR(--GND
                       |________|      ((     
                                        (     

          Pin 1: RST - held high through pull-up to prevent reset
          Pin 4: GND
          Pin 5: PB0 - through speaker/buzzer to GND
          Pin 8: VCC - can be a CR2032 Lithium coin cell

          Not shown: 100 nF decoupling capacitor between VCC and GND
          Short Pin 1 to GND to restart song

If you weren’t able to compile the tunes, I’ve included (with Blake’s permission) source for any AVR µc plus hex files for ATtiny85s here: protodome-mmml-examples.zip

Last but not least, there are a couple of tracks included in the source that aren’t on the 4000AD album. Blake gave me permission to include them here, too:

Fly Me to the Moon by Bart Howard, arranged for ATtiny85 microcontroller by PROTODOME, 2020.
Download: fly_me_to_the_moon.mp3
Till There was You by Meredith Willson (from the musical ‘The Music Man’), arranged for ATtiny85 microcontroller by PROTODOME, 2020.
Download: till_there_was_you.mp3

These weren’t recorded from a tiny speaker (that went badly), but directly to a Marantz solid state recorder. The rig’s the same as the playback one, with the speaker replaced by a potentiometer (for level control), a 100 µF capacitor (to take off some of the DC bias and also to cut some of the very high frequencies) and a headphone socket. Have fun!

it’s the most awkward walkman!

Categories
computers suck

goodbye X10, hello trådfri …

scruss/ihsctrl: a package of bash scripts to control selected IKEA Home smart (aka “TRÅDFRI”) devices via their network gateway

The old X10 devices were getting really unreliable: seldom firing at all, getting far too hot, bringing a whole lot of not working to my life. So while it was kind of cool to have my lights controlled by an original 256 MB Raspberry Pi Model B from 2012, it was maybe working one schedule out of ten.

So it had to go: replaced by a Raspberry Pi Zero W and a whole lot of IKEA TRÅDFRI kit. I was deeply unimpressed with the IKEA Home smart app, though: you couldn’t use even basic schedules with more than one light cycle per day. So while I know there are lots of clever home automation systems, I wanted to replace my old cron scripts and set about writing some simple command tools. The result is ihsctrl: very limited, but good enough for me. It’s been working exactly as expected for the last week, so I’ll finally get to wade through 8 years of cobwebs and dismantle the old X10 setup. I already miss the 06:30 clonk of the X10 controller turning the front light on — that was my alarm clock (or alarm clonk) every morning.

(local copy: ihsctrl.zip)

Categories
computers suck

The coolest font (when I was 15, that is)

vaguely uncial style bitmap font from old 8-bit Level 9 text adventure
The Colossal Cave font on the Amstrad CPC 464

Though I didn’t really have the patience for text adventures, Level 9 used what I thought was the coolest font (circa 1985). After checking through them all on the Internet Archive Amstrad CPC software library, I couldn’t find a version that used this bitmap font. I eventually found it on nvg. After lots of messing about, I extracted it and present it here. I’m sure I’ll make a TTF of it soon enough.

Tastes change a bit, don’t they?

 10 REM     *** L9FONT.BAS ***
 15 REM bitmap font from Level 9's
 20 REM Colossal Cave adventure
 30 REM  on the Amstrad CPC 464
 40 REM (it was so cool at the time…)
 50 REM Dug up by scruss, 2019-12
 60 REM ==============================
 100 SYMBOL AFTER 32
 110 MODE 1
 120 GOSUB 1000
 130 PRINT" *** It's the Level 9 font ***"
 140 PRINT" ***  from Colossal Cave!  ***"
 150 PRINT"   Dug up by scruss, 2019-12"
 160 PRINT
 170 PEN 2
 180 PRINT"Lorem ipsum dolor sit amet, consectetur"
 190 PRINT"adipiscing elit, sed do eiusmod tempor"
 200 PRINT"incididunt ut labore et dolore magna"
 210 PRINT"aliqua. Ut enim ad minim veniam, quis"
 220 PRINT"nostrud exercitation ullamco laboris"
 230 PRINT"nisi ut aliquip ex ea commodo consequat"
 240 PRINT"arfle barfle gloop? | | |"
 250 PRINT
 260 PEN 1
 270 FOR i%=32 TO 127
 280 PRINT CHR$(i%); " ";
 290 NEXT i%
 300 PRINT
 310 PRINT
 990 END
 1000 SYMBOL 33,&18,&24,&24,&24,&18,&0,&18,&0
 1010 SYMBOL 34,&66,&66,&44,&88,&0,&0,&0,&0
 1020 SYMBOL 35,&0,&24,&7E,&24,&24,&7E,&24,&0
 1030 SYMBOL 36,&12,&7C,&D0,&7C,&16,&FC,&10,&0
 1040 SYMBOL 37,&E4,&A4,&E8,&10,&2E,&4A,&4E,&0
 1050 SYMBOL 38,&70,&D8,&D8,&72,&D6,&CC,&76,&0
 1060 SYMBOL 39,&30,&30,&20,&40,&0,&0,&0,&0
 1070 SYMBOL 40,&1C,&38,&70,&70,&70,&38,&1C,&0
 1080 SYMBOL 41,&70,&38,&1C,&1C,&1C,&38,&70,&0
 1090 SYMBOL 42,&10,&54,&38,&FE,&38,&54,&10,&0
 1100 SYMBOL 43,&0,&10,&10,&7C,&10,&10,&0,&0
 1110 SYMBOL 44,&0,&0,&0,&0,&30,&30,&20,&40
 1120 SYMBOL 45,&0,&0,&0,&F8,&0,&0,&0,&0
 1130 SYMBOL 46,&0,&0,&0,&0,&0,&60,&60,&0
 1140 SYMBOL 47,&0,&4,&8,&10,&20,&40,&0,&0
 1150 SYMBOL 48,&7C,&C6,&CE,&D6,&E6,&C6,&7C,&0
 1160 SYMBOL 49,&8,&18,&38,&18,&18,&18,&3C,&0
 1170 SYMBOL 50,&3C,&66,&C,&18,&30,&62,&7E,&0
 1180 SYMBOL 51,&7E,&4C,&18,&3C,&6,&66,&3C,&0
 1190 SYMBOL 52,&4,&C,&1C,&2C,&7E,&C,&1E,&0
 1200 SYMBOL 53,&3E,&66,&60,&7C,&6,&6,&7C,&0
 1210 SYMBOL 54,&3C,&66,&60,&7C,&66,&66,&3C,&0
 1220 SYMBOL 55,&7E,&46,&6,&C,&C,&18,&18,&0
 1230 SYMBOL 56,&3C,&66,&34,&18,&2C,&66,&3C,&0
 1240 SYMBOL 57,&3C,&66,&66,&3E,&6,&66,&3C,&0
 1250 SYMBOL 58,&0,&30,&30,&0,&0,&30,&30,&0
 1260 SYMBOL 59,&0,&30,&30,&0,&30,&30,&20,&40
 1270 SYMBOL 60,&1C,&30,&60,&C0,&60,&30,&1C,&0
 1280 SYMBOL 61,&0,&0,&F8,&0,&F8,&0,&0,&0
 1290 SYMBOL 62,&E0,&30,&18,&C,&18,&30,&E0,&0
 1300 SYMBOL 63,&7C,&64,&C,&18,&10,&0,&10,&0
 1310 SYMBOL 64,&7C,&C6,&DE,&D2,&DE,&C0,&7E,&0
 1320 SYMBOL 65,&18,&6C,&C6,&C6,&FE,&66,&F6,&0
 1330 SYMBOL 66,&FC,&C6,&C6,&FC,&C6,&C6,&FC,&0
 1340 SYMBOL 67,&3C,&66,&C0,&C0,&C0,&66,&3C,&0
 1350 SYMBOL 68,&D8,&EC,&C6,&C6,&C6,&EC,&D8,&0
 1360 SYMBOL 69,&FE,&62,&60,&78,&60,&62,&FE,&0
 1370 SYMBOL 70,&FE,&62,&60,&78,&60,&60,&E0,&0
 1380 SYMBOL 71,&3C,&66,&C0,&CE,&C6,&66,&3C,&0
 1390 SYMBOL 72,&C6,&C6,&C6,&FE,&C6,&C6,&C6,&0
 1400 SYMBOL 73,&7E,&18,&18,&18,&18,&18,&7E,&0
 1410 SYMBOL 74,&FE,&8C,&C,&C,&C,&CC,&78,&0
 1420 SYMBOL 75,&E6,&CC,&D8,&F0,&D8,&CC,&C6,&0
 1430 SYMBOL 76,&E0,&C0,&C0,&C0,&C0,&C2,&FE,&0
 1440 SYMBOL 77,&C6,&EE,&FE,&D6,&C6,&C6,&CC,&0
 1450 SYMBOL 78,&CE,&E6,&F6,&DE,&CE,&C6,&C6,&0
 1460 SYMBOL 79,&38,&6C,&C6,&C6,&C6,&6C,&38,&0
 1470 SYMBOL 80,&DC,&E6,&C6,&C6,&FC,&C0,&C0,&0
 1480 SYMBOL 81,&38,&6C,&C6,&C6,&CA,&64,&3A,&0
 1490 SYMBOL 82,&DC,&E6,&C6,&C6,&FC,&CC,&C6,&0
 1500 SYMBOL 83,&7C,&C6,&C0,&7C,&6,&C6,&7C,&0
 1510 SYMBOL 84,&FE,&B2,&30,&30,&30,&30,&30,&0
 1520 SYMBOL 85,&E6,&66,&C6,&C6,&C6,&C6,&7C,&0
 1530 SYMBOL 86,&E6,&66,&C6,&C6,&CC,&78,&30,&0
 1540 SYMBOL 87,&EC,&66,&C6,&C6,&D6,&D6,&6C,&0
 1550 SYMBOL 88,&EE,&C6,&6C,&38,&6C,&C6,&EE,&0
 1560 SYMBOL 89,&EE,&C6,&2C,&18,&18,&18,&18,&0
 1570 SYMBOL 90,&FE,&8C,&18,&30,&60,&C2,&FE,&0
 1580 SYMBOL 91,&7C,&64,&60,&60,&60,&60,&7C,&0
 1590 SYMBOL 92,&0,&60,&30,&10,&8,&C,&6,&0
 1600 SYMBOL 93,&3E,&6,&6,&6,&6,&26,&3E,&0
 1610 SYMBOL 94,&18,&24,&42,&42,&0,&0,&0,&0
 1620 SYMBOL 95,&0,&0,&0,&0,&0,&0,&EE,&BB
 1630 SYMBOL 96,&3C,&22,&78,&20,&78,&20,&7E,&0
 1640 SYMBOL 97,&0,&0,&74,&DC,&C4,&CC,&74,&0
 1650 SYMBOL 98,&C0,&C0,&DC,&E6,&C6,&E6,&DC,&0
 1660 SYMBOL 99,&0,&0,&78,&CC,&C0,&CC,&78,&0
 1670 SYMBOL 100,&0,&70,&18,&7C,&CC,&CC,&78,&0
 1680 SYMBOL 101,&0,&0,&78,&CC,&FC,&C0,&7C,&0
 1690 SYMBOL 102,&68,&74,&60,&F8,&60,&60,&60,&C0
 1700 SYMBOL 103,&0,&0,&78,&CC,&C0,&CC,&7C,&C
 1710 SYMBOL 104,&C0,&C0,&D8,&EC,&CC,&D8,&DC,&0
 1720 SYMBOL 105,&C,&0,&38,&18,&18,&18,&38,&0
 1730 SYMBOL 106,&6,&0,&1C,&C,&C,&C,&4C,&38
 1740 SYMBOL 107,&C0,&C0,&CC,&D8,&F0,&D8,&CE,&0
 1750 SYMBOL 108,&30,&30,&30,&30,&30,&36,&3E,&0
 1760 SYMBOL 109,&0,&0,&AC,&D6,&D6,&C6,&CC,&0
 1770 SYMBOL 110,&0,&0,&BC,&C6,&C6,&CC,&DE,&0
 1780 SYMBOL 111,&0,&0,&7C,&C6,&C6,&C6,&7C,&0
 1790 SYMBOL 112,&0,&0,&DC,&E6,&C6,&E6,&DC,&C0
 1800 SYMBOL 113,&0,&0,&76,&CE,&C6,&CE,&76,&6
 1810 SYMBOL 114,&0,&0,&DC,&E6,&C6,&FC,&C6,&0
 1820 SYMBOL 115,&0,&0,&3C,&60,&3C,&8E,&7C,&0
 1830 SYMBOL 116,&18,&30,&FC,&30,&30,&32,&1C,&0
 1840 SYMBOL 117,&0,&0,&E6,&66,&C6,&C6,&7A,&0
 1850 SYMBOL 118,&0,&0,&EC,&66,&C6,&EC,&38,&0
 1860 SYMBOL 119,&0,&0,&EC,&C6,&D2,&7C,&28,&0
 1870 SYMBOL 120,&0,&0,&EE,&6C,&38,&6C,&EE,&0
 1880 SYMBOL 121,&0,&0,&EC,&C6,&6C,&18,&30,&E0
 1890 SYMBOL 122,&0,&0,&FE,&9C,&30,&62,&FE,&0
 1900 SYMBOL 123,&C,&30,&30,&60,&30,&30,&C,&0
 1910 SYMBOL 124,&CF,&DB,&DB,&CF,&C3,&DB,&FB,&0
 1920 SYMBOL 125,&60,&18,&18,&C,&18,&18,&60,&0
 1930 SYMBOL 126,&7C,&C6,&BA,&A2,&BA,&C6,&7C,&0
 1940 SYMBOL 127,&FF,&FF,&FF,&FF,&FF,&FF,&FF,&FF
 1950 RETURN

Categories
computers suck

TPUG Library CD – disk image contents, mostly

TPUG – Toronto PET Users Group still publishes its software library for Commodore computers. You can buy it for $20.00 (Cdn) plus shipping and handling. Yes, it still makes TPUG money to sell it this way. No, it’s not available online.

The scanned library catalogues are available as PDF: About the TPUG Library. They’re searchable via web search engines:
Google: site:tpug.ca amiga “puzzle maker”. The search is only as good as the OCR in the scan, but is better than nothing.

What you can’t do is search inside the disk images themselves. The files I made below might help with that, especially once search engines get hold of them:

Each line has the disk name and then the name of the file in that disk image, something like:

TPUG C64/A-Monthly Disks/(c)aaa.d64 : 0 "tpug may86(c)aaa" ac 2a
TPUG C64/A-Monthly Disks/(c)aaa.d64 : 23 "autoload" prg
TPUG C64/A-Monthly Disks/(c)aaa.d64 : 119 "infusr/2.0.txt" seq
TPUG C64/A-Monthly Disks/(c)aaa.d64 : 13 "infbot/2.1" prg
 …

Note that I haven’t uploaded any of the disk images. Please don’t ask me for them.

Categories
computers suck goatee-stroking musing, or something

Possibly Painless Network Printing from your Raspberry Pi

Printing from computers goes through waves of being difficult to being easy, then back to difficult again. This is likely due to the cycles of technology, complexity and user demand flow in and out of sync. I think we’re at peak annoyance right now.

It’s even harder with Raspberry Pis, as when printer drivers support Linux, 90% of them are for x86 or x86_64 computers only (Canon: ಠ_ಠ). ARM doesn’t get a look in. But one technology does actually seem to help: network printers that support IPP — Internet Printing Protocol.

We had an old Brother laser printer that just got slower and crankier and less useful as a printer, so yesterday I got a new Brother DCP-L2550DW to replace it. It says it supports Linux in the spec, but I knew not to be too optimistic with my Raspberry Pis. And indeed, it was seen on the network but no driver was found. I had a sad.

What turned my frown upside down was finding out about Raspbian’s cups-ipp-utils package. For desktop use, install it this way:

sudo apt install cups cups-ipp-utils system-config-printer

(leave off system-config-printer if you’re running from the terminal.)

Update: while you’re here, you might also want to install the print-to-PDF driver too. This allows you to print without wasting paper. Install it (and the IPP driver) with:

sudo apt install cups cups-ipp-utils system-config-printer printer-driver-cups-pdf

On the desktop, open up Preferences → Print Settings and add a new printer. Yes, it prompts for your user password which you may have forgotten. I’ll wait while you try to remember it …

Now under Network Printers, you should see a device you recognize. Pick the one that says IPP network printer somewhere:

IPP network printer

Here’s where the magic happens: you actually want to pick the generic driver for once:

Select Generic (recommended) manufacturer

And again, the IPP utilities package will have picked the right driver for you:

Just go with what the driver suggests

Changing the name and location is optional:

Your new printer’s almost ready to go!

Hit Apply, and you should be printing!

(Hey, printer manufacturers have been known to be evil and make good, working stuff suddenly not work. IPP is supposed to make everything sparkly again, but I can’t guarantee that something wicked won’t come this way.)

Update: After a few months of using the Brother DCP-L2550DW, I don’t recommend you buy it. It’s a perfectly capable printer, but it takes ‘chipped’ toner cartridges that:

  1. stop dead when you hit their page count limit, wasting toner and preventing you from finishing the print job;
  2. can’t easily be refilled by local technicians, so are wasteful of resources.

To get around (1), select Continue instead of Stop in the Toner Out configuration menu.

Update, January 2020: with sales and all needing a printer for work, the DCP-L2550DW will go with me to the office. I now have a MFC-L2750DW at home that scans to network, amongst other things. IPP proved it was magic yet again by the new printer being found and just worked with all my machines as soon as I added it to the network.

Categories
computers suck

Just what 2019 needs: the QBasic Online Help Index

QBasic (from olddos.exe) running nicely under dosbox on Linux

Only umpteen years late, I bring you the

QBasic Online Help Indexhttps://scruss.com/qbasic_hlp/

It’s the QuickHelp file from Microsoft’s ancient-but-still-useful QBasic interpreter for MS-DOS. I converted it to HTML, and made some minor cleanups so it would work better on the web.

So if you’ve got a hankering to understand the parameters for MKSMBF$ or know the syntax of PRINT USING, I’ve got your back.

Categories
computers suck

HSV(ish) Colour Wheel in Python

Years back I wrote something about HSV colour cycling for Arduino. Things have moved on: we’re all writing code in MicroPython/CircuitPython now and 8-bit micro-controllers are looking decidedly quaint. Yes, yes; some of you must still write code in PIC assembly language and I’m sure that’s very lovely for you indeed don’t @ me.

If you look at the output of a typical HSV to RGB algorithm, the components map something like this:

Hue between 0-1, with saturation and value set to 1. Output range 0-1 for each component

These lines remind me so much of sine waves, if very blocky ones. The red trace in particular is just the cosine function, with the input range of 0..2π and the output range of -1..1 both mapped to 0..1. The green and blue traces are just the red trace shifted horizontally by ⅓ and ⅔ respectively.

Since we have transcendental functions in MicroPython, we don’t have to fossick about with linear approximations. The common RGB LED function wheel() uses similar linear interpolation as the graph above. Why make do with blocky cogwheels when you can have a smooth colour wheel?

def cos_wheel(pos):
# Input a value 0 to 255 to get a colour value.
# scruss (Stewart Russell) - 2019-03 - CC-BY-SA
from math import cos, pi
if pos < 0:
return (0, 0, 0)
pos %= 256
pos /= 255.0
return (int(255 * (1 + cos( pos * 2 * pi)) / 2),
int(255 * (1 + cos((pos - 1 / 3.0) * 2 * pi)) / 2),
int(255 * (1 + cos((pos - 2 / 3.0) * 2 * pi)) / 2))
Though you never quite get a pure red, green or blue, the results are pleasing

Quite elegant, I thought. Yeah, it may be computationally expensive, but check next year when we’ll all be running even faster µcs. Certainly none of the mystery switch statements or nested conditionals you’ll see in other code. Just maths, doing its thing.

First half is cosine wheel, second half (after red flash) is linear
Categories
computers suck

Symmetric chamfered extrusion in OpenSCAD

enjoy the quality of the smooth, smooth taper

I like using OpenSCAD, but it has some limitations. While you can linear_extrude() 2D paths into 3D shapes, you can’t get a proper tapered/chamfered extrusion of anything but simple shapes that are symmetric about the origin:

// this is symmetrical …
linear_extrude(height=20, scale=2)square(10, center=true);

// but shift the same square off the origin and this happens …
linear_extrude(height=20, scale=2)translate([20, 20])square(10, center=true);

There are lots of partial attempts at fixing this, many of which end up with ugly results. Some of them even mess up the top surface, which is precisely what I wanted to avoid. My code uses the computationally-intensive minkowski() sum function to replace every vertex of a 2D shape with a many-sided pyramid.

Minkowski sums effectively replace every vertex with another shape, here making a rounded cube from a cube and a sphere:

minkowski() {
cube(10);
sphere(4);
}

One feature of OpenSCAD’s implementation of the Minkowski sum is that the operator takes into account the second shape’s position relative to the origin. So if I take the same cube and apply the minkowski() operator with the same sphere moved away from the origin, I get:

// the same cube, but shifted by the power of minkowski()!
minkowski() {
cube(10);
translate([-15,-15,-15])sphere(4);
}

So I can approximate a tapered extrusion by turning a 2d path into a very thin 3d plate (OpenSCAD’s 2D and 3D subsystems can never meet in the same output) and using a pyramid as the second argument to the operator:

// the component parts, before minkowski()

// thin extrusion of 2D path
linear_extrude(height=0.001)text(“S”, size=24, font=”EB Garamond:style=12 Italic”);

// a 30 degree pyramid with its apex at the origin
rotate_extrude()polygon([ [0,0] , [4, -8], [0, -8] ]);

You get:

minkowski() {
// thin extrusion of 2D path
linear_extrude(height=0.001)text(“S”, size=24, font=”EB Garamond:style=12 Italic”);
// a 30 degree pyramid with its apex at the origin
rotate_extrude()polygon([ [0,0] , [4, -8], [0, -8] ]);
}

In reality, you’d probably use a smaller taper angle, but the example is short rather than pretty. If you’re really picky about correctness, the process leaves the thin extrusion as parallel walls at the bottom of the shape, shown grossly exaggerated here for effect:

hugely exaggerated vertical profile

If you’re working in consumer-grade 3D printing and are using the standard 1 unit = 1 mm scale, the residual parallel section would only be 1 µm thick and way below any realistic layer height. Feel free to remove it, but be warned that this process creates so many facets that the difference() required to remove it will be very time-consuming for no visible difference.

Here’s the code: chamfer_extrude.scad – make sure to rename the txt extension to scad. Or, if you’d prefer, here’s a link to a gist: scruss/chamfer_extrude.scad

Put it in your OpenSCAD library folder, then you can use it like this:

include <chamfer_extrude.scad>; 

chamfer_extrude(height=4, angle=15, $fn=16)text("S", size=24, font="EB Garamond:style=12 Italic", $fn=64);
way smooth s

The library just adds some expected utility and tidiness to the above process. The source includes documentation and examples.

Categories
computers suck

joy!!!

Llamasoft’s Five a Day on Android

I can play Five A Day on my Android phone. You should too.

Categories
computers suck

non-aesthetic gears

Categories
computers suck

hypnotapir

original: Cheyenne Mountain Zoo (Facebook), 2018-11-08.

Categories
computers suck

SBC6120 build: day 1(-ish)

SBC6120 (RBC Edition) with all the sockets

Just started on a SBC6120 RBC Edition kit. It’s a DEC PDP-8-compatible single board computer that uses a CMOS chipset from the early 1980s. Yes, it will be very slow, even with the optional speedy 8 MHz oscillator installed. With a 12-bit processor and 32 kilo-words of RAM, this is definitely going to be a Slow Computing device.

Lots and lots of sockets. So many sockets. It’s quite soothing soldering them all in, one hole at a time. It looks like it’ll go more quickly than the Zeta did.

> Does anyone know what each of the pins on the 6502 CPU chip in the Apple II Plus does?
They all plug into the socket on the motherboard to keep the chip from drifting away. – c.s.a2 FAQ of yore

Categories
computers suck

eben’s bbc basic programmes

I wrote this as a comment to Learn to write games for the BBC Micro with Eben – Raspberry Pi, but it didn’t seem to save:

BeebEm? Lawks, that’s a bit old (2006). All the cool (*cough*) kids are running b-em – https://github.com/stardot/b-em – these days. It’s lovingly maintain by Stardot forum members. It’s a little crashy on some Linux platforms, but seems stable on the Raspberry Pi and Raspbian. You may need to install the liballegro5-dev and zlib1g-dev packages to get it to compile.

If you want a native version of BBC BASIC, Richard Russell’s version is pretty neat: http://www.bbcbasic.co.uk/bbcsdl/ . You’ll most likely need to change line 280 to use some variant of the WAIT command to make it playable.

Another native interpreter is Brandy. There’s an ancient one in the repos, but I’m completely taken with the Matrix Brandy fork: https://github.com/stardot/MatrixBrandy . It may need a few packages installed to get it to build (libsdl1.2-dev might be a good first try), but it’s really fast. For cross-platform happiness, change line 280 to WAIT 10. If you stick to using a FOR loop, you might have to have it as high as 2,000,000 on a fast computer!

Lastly, if you want to run the game in a browser, JSBeeb to the rescue: https://bbc.godbolt.org/?autorun&loadBasic=https://gist.githubusercontent.com/scruss/f5a8eb83f28b85d6399142cac460c806/raw/74c4e39de7661bb2e3dd7f435840dd8db7172589/helicopter.bbc
It’s a bit slow in Chromium on a Raspberry Pi, but it does work!

Categories
computers suck

Small things that make me happy …

Chebucto Community Net in Nova Scotia still has all its downloads and instructions for helping to get an Apple II (8 bit) & Apple IIGS (16 bit) online.

Categories
choons computers suck

Comprehensive Uncle TechTip Simulator

Around 1988–1991 there was a weekly computer magazine in the UK called New Computer Express. This period coincided roughly with the time I was a freelance writer in the same field.

For childish reasons now lost to time, a group of us freelancers had a major hate-on for  NCE’s advice columnist. Writing under the name Uncle TechTip, this columnist seemed to answer most questions with something like “Hmm, I don’t know anything about _____. Maybe a reader can help?” Almost without fail, he’d have readers write in answers for next week’s issue.

Not realizing that Uncle TT’s economy of response was a sly precursor to crowdsourcing websites, the neophyte journo brigade were incensed by his lack of knowledge. One of us wrote an Uncle TechTip Simulator in BASIC, which I recreate from memory for your enjoyment:

10 CLS
15 PRINT " *** Uncle TechTip Simulator ***"
20 PRINT
25 INPUT "What is your question for Uncle TechTip";a$
30 PRINT
35 PRINT "Uncle TechTip's Answer: "
40 PRINT
45 PRINT "Hmm, I don't know anything about"
50 PRINT " ";a$;" ..."
55 PRINT "Maybe a reader can help?"
Categories
computers suck

Using SI prefixes/multipliers in spreadsheets

Note: I’ve lightly tested this with Microsoft Excel (Windows 10), Excel Online, Google Sheets and LibreOffice Calc. It seems to work. Like all spreadsheet data conversions, please verify before trusting your PhD thesis tables to it …

Asked on the GTALUG mailing list the other week:

Does anybody know how to display and work with SI numbers like 10k or 
20M or 40G within LibreOffice?

I came up with the following formula, in this example for data in cell D3:

=IF(LEN(T(D3))=0, D3, CONVERT(VALUE(LEFT(D3, LEN(D3) - 1)),
    RIGHT(D3, 1) & "m", "m"))

which results in:

Input Value
1u 1.00E-06
10u 10.00E-06
100u 100.00E-06
1m 1.00E-03
10m 10.00E-03
100m 100.00E-03
1 1.00E+00
10 10.00E+00
100 100.00E+00
1k 1.00E+03
10k 10.00E+03
100k 100.00E+03
1M 1.00E+06

The right column is displayed in LibreOffice Calc’s newly(ish)-supported engineering notation.

This function works through creative (mis-)use of the CONVERT() function:

  1. if the argument is a numeric value, pass it through;
  2. if the argument is a string, return CONVERT(«numeric part», "«prefix»m", "m"). This is lightly misusing overloading the unit conversion function by going via metres, but it saves having a lookup table.

This function doesn’t work with IEC 60027-2 binary prefixes, but they’re silly and I wouldn’t be caught dead using ’em.

Categories
computers suck

vase mode

I’m still a sucker for vase mode/spiral contour prints … this one made in OpenSCAD:

Thanks to Andrew at ProtoLab for the loan of the PrintrBot. I’ve got a demo at UofT on Wednesday, and my Reach 3D isn’t exactly portable. Yeah, I should probably get a cheap Monoprice printer to lug around to occasional demos, but I’d need to find a donor …

Categories
computers suck

Thingiverse Customizer: a tiny guide

Thingiverse‘s Customizer allows users to customize suitable OpenSCAD models without knowing any OpenSCAD code. While it does have some documentation to help developers along, there’s still a lot of guesswork.

I released my first (working!) Customizer design the other week: Parametric Finger Pen Holder (Vertical). While the docs are the primary source of developer information, you might want to know the following:

  • Customizer assumes that every variable defined before the first module definition in the script is a user parameter. To give it a hint that it should stop displaying variables, add an empty module (such as module naff() { }) after the last variable definition you want Customizer to display.
    (There’s supposed to be a CUSTOMIZER VARIABLES/CUSTOMIZER VARIABLES END comment pair that will do this too, but it didn’t work for me)
  • Customizer will fail if there’s any character other than strict ASCII in the script, and won’t give useful diagnostics about the problem. Check your comments for accents and fancy punctuation
  • Customizer displays a real-time preview of your model. This means the rendering will be a little rough, especially if you use set operations such as union(), difference() and intersection(). If you have to hit F6 to render your model in OpenSCAD properly, it’s going to look a bit off in Customizer
  • If you must use resource-intensive functions such as hull() and minkowski(), try to limit them to 2D paths that are subsequently extruded. Everyone else in the Customizer job queue will thank you
  • Similarly, keep the circle smoothness variables ($fa, $fn, $fs) in sensible ranges
  • Customizer creates a new Thing under your name rather than just letting you download your customized model. You likely want to delete that once you’re finished with it.
    (This also means that Customizer only works for registered Thingiverse users. I can’t see any way around this, unfortunately)
Categories
computers suck

“space acid poisoning …”

Thanks to users sbadger and lurkio on the stardot forum, I’ve been reunited the original BBC BASIC one-liner that begat 2d Star Dodge/Stardodger: Asterisk Tracker!

Asterisk Tracker

It was published in the December 1984 edition of BEEBUG Magazine (vol. 3, issue 7; page 9) and is credited to N. Silver.

It’s impossibly short:

1L=0:REP.L=L+3:MO.4:DR.1279,0:DR.1279,452:MOVE1279,572:DR.1279,1023:DR.0,1023:F.I=1TOL:V.31,RND(32)+5,RND(31),42,30:N.:P.(L-3)/3:X=0:Y=512:REP.PL.69,X,Y:X=X+4:Y=Y-(INKEY-74+.5)*8:U.PO.X,Y)=1ORX=1280:U.X<1280:V.7:REP.U.INKEY-99:RUN

It makes extensive use of BBC BASIC’s abbreviations, and the writeup even warns

… Here the programs are extensively abbreviated so that the line will fit into Basic’s keyboard buffer. Because of this, you cannot edit a LISTed version, and so, to allow for errors, it is best to spool out a copy of the text to tape/disc initially. This can be achieved as follows:

*SPOOL PROGRAM
type in program
*SPOOL

The program unwinds to something much more understandable:


   10 L=0
   20 REPEAT
   25   L=L+3
   30   MODE 4
   40   DRAW 1279,0
   50   DRAW 1279,452
   60   MOVE 1279,572
   70   DRAW 1279,1023
   80   DRAW 0,1023
   90   FOR I=1 TO L
  100     VDU 31,RND(32)+5,RND(31),42,30
  110   NEXT
  120   PRINT (L-3)/3
  130   X=0
  140   Y=512
  150   REPEAT
  155     PLOT 69,X,Y
  160     X=X+4
  170     Y=Y-(INKEY(-74)+.5)*8
  180   UNTIL POINT(X,Y)=1 OR X=1280
  190 UNTIL X<1280
  200 VDU 7
  210 REPEAT UNTIL INKEY(-99)
  220 RUN

The instructions are typical of the day:

The first game (called ‘Asterisk Tracker’) is a very simple game in which you have to guide a ‘snake’ across the screen, whilst avoiding the stars. As the game progresses, more and more stars will be displayed, and the ease of the game rapidly disappears. The Return key guides the ‘snake’ upwards, but it moves down if Return is not pressed. Aim your ‘snake’ for the gap in the wall, and don’t touch any objects as this causes instant death from space acid poisoning!

Um, yeah, N. Silver, whatevs …

It’s pretty amazing that three type-ins could fit on a page: especially when you consider that the BEEBUG magazine was A5!

beebug vol 3 issue 7 page 9

If you want to play it (and who wouldn’t? We wasted days on this game) you can either run this Asterisk Tracker alone in the browser: Asterisk Tracker, or lurkio has combined them into one, and put them here: Beebug One-Line Games (Asterisk Tracker, a Truffle Hunt clone, and a treasure hunt).

I just wish Graeme Smith were still with us to play this.

Categories
computers suck

moar 10PRINT nonsense

10 Print CHR$(205.5+RND(1)): Goto 10

but this still owns it:

10 PRINT CHR$(199+2*RND);: GOTO 10

I found I can get this to preload in an emulator, but you still have to type RUN and hit return. See, look: http://scruss.com/cpc/6128s.html?stardoj.dsk/10%20PRINT%20CHR$(199+2*RND);:%20GOTO%2010