How to create a touch button for Spotify
Learn how to create a touch button for Spotify
In this tutorial, we are going to show you how to make a touch button for Spotify with micro:bits and Electric Paint. All you need are two micro:bits, Electric Paint and a macOS computer that is playing Spotify. Have look at our How to create a touch sensor for the microbit with Electric Paint tutorial to create a simple touch button.
For this tutorial, you need to have Node installed, which you can download here. We have used Sam’s Hackster tutorial and Barry’s code as a basis for this tutorial. Thank you for sharing your work with us!
Step 1 Create your touch button
First, paint your touch button with Electric Paint. In this tutorial, we created a “Next” button: when you touch the button, it skips to the next song. Firstly, we painted the universal “Next” symbol. Make sure to paint a line that you can connect to the paint. Leave the paint to dry for about 15 minutes.
Step 2 Prepare your micro:bits
You are going to need two micro:bits. First, upload the code Spotify Touch Button to your first micro:bit. This micro:bit is going to be connected to the Electric Paint and send data to the second micro:bit. Once you have uploaded the code, disconnect the first micro:bit. Then, download the code Spotify Touch Button Receiver to your second micro:bit. This micro:bit is going to receive commands from the first micro:bit and send commands to the computer. You can leave the second micro:bit connected to the computer.
Step 3 Prepare the code for your Mac
On your Mac, open your terminal application and download this repository. Once it has successfully downloaded, install the packages with “npm install”.
Then, back in Terminal, run “ls /dev/tty.*”. This will show you the devices connected to your computer and one of them will be the micro:bit. If you’re not sure which one is the micro:bit, first run the command “ls /dev/tty.*” without the micro:bit attached and then again with the micro:bit attached. The one device that was added to the list is your micro:bit. In our case, it was “/dev/tty.usbmodem14102”
Open the code “spotify_touch_button.js” and have a look at line 5, where it says “/dev/tty.usbmodem14102”. Change this variable with the name of your micro:bit. Save and close the file. Back in Terminal, enter “node spotify_touch_button.js”. If everything went well, it should say “Port open”. Make sure you have Spotify open and that something is playing.
Step 4 Connect your button to the micro:bit
Connect your touch button to the pin 0 of the first micro:bit with a crocodile clip, and then connect the micro:bit to a power source. First press the A button, a number will flash across the screen. Then, press the B button. Now, if you touch the button, it should send a signal to the second micro:bit and the next song should play.