My LEGO Minifigures Play Music

Dennis Mellican
codeburst
Published in
6 min readSep 9, 2020

--

Instead of selecting a record, a minifigure is selected for this Jukebox Portal.

Photo credit: Dennis Mellican

The “toys-to-life” LEGO Dimensions console game was discontinued in October 2017. Now you can bring it back to life as a jukebox by connecting the USB toy pad to a Raspberry Pi and running the Open Source “Musicfig” app. Listen to songs, albums, or playlists by placing a LEGO Minifigure on the LEGO Dimensions pad and enjoy the audio and light show!

LEGO Dimensions set transformed into an interactive jukebox music concert stage.

As seen in the video, the LEGO Dimensions base is transformed into a concert stage. The LEGO 40173 Iconic Picture Frame holds a phone with the Spotify app running between scaffolding and spotlights. Finally, two actual speakers are on the pad to appear as a rock concert stage. Jukebox control is not limited to just LEGO Minifigures. Disney Infinity characters, NFC tags, stickers, or cards can be assigned to a song, album, or playlist too.

Musical tags can come in all shapes and forms.

While the light show plays for the duration of the track, on the Musicfig web app, the album art of the current track is displayed. In the demo video, this is shown in full screen on the TV in the background. A web browser screenshot is shown below.

The Musicfig app displays the currently playing track album art from Spotify.

My 7 year old enjoys playing with LEGO and with these toys he can play his favourite songs in the old fashioned tactile way, as it was with cassettes, vinyl and compact disc. Albeit, his choice of music The Chicken Dance and the Ninja Kidz is on constant repeat.

Musicfig is also an attraction with the grown ups, serving as a novelty during visits and gatherings.

Instead of selecting a record or CD, a minifigure is selected for this Jukebox Portal.

The LEGO Dimensions pad lights up, the connected Spotify device plays the track and on a nearby TV, the currently playing track image is displayed.

How it works:

The LEGO minifigures are attached to a LEGO Dimensions disc, which has a NFC tag embedded inside.

Each tag contains a small amount of data (such as 180 bytes for NTAG213 types) including a Unique ID, such as “04 83 1a 62 71 40 80”. This UID is used by the Musicfig app, to uniquely identify a tag and therefore something that tag is attached to, along with the MP3 or Spotify “action” assigned to it. For example, the Ironman minifigure will play Black Sabbath’s Iron Man track.

Since Musicfig leverages the NFC technology in the Lego Dimensions base, most NFC enabled devices or tags can be used, such as the Disney Infinity toy characters.

Tags are defined in a NFC tags configuration file, for example:

NFC tags are assigned actions in the tags.yml file.

The tag identifier can be obtained by initially placing the tag on the LEGO Dimensions base. The Musicfig app will display the unknown tag’s identifier in the logs. Copy this into the tags.yml file along with the relevant name and tag action. Now, take the physical tag off and on again for the app to recognize the new tag and perform the assigned action.

The MP3 action points to the mp3 file to be played.

The Spotify action is obtained from a Spotify client, selecting the track, album or playlist to obtain the “Spotify URI”, as shown below:

How to obtain the Spotify URI for a Playlist or Song.

A Slack action is also available to send messages via a webhook to a Slack channel. In my use case (see the aforementioned tag.yml file example), a tag will trigger a Slack message to a home automation chat bot to toggle the lights on or off. By proxy, the LEGO Dimensions pad also becomes a home automation controller! See the Medium article on “The Traveling Slack Bot Troupe” to extend Musicfig’s capabilities.

You will require:

A LEGO Dimensions base is limited to the PS3, PS4 or Wii gaming consoles. Sorry, Xbox bases are not supported by the Musicfig app.

Any NFC Tag that contains an UID, such as LEGO Dimensions character discs, Disney Infinity characters, NFC NTAG213 tags, stickers or cards.

A Raspberry Pi with Python 3.8 installed to run the Musicfig app.

Optional: A Spotify Premium account is required to leverage the API resources.

Instructions

Prerequisites

Python 3.8. You may need to download and compile this version on the Raspberry Pi.

To install Python 3.8 follow these command line steps:

sudo apt-get -y update
sudo apt-get -y install build-essential tk-dev libncurses5-dev libncursesw5-dev libreadline6-dev libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev libffi-dev libjpeg-dev
wget https://www.python.org/ftp/python/3.8.5/Python-3.8.5.tar.xz
tar xf Python-3.8.5.tar.xz
cd Python-3.8.5
sudo ./configure-enable-optimizations
sudo make -j 4
sudo make altinstall
cd ..
sudo rm -r Python-3.8.5
rm Python-3.8.5.tar.xz
sudo apt-get -y autoremove
sudo apt-get -y clean
cd
python3.8 -m venv venv
. ./venv/bin/activate

Download the Musicfig software:

git clone https://github.com/meltaxa/musicfig.git
cd musicfig

Install dependencies:

./install.sh

Optional. Make the Raspberry Pi a Spotify device:

pip install raspotify

Spotify Setup (optional)

1. Login to the Spotify API developer dashboard:

https://developer.spotify.com/dashboard/

2. Click the CREATE AN APP button. Fill in the App name and description, accept the conditions and click CREATE.

3. Take note of the Client ID and Client Secret. These will be pasted into the config.py file later.

4. Click EDIT SETTINGS. Add a Redirect URI: http://localhost:5000/callback and click SAVE.

Configure the Musicfig app

Edit the config.py file. Replace the Spotify API app credential values:

CLIENT_ID = "<...>"
CLIENT_SECRET = "<...>"

Optional: To add a Slack webhook for tag actions, add this line to the tags.yml file:

slack_hook: <REPLACE_THIS_WITH_THE_WEBHOOK_URL>

Start Musicfig

./run.py

Visit in the browser: http://localhost:5000/

If you configured Spotify, you will be asked to login and connect to Spotify:

Musicfig will flash the lights on the LEGO Dimension pad to indicate it is now ready.

If you are using Spotify, connect to a device to where you want the audio to be streamed.

Place a tag on the pad.

New tags will be identified in the app console logs. Edit the tags.yml file with the identifier and the MP3 file or Spotify URI action that should be assigned to it. No need to restart the app. Now place the tag off and on again.

The track should now be playing.

For Spotify users, the browser app will display the currently playing track’s album art. If nothing is playing, the Musicfig home page is shown:

Hope you enjoy the Musicfig app.

Share your LEGO Dimensions set and musical LEGO minifigure character creations in the comments section.

Thanks for reading, building and playing!

--

--