I listen to music.... a lot, more specifically via Spotify Premium's streaming services. As a result I wanted to see if I could create a device that would visualize a data quantity of whatever song I was listening too. I settled on making a disco ball that spins atop a micro-servo motor if a song I select has a *popularity level above a 65 ranking.
The HardwareThe micro-servo SG90 is a tiny device that has the ability to rotate on an axis of 180 degrees. It comes equipped with "arms" that need to be screwed in place on top of the servo motor (its thankfully easy to do). Consequently, I found it perfect to use as the axis my disco ball would spin on.
The circuit set up for the servo is relatively simple as there are only three required pins to get it up and running- The Positive pin, the Ground pin, and the digital pin. *The pins come preinstalled on the servo (input end)* In the image above you can see that I plugged the positive pin/RED jumper wire to the vusb port on the argon for 5V power (the servo will not work with a voltage less than 1). Then the ground pin/BROWN jumper wire to the ground port. And lastly, the digital pin into the D7 digital port.
For this project I used thebuild.particle IDE. It offers a programming interface, as well as a streamline event/console window. The key feature it has for this task however is its "Integrations" tool. With Integrations you can create webhooks to call and receive your desired data from API's.
On the Spotify end, I took advantage of "Spotify for Developers, " Spotify's open source web API (https://developer.spotify.com/). After creating an account you have access to all their available functionalities.
Because I wanted to get information on an artists album/tracks I directed my attention to the Album API reference page.
To elaborate on whats shown in the above image, the Spotify API requires an authorization token, the ID of the album you need, and the market (in this case not necessary) to receive an album. There are also some other general requirements (I say general because most other APIs need these things).
The sequence after the "album/" is the ID of the song and/or album that's currently playing. I found it easier to get the ID from the browser player instead of the installed app (Click on the three dots next to a song and click on share to find the ID).
Here's how all the information looks put together in the webhook on particle.(below)
- The URL includes the correct endpoint with the song ID included
- The request type is GET (as listed by spotify) because we're trying to receive data
- nodefaults and reject unauthorized set to true because we need specific data and authorization
- Response Template is something I included after I received my json object (the data format that sent back to you) which allowed me to get the specific data I wanted, popularity. Using *mustache brackets* I was able to single out popularity.
- The headers are where the json data is accepted as well as where you copy and paste you authorization token(located after bearer)
Here are the materials I used to make my mini disco ball!
.... as well as a glue stick and some tape.
*Code Explanation below*
If I were to do it again, what would I change?-There were errors with my servo so I'd definitely refine that
- Get the project working in real time
SEE IT IN ACTION
Comments
Please log in or sign up to comment.