Better Raspberry Pi audio: the JustBoom DAC HAT

I decided that the sound output from the Pi’s built-in headphone jack wasn’t sufficient after all and so went searching for better options (a DAC—digital-to-analog converter).

The Raspberry Pi foundation created a specification called “HAT” (Hardware Attached on Top) a few years ago which specifies a standard way for devices to automatically identify and configure a device and drivers that’s attached to the Pi via its GPIO (General Purpose Input/Output) pins. There’s a number of DACs now that conform to this standard, and the one I settled on is the JustBoom DAC HAT. It’s a UK company but you can buy them locally from Logicware (with $5 overnight shipping no less).

The setup is incredibly simple: connect the plastic mounting plugs and attach the DAC to the Pi, then start it up and edit /boot/config.txt to comment out the default audio setting:

#dtparam=audio=on

Then add three new lines in:

dtparam=audio=off
dtoverlay=i2s-mmap
dtoverlay=justboom-dac

Then reboot. (If you’re running Raspbian Stretch or newer, the i2s-mmap line should not be added).

To say that I’m impressed would be an understatement! I didn’t realise just how crappy the audio from the Pi’s built-in headphone jack was until I’d hooked up the new DAC and blasted some music out. I’m not an audiophile and it’s hard to articulate, but I’d compare it most closely to listening to really low-quality MP3s on cheap earbuds versus high-quality MP3s on a proper set of headphones.

If you’re going to be hooking your Pi into a good stereo system, I can’t recommend JustBoom’s DAC HAT enough!

Raspberry Pi project: AirPlay receiver

I bought a Raspberry Pi almost exactly a year ago, intending on eventually replacing my Ninja Block and its sometimes-unreliable wireless sensors with hardwired ones (apart from the batteries needing occasional changing, there’s something that interferes with the signal on occasion and I just stop receiving updates from the sensor outside for several hours at a time, and then suddenly it starts working again). To do that, I need to physically run a cable from outside under the pergola to inside where the Raspberry Pi will live and I don’t really want to go drilling holes through the house willy-nilly. I want to eventually get the electrician in to do some recabling so I’m going to get him to do that as well, but until then the Pi was just sitting there collecting dust. I figured I should find something useful to do it with, but having a Linode meant that any sort of generic “Have a Linux box handy to run some sort of server on” itch was already well-scratched.

I did a bit of Googling, and discovered Shairport Sync! It lets you use the Raspberry Pi as an AirPlay receiver to stream music to from iTunes or iOS devices, a la an Apple TV or AirPort Express. We already have an Apple TV but it’s plugged into the HDMI port on the Xbox One which means that to simply stream audio to the stereo we have to have the Xbox One, TV, and Apple TV all turned on (the Apple TV is plugged into the Xbox’s HDMI input so we can say “Xbox, on” and the Xbox turns itself on as well as the TV and amplifier, then “Xbox, watch TV” and it goes to the Apple TV; it works very nicely but is a bit of overkill when all you want to do is listen to music in the lounge room).

Installing Shairport Sync was quite straightforward, I pretty much just followed the instructions in the readme there then connected a 3.5mm to RCA cable from the headphone jack on the Raspberry Pi to the RCA input on the stereo. It’s mentioned in the readme, but this issue contains details on how to use a newer audio driver for the Pi that significantly improves the audio output quality.

The only stumbling block I ran into was the audio output being extremely quiet. Configuring audio in Linux is still an awful mess, but after a whole lot of googling I discovered the “aslamixer” tool (thanks to this blog post), which gives a “graphical” interface for setting the sound volume, and it turned out the output volume was only at 40%! I cranked it up to 100% and while it’s still a bit quieter than what the Apple TV outputs, it doesn’t need a large bump on the volume dial to fix—there’s apparently no amplifier or anything on the Raspberry Pi, it’s straight line-level output. The quality isn’t quite as good as going via the Apple TV, but it gets the job done! I might eventually get a USB DAC or amplifier but this works fine for the time being.

On macOS it’s possible to set the system audio output to an AirPlay device, so you can be watching a video but outputting the audio to AirPlay, and the system keeps the video and audio properly in sync. It works extremely well, but the problem we found with having the Apple TV hooked up to the Xbox One’s HDMI input is that there’s a small amount of lag from the connection. When the audio and video are both coming from the Apple TV there’s no problem, but watching video on a laptop while outputting the sound to the Apple TV meant that the audio was just slightly out of sync from the video. Having the Raspberry Pi as the AirPlay receiver solves that problem too!

UPDATE: Two further additions to this post. Firstly, and most importantly, make sure you have a 5-volt, 2.5-amp power supply for the Raspberry Pi. I’ve been running it off a spare iPhone charger which is 5V but only 1A, and the Pi will randomly reboot under load because it can’t draw enough power from the power supply.

