how do i display the song metadata on the oled screen?
I found a library for turning my esp32 into a bluetooth receiver, i have made good progress on it and it is working amazingly. I have added a oled screen to it, and figured out how to make text scroll (song titles can be long, this makes it so the full title and song author can be displayed on the display.)
The code i currently got is:
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "BluetoothA2DPSink.h"
#define SCREEN_WIDTH 128 // OLED display width in pixels
#define SCREEN_HEIGHT 32 // OLED display height in pixels
#define OLED_RESET 4 // Reset pin #
#define SCREEN_ADDRESS 0x3C // 0x3D for 128x64, 0x3C for 128x32 (some x64 models also use 0x3C)
unsigned long minutes = 60000; //60k ms -> 1 minute
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
BluetoothA2DPSink a2dp_sink;
bool is_active = true;
void data_received_callback() {
Serial.println("Data packet received");
}
void avrc_metadata_callback(uint8_t data1, const uint8_t *data2) {
Serial.printf("0x%x, %s\n", data1, data2);
}
char message[] = "X"; //THIS IS WHAT I CAN'T FIGURE OUT
int x, minX;
void setup() {
pinMode(2, OUTPUT);
Serial.begin(9600);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.setTextSize(2);
display.setTextColor(WHITE);
display.setTextWrap(false);
x = display.width();
minX = -12 * strlen(message); // 12 = 6 pixels/character * text size 2
Serial.begin(115200);
i2s_pin_config_t my_pin_config = {
.bck_io_num = 26, //BCK -> IO26
.ws_io_num = 25, //LCK / LRCK -> IO25
.data_out_num = 18, //DIN - > IO18
.data_in_num = I2S_PIN_NO_CHANGE
};
a2dp_sink.set_pin_config(my_pin_config);
a2dp_sink.set_avrc_metadata_callback(avrc_metadata_callback);
a2dp_sink.start("Bluetooth :)");
}
void loop() {
digitalWrite(2, (millis() / 400) % 2);
display.clearDisplay();
display.setCursor(0, 0);
display.setTextSize(1);
display.print("currently playing:"); // top row will say.. x
display.setTextSize(2);
display.setCursor(-x, 10); // (x,10) -> right to left (-x,10) left to right
display.print(message); //scrolling message (song metadata)
display.display();
x = x - 1; // scroll speed, to increase change x=x-2; to x=x-1 // to increase change x=x-1; to x=x-2 for example
if (x < minX) x = display.width();
}
The song metadata shows up properly on the serial monitor,
It shows this ,for example:
0x1, SONG TITLE
0x2, SONG AUTHOR
So i need to bring that data over into:
char message[] = "X";
I have no idea on how to do this, hopefully someone can break my mind loose on how to approach this.
I have tried scrapping everything and starting again just trying to show the metadata on the screen, but i also can't figure that out. Especially trying to show all the text on the screen without scrolling, so the scrolling is a neccesity.
Greets, Arik Nel
-Belgium