The qrocodile is a a snappy Raspberry Pi project that makes it easier to control a Sonos multi-room speaker system.

Keen to find a way to enable his young children to quickly and easily search for and play their favourite music tracks on the family’s Sonos sound system, Chris Campbell had a brainwave. “Usually my kids ask me to play certain songs that they already know, and then I have to use the Sonos app on my phone or computer to hunt them down. One night at the dinner table I was lamenting how many steps are involved in using the Sonos apps to search for music or to enable the turnable… That’s when the seed of an idea was planted.”

Initially he thought of creating a simple button that just enabled the vinyl turntable linked to the Sonos, but grander plans soon started to take shape, centred on the use of QR codes.

This Project Showcase was written by Nicola King and first appeared in The MagPi 68.

Project qcrocodile: Scanning for Sonos codes

Printed on cards, the QR codes are read by a mini camera connected to a Raspberry Pi 3, housed in a LEGO crocodile case. “When my software sees a QR code that it understands (for example, a code representing a music library track), it builds up and sends the appropriate request(s) to the Sonos system,” explains Chris. In addition to playing tracks, some of the cards contain commands such as ‘Play music in living room’ or ‘Build a list of songs’. The qrocodile also speaks to you, to tell you what it is doing!

Chris spent around four weeks working on the project in his spare time, ironing out several issues along the way, such as with the QR encoding algorithm. His first implementation simply encoded the full artist, album, and song title metadata in the QR code. “This worked fine for short names/titles, but not so well for songs or albums with really long titles. It hadn’t occurred to me that the more information you cram into a QR code, the tinier those little black and white squares get. And the smaller those squares get, the harder it becomes for the camera to read.”

His solution was to apply a hash function to the metadata, so that only a few characters need to be stored in the QR code in order to identify a song. “After making that change, the QR codes were much less fine-grained and could be read easily by the Raspberry Pi- attached camera.”

So, what do his children think of their dad’s invention? “They love it! My son likes that it allows him to be in control of the playlist for their dance parties. My daughter enjoys being able to play her favourite song Starman over and over.”

No qrocodile tears

So far, no qrocodile-related fights have broken out between the kids. “They picked up on how to use it almost immediately.”

For those who’d like to build one, Chris has supplied full instructions on GitHub.

“My qrocodile is just one incarnation of a concept; I’m interested to see what sort of tweaks and variations other people come up with on their own!”

Still working on perfecting the project, he has plans to add extra commands such as a weather forecast. He’d also like to explore making the qrocodile work with NFC-embedded cards, and creating a smaller version using a Pi Zero W.

Step-01: Croc case

The crocodile-shaped case houses the Raspberry Pi 3, QR code card holder, and mini camera. It’s built from green LEGO bricks belonging to Chris’s son. This was the easiest part of the project.

Step-02: Generate codes

A Python script takes a list of songs (from your local music library and/or Spotify), as well as commands, and generates cards with an icon and text on one side and a QR code on the other.

Step-03: Play the music

Another Python script run on the Raspberry Pi scans the QR code with the camera and acts upon it, using a custom fork of node-sonos-http-api to access the Sonos sound system and play the music.