Marco Garcia
Published

Lane Tech HS PCL- Spotify API Data Visualization w/ Particle

Proof of Concept project that allows you to visually see what the popularity of a song is on spotify's metrics.

IntermediateFull instructions provided214
Lane Tech HS PCL- Spotify API Data Visualization w/ Particle

Things used in this project

Hardware components

Argon
Particle Argon
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE
Spotify API

Story

Read more

Schematics

Simple Schematics

Code

Program Code

C/C++
-Go to the libraries tab and search for "ArduinoJson" and integrate into the code for the program to work
- Servo myservo; is needed to control the servo
-Particle.subscribe is mandatory in order for the data to publish in the events page
-Serial.begin publishes to a serial monitor if you choose to monitor your data that way
-String data in the loop is required by particle for the integration to work
// This #include statement was automatically added by the Particle IDE.
#include <ArduinoJson.h>

// The number below has to be updated to the correct doc size
// Use the official ArduinoJSON Assistant below:
// https://arduinojson.org/v6/assistant/
StaticJsonDocument<200> doc;
Servo myservo;  // create servo object to control a servo
                
int pos = 0;    // variable to store the servo position


void setup()
{
    // Subscribe to the webhook response event
    Particle.subscribe("hook-response/Spotify Entries", myHandler, MY_DEVICES);
    Serial.begin(9600);
    
    myservo.attach(D7);  // attaches the servo on the D0 pin to the servo object
  // Only supported on pins that have PWM
}

void loop()
{
    // Get some data
  String data = String(10);
  // Trigger the integration
  Particle.publish("Spotify Entries", data, PRIVATE);
  // Wait 60 seconds
  delay(5000);
}

void myHandler(const char *event, const char *data)
{
   float popularity = atof(data); //easily accesses the data you need
   Serial.println(popularity);

if(popularity > 65)
{

   for(pos = 0; pos < 180; pos += 1)  // goes from 0 degrees to 180 degrees
  {                                  // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for(pos = 180; pos>=1; pos-=1)     // goes from 180 degrees to 0 degrees
  {
   myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
}
}

Credits

Marco Garcia
2 projects • 1 follower
Contact

Comments

Please log in or sign up to comment.