Secondly, the volume changes done with the “alsamixer” tool are not saved between reboots. Once you’ve set the volume to your preferred level, you need to run “sudo alsactl store” to persist it (this was actually mentioned in the blog post I linked to above, but I managed to miss it).

New job!

No, I haven’t left Atlassian, but come Monday I’m starting in a new role!

We have the concept of a role called a “Shield” that’s essentially support but for helping our own internal developers and users (as opposed to external customers), and the idea is that it’s the first point of contact for developers who need help or have questions about the particular service/platform/whatever that the Shield is supporting, as well as being able to step back and look at the bigger picture in terms of pain points that those developers run into and what sort of things could be done to minimise that. The name “shield” comes from the fact that you’re essentially shielding the rest of the developers on the team from the distractions that come from other people constantly contacting them throughout the day, and letting them get on with what they do best (actual coding and improvements to the product). I’ll also have the opportunity to actually do some coding and make improvements too, though. \o/

The team I’m joining runs our internal microservices platform that an increasing number of our applications are being run on, and though the microservices themselves can be pretty much any language you’d like (it’s all Docker-based), the code that the platform itself runs on is Node.js which ties in rather nicely with all my learning over it over the past almost eighteen months.

I’ve been doing external customer-facing support for over thirteen and a half years so this is going to be a lovely change! It’s going to be really weird starting anew where I know next to nothing about the inner workings of the thing I’m supporting though. 😛 I expect my brain is going to be dribbling out my ears come the end of next week.

Back to Tasmania

We went back to Tasmania again last week, and it was pretty great!

Where last time we stayed in Hobart for the whole trip, this time we drove up to Bicheno first, which is about a two and a half hour drive north of Hobart. The accomodation itself (the “Diamond Island Retreat”) was not great, the house was built in probably the 1970s and had clearly had next to nothing done with it since. The kitchen was terrible and the two frying pans were both quite burnt and scratched up, and there was zero internet access (at least in terms of wifi, thankfully there was plenty of 4G reception). It was completely clean and tidy, at least.

That being said, the location was amazing. This was the view from the back deck –

Diamond Island

You could walk down the paddock and down to the beach, which had some of the whitest sand I’ve seen. The first sunset was pretty epic as well.

Sunset

Reflections

Walking

More patterns

They do “penguin tours” right near where we were staying, there’s a whole section of land that’s restricted to the public and they get lots of penguins living and breeding there. We went during the decidedly off-season and so only saw a couple of penguins, but one of them waddled its way up the beach and right past us to its burrow! The other penguins we could only see in the distance down on the rocks near the beach. The tours are done after the sun has set and the guides have special torches that emit really yellow light so as not to hurt the penguins’ eyes. During the breeding season you can apparently see upwards of a hundred penguins all coming ashore to feed their chicks.

There’s a few other things to do around Bicheno as well, one is Freycinet National Park which has some epic hiking trails through it (neither Kristina nor I are hikers so we opted to just go by what we could reach by car).

Untitled

Untitled

Cape Tourville Lighthouse

Then right up the road from where we were staying is Douglas-Apsley National Park, which is the same deal as Freycinet with the hiking, and requires a good couple of kilometres of dirt road to get to the carpark.

Untitled

Untitled

Untitled

Untitled

Untitled

(There’s a few more photos from each in the photoset).

The last bit of Bicheno we saw was East Coast Natureworld, a big wildlife sanctuary and conservation area.

Esther the wombat

Emu

Lazing

Ostrich

Don’t ask me why there was an ostrich there, I don’t know. 😛 The baby wombat at the top is named Esther, and she was just sitting there in the keeper’s arms dozing while the keeper was talking. They also do conservation and breeding for Tasmanian devils there, and we got to see one of them being fed which was pretty neat!

Feeding Dennis the Tasmanian Devil

Nom nom nom

After that, we drove back down to Hobart and spent the rest of the trip just wandering around some more.

The side path

190

Up the hill

Mirror selfie

Lit from below

Aurora Australis

Grafitti

Happy doggo grafitti

Under construction

Docked

The huge orange ship is an icebreaker

Aurora Australis is an Australian icebreaker. Built by Carrington Slipways and launched in 1989, the vessel is owned by P&O Maritime Services, but is regularly chartered by the Australian Antarctic Division (AAD) for research cruises in Antarctic waters and to support Australian bases in Antarctica.

And it’s quite an impressive sight in person!

We also went up to Mount Nelson, which is the next-highest mountain in Hobart, but unfortunately they were doing hazard-reduction burns (basically controlled bushfires) so it was really smokey and you mostly couldn’t see anything. 🙁

Despite that, all in all it was an excellent trip.

iPhoneography

Both Kristina and I upgraded to the iPhone 7 last month, I’d heard the camera was good but I took it out for a spin last week when I went on a lunchtime photo walk with some co-workers, and man. I can see why the point-and-shoot market is dying! I processed all these photos in Lightroom on my iMac so it wasn’t solely done on the iPhone, but even so, I’m incredibly impressed.

