-
-
Notifications
You must be signed in to change notification settings - Fork 37
Description
Hi Brian, first thank you for your work.
I have implemented your Spotify api in order to show current track name and artist on a rgb matrix display (single 64x32 module with esp32 hub75 / Mrfaptastic library ).
Although in principle it works correctly, I can't show the name of the artist with dma_display->print(currentlyPlaying.artists[i].artistName);
I get compiling error with this funtion on RGB matrix display (on serial monitor is just fine)ç
Another help that I would like to ask you, is if it is possible to make the text scroll since there is not space for so much information in a simple panel.
Thanks in advance
`// ----------------------------
// Standard Libraries
// ----------------------------
#if defined(ESP8266)
#include <ESP8266WiFi.h>
#elif defined(ESP32)
#include <WiFi.h>
#endif
#include <Adafruit_GFX.h>
#include <Adafruit_GrayOLED.h>
#include <Adafruit_SPITFT.h>
#include <Adafruit_SPITFT_Macros.h>
#include <gfxfont.h>
#include <Arduino.h>
#include "Fonts/FreeSansBold9pt7b.h"
#include "Fonts/FreeSansBold12pt7b.h"
#include "Fonts/FreeSansBold18pt7b.h"
#include "Fonts/Picopixel.h"
#include "Fonts/FreeSerif9pt7b.h"
#include "Fonts/FreeSerif12pt7b.h"
#include "Fonts/FreeSerif18pt7b.h"
//#include "Fonts/FreeSerif12pt7b.h"
#include <WiFiClientSecure.h>
#include <ESP32-HUB75-MatrixPanel-I2S-DMA.h>
// ----------------------------
// Additional Libraries - each one of these will need to be installed.
// ----------------------------
#include <SpotifyArduino.h>
// Library for connecting to the Spotify API
// Install from Github
// https://github.com/witnessmenow/spotify-api-arduino
// including a "spotify_server_cert" variable
// header is included as part of the SpotifyArduino libary
#include <SpotifyArduinoCert.h>
#include <ArduinoJson.h>
// Library used for parsing Json from the API responses
// Search for "Arduino Json" in the Arduino Library manager
// https://github.com/bblanchon/ArduinoJson
//------- Replace the following! ------
char ssid[] = "MiFibra-XXXX"; // your network SSID (name)
char password[] = "XXXXXXX"; // your network password
char clientId[] = "XXXXXXXXXXXXXXXXXXXXXXXXXXXX"; // Your client ID of your spotify APP
char clientSecret[] = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; // Your client Secret of your spotify APP (Do Not share this!)
// Country code, including this is advisable
#define SPOTIFY_MARKET "IE"
#define SPOTIFY_REFRESH_TOKEN "AQBn5xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx--D4oPfCCMaXZAnQqBcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxaO4"
//------- ---------------------- ------
// -------------------------------------
// ------- Matrix Config ------
// -------------------------------------
const int panelResX = 64; // Number of pixels wide of each INDIVIDUAL panel module.
const int panelResY = 32; // Number of pixels tall of each INDIVIDUAL panel module.
const int panel_chain = 1; // Total number of panels chained one to another
#define ENABLE_DOUBLE_BUFFER 1 // This is a good example to show the difference the //estaba quitado originalmente
// double buffer makes, it doesn't flash as much
// comment this out to test without it
// See the "displaySetup" method for more display config options
//------------------------------------------------------------------------------------------------------------------
MatrixPanel_I2S_DMA *dma_display = nullptr;
WiFiClientSecure secured_client;
uint16_t myBLACK = dma_display->color565(0, 0, 0);
uint16_t myWHITE = dma_display->color565(255, 255, 255);
uint16_t myRED = dma_display->color565(255, 0, 0);
uint16_t myGREEN = dma_display->color565(0, 255, 0);
uint16_t myBLUE = dma_display->color565(0, 0, 255);
uint16_t myPINK = dma_display->color565(227, 28, 121);
uint16_t myYELLOW = dma_display->color565(255, 255, 0);
uint16_t myPURPLE = dma_display->color565(199, 36, 177);
void displaySetup() {
HUB75_I2S_CFG mxconfig(
panelResX, // module width
panelResY, // module height
panel_chain // Chain length
);
#ifdef ENABLE_DOUBLE_BUFFER
// This is how you enable the double buffer.
// Double buffer can help with animation heavy projects
mxconfig.double_buff = false;
#endif
mxconfig.clkphase = false;
dma_display = new MatrixPanel_I2S_DMA(mxconfig);
dma_display->begin();
}
TaskHandle_t Task1;
WiFiClientSecure client;
SpotifyArduino spotify(client, clientId, clientSecret, SPOTIFY_REFRESH_TOKEN);
unsigned long delayBetweenRequests = 6000; // Time between requests (1 minute)
unsigned long requestDueTime; //time when request due
void setup()
{
Serial.begin(115200);
displaySetup();
dma_display->fillScreen(myBLACK);
dma_display->setFont(&FreeSansBold9pt7b);
dma_display->setCursor(0,20);
dma_display->setTextSize(1); // size 2 == 16 pixels high
dma_display->setTextWrap(false); // N.B!! Don't wrap at end of line
dma_display->setTextColor(myWHITE);
#ifdef ENABLE_DOUBLE_BUFFER
dma_display->flipDMABuffer();
#endif
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
Serial.println("");
// Wait for connection
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
// Handle HTTPS Verification
#if defined(ESP8266)
client.setFingerprint(SPOTIFY_FINGERPRINT); // These expire every few months
#elif defined(ESP32)
client.setCACert(spotify_server_cert);
#endif
Serial.println("Refreshing Access Tokens");
if (!spotify.refreshAccessToken())
{
Serial.println("Failed to get access tokens");
}
}
void printCurrentlyPlayingToSerial(CurrentlyPlaying currentlyPlaying)
{
Serial.print("Track: ");
Serial.println(currentlyPlaying.trackName);
dma_display->fillScreen(myBLACK);
dma_display->setCursor(0,20);
dma_display->print(currentlyPlaying.trackName);
Serial.println("Artist: ");
for (int i = 0; i < currentlyPlaying.numArtists; i++)
{
Serial.print("Name: ");
Serial.println(currentlyPlaying.artists[i].artistName);
//Serial.print("Artist URI: ");
//Serial.println(currentlyPlaying.artists[i].artistUri);
Serial.println();
}
}
void loop()
{
#ifdef ENABLE_DOUBLE_BUFFER
dma_display->flipDMABuffer();
#endif
if (millis() > requestDueTime)
{
Serial.println("getting currently playing song:");
// Market can be excluded if you want e.g. spotify.getCurrentlyPlaying()
int status = spotify.getCurrentlyPlaying(printCurrentlyPlayingToSerial, SPOTIFY_MARKET);
if (status == 200)
{
Serial.println("Successfully got currently playing");
}
else if (status == 204)
{
Serial.println("Doesn't seem to be anything playing");
}
else
{
Serial.print("Error: ");
Serial.println(status);
}
requestDueTime = millis() + delayBetweenRequests;
}
}`