Categories
photo

Indifferent Salad with Cheezies

Indifferent Salad with Cheezies

Instagram filter used: Normal

View in Instagram ⇒

Categories
photo

disco eggdog

disco eggdog

Instagram filter used: Lo-fi

View in Instagram ⇒

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
photo

moar nerrrdy shytte #attiny85

moar nerrrdy shytte #attiny85

Instagram filter used: Lo-fi

View in Instagram ⇒

Categories
photo

0.8g of amalgam fell out my head today

0.8g of amalgam fell out my head today

Instagram filter used: Normal

View in Instagram ⇒

Categories
photo

sunday morning chiptunes

sunday morning chiptunes

Instagram filter used: Lo-fi

View in Instagram ⇒

Categories
goatee-stroking musing, or something

I maded it: TRex Solder 3rd Hand

TRex Solder 3rd Hand

https://www.thingiverse.com/thing:4241697

(since Thingiverse’s markdown parser seems to be broken)

Summary

A weighted, non-slip, non-wobble soldering third hand.

Huge thanks to Modular Hose for giving me the Loc-Line samples I used to make this!

Why is it called TRex? It’s got really short arms …

Despite what Thingiverse might say, this is not a Customizer project. Opening that link will disappoint.

Parts required

  • at least 12× ¼” Loc-Line segments
  • 2× Loc-Line ¼” NPT threaded connectors
  • 2× Loc-Line ¼” nozzles
  • 2× alligator clips
  • 3× adhesive round non-slip feet (up to 16 mm diameter)
  • appx. 60 g steel BB shot (or available equivalent) as ballast
  • hot glue to secure ballast and seal port in place
  • Polycaprolactone (PCL; trade names include InstaMorph) warm-melt granules to secure clips into nozzles
  • (optional) PTFE plumber’s tape.

Note that Modular Hose promotional Loc-Line keyrings each have 3 segments plus a threaded connector and nozzle, so four keyrings provide enough parts.

Assembly

  1. assemble the two Loc-Line arms with a threaded connector and at least six segments each
  2. secure the ends of the alligator clips in the nozzles using softened PCL or hot glue. Make sure that the ball joint connector surface is clear of material, as you’ll need this to fit the nozzle onto the arm
  3. fill the tool body with ballast, apply a plug of hot glue to stop it rattling and secure the end port in place
  4. Carefully thread the arms onto the tool body. NPT threads are tapered, so become gradually tighter as they go in. Use a little plumber’s tape if they’re too loose. Be careful not to overtighten, as this might crack the tool
  5. Apply the non-slip feet, applying appropriate pressure to activate the adhesive
  6. Get soldering!

Acknowledgements

Dan Kirshner’s Thread-drawing modules for OpenSCAD were used to make a nice ¼” NPT taper-profile thread. Thanks, Dan!

Foot and shot port
Side view

Data archive: TRexSolder3rdHand.tar.gz

Categories
photo

Russian baked beans are refined

Russian baked beans are refined

Instagram filter used: Normal

View in Instagram ⇒

Categories
photo

Accessible Gaming buttons are done!

Accessible Gaming buttons are done!

So in an attempt to avoid going completely shack-wacky, I made a bunch of Round Flexure Switches in my free time. I’m donating them to Makers Making Change, the charity I work for.

They are by no means in any form of corporate colour, except perhaps Lisa Frank. The tops are less tactile than I thought they’d be: the top couple of layers are gold PLA and are printed first, then the next layers are bridged above that. They’re almost imperceptible, especially after a thin layer of acrylic varnish.

The bodies are a mix of acrylic paint and ultrafine glitter, layered over with acrylic varnish to limit glitter shedding. The one that looks like a disco tree stump uses heavy gold mica flake medium. The iridescent green is unvarnished, unfinished translucent PET-G (from eSUN; perhaps my favourite material).

From a technical point of view:

  • The button nut is hot-glued in place. This keeps the top straight as a nice side effect.
  • The nuts are held in place with medium (blue) thread-lock. They won’t come apart unless you use appropriate force. Unlike red thread-lock, you will be able to take these apart for repair.
  • Digikey were out of stock on specified parts. These substitutes work directly, though you’ll have to remove a small lever from the microswitch:
Categories
photo

moar switches

moar switches

Instagram filter used: Normal

View in Instagram ⇒

Categories
photo

building switches

building switches

Instagram filter used: Lo-fi

View in Instagram ⇒

Categories
photo

port union, just past dawn

port union, just past dawn

Instagram filter used: Normal

View in Instagram ⇒

Categories
photo

doily

doily

Instagram filter used: Normal

View in Instagram ⇒

Categories
photo

it is eggdog 🥚+ 🐕 eggdog

it is eggdog
🥚+ 🐕
eggdog

Instagram filter used: Lo-fi

View in Instagram ⇒

Categories
photo

a tower crane at that awkward stage

a tower crane at that awkward stage

Instagram filter used: Lo-fi

View in Instagram ⇒

Categories
photo

You could almost type RUN”DISC on it …

You could almost type RUN”DISC on it …

Instagram filter used: Lo-fi

View in Instagram ⇒

Categories
photo

things that fit together in a pleasing manner

things that fit together in a pleasing manner

Instagram filter used: Lo-fi

View in Instagram ⇒

Categories
photo

inversion from burnaby mountain

inversion from burnaby mountain

Instagram filter used: Normal

View in Instagram ⇒

Categories
photo

Congealed accursèd souls, like in Lincoln in the Bardo

Congealed accursèd souls, like in Lincoln in the Bardo

Instagram filter used: Clarendon

View in Instagram ⇒

Categories
photo

a bad case of tentacles

a bad case of tentacles

Instagram filter used: Lo-fi

View in Instagram ⇒