It’s not going to replace a full DSLR setup in low-light or shallow depth-of-field situations, but where I’d be wandering around during the day taking photos at f/8 anyway…

Untitled

Untitled

Untitled

Untitled

Untitled

Untitled

Untitled

Untitled

Untitled

A year of Node.js

Today marks one year exactly since switching my website from Perl to Javascript/Node.js! I posted back in March about having made the switch, but at that point my “production” website was still running on Perl. I switched over full-time to Node.js shortly after that post.

From the very first commit to the latest one:

$ git diff --stat 030430d 6b7c737
[...]
177 files changed, 11313 insertions(+), 2110 deletions(-)

Looking back on it, I’ve learnt a hell of a lot in that one single year! I have—

  • Written a HipChat add-on that hooks into my Ninja Block data (note the temperature in the right-hand column as well as the slash-commands; the button in the right-hand column can be clicked on to view the indoor and outdoor temperatures and the extremes for the day)
  • Refactored almost all of the code into a significantly more functional style, which has the bonus of making it a hell of a lot easier to read
  • Moved from callbacks to Promises, which also massively simplified things (see the progression of part of my Flickr– and HipChat-related code)
  • Completely overhauled my database schema to accomodate the day I eventually replace my Ninja Block with my Raspberry Pi (the Ninja Block is still running though, so I needed to have a “translation layer” to take the data in the format that the Ninja Block sends and converts it to what can be inserted in the new database structure)
  • Added secure, signed, HTTP-only cookies when changing site settings
  • Included functionality to replace my old Twitter image hosting script, and also added a nice front-end to it to browse through old images

Along with all that, I’ve been reading a lot of software engineering books, which have helped a great deal with the refactoring I mentioned above (there was a lot of “Oh god, this code is actually quite awful” after going through with a fresh eye having read some of these books)—Clean Code by Robert C. Martin, Code Complete by Steve McConnell, The Art of Readable Code by Dustin Boswell and Trevor Foucher.

I have a nice backlog in JIRA of new things I want to do in future, so I’m very interested to revisit this in another year and see what’s changed!

Farewell Dreamhost

After 12 years of service, I’m shutting my Dreamhost account down (for those unaware, Dreamhost is a website and email hosting service).

My very first—extremely shitty—websites were hosted on whichever ISP we happened to be using at the time—Spin.net.au, Ozemail, Optus—with an extremely professional-looking URL along the lines of domain.com.au/~username. I registered virtualwolf.org at some point around 2001-2002 and had it hosted for free on a friend’s server for a few years, but in 2005 he shut it down so I had to go find some proper hosting, and that hosting was Dreamhost.

The biggest thing I found useful as I was dabbling in programming was that Dreamhost offered PHP and MySQL, so I was able to create dynamic sites rather than just static HTML. Of course, looking back at the code now is horrifying, especially the amount of SQL injection vulnerabilities I had peppered my sites with.

Around the start of 2011, I started using source control—Subversion initially—and finally had a proper historical record of my code. I used PHP for the first year or so of it, then ended up outgrowing that and switched to a Perl web framework called Mojolicious. The only option to run a long-lived process on Dreamhost is to use Fast-CGI, which I never managed to get working with Mojolicious, but fortunately Mojolicious could also run as a regular CGI script so I was still able to use it with Dreamhost, albeit not at great speed.

At the same time I started using Subversion, I also signed up with Linode who offer an entire Linux virtual machine with which you can do almost anything you’d like as you have full root access. I originally used it mostly to run JIRA so I could keep track of what I wanted to do with my website and have the nifty Subversion/JIRA integration working to see my commits against each JIRA issue. I slowly started using the Linode for more and more things (and switched to Git instead of Subversion as well), until in 2014 I moved my entire website hosting over to the Linode.

At that point the only thing I was using Dreamhost for was hosting Kristina’s website and WordPress blog, and the email for our respective domains. Dreamhost’s email hosting wasn’t always the most reliable and towards the end of 2015 they had more than their usual share of problems, so we started looking for alternatives. Kristina ended up moving to Gmail and I went with FastMail (who I am extremely happy with and would very highly recommend!), I moved her blog and my previously-LiveJournal-but-now-Wordpress-blog over to the Linode, and that was that!

Moving my website hosting to the Linode also allowed me to move over to Node.js and I’ve been going full steam ahead ever since. Since that posted I’ve moved over from callbacks to Promises (so much nicer), I wrote myself a HipChat add-on to keep an eye on the temperature that my Ninja Block is reporting, and I moved my dodgy Twitter image upload Perl script functionality into my site and added a nice front-end to it. Even looking back at my code from 6 months ago to now shows a marked increase in quality and readability.

So in summary, thanks for everything Dreamhost, but I outgrew you. 🙂