-
1Breadboard Setup
- First, we combined the Pico, DFPlayer, Buttons, OLED, and Speaker by joining them all together according to the wiring diagram.
- We connect the OLED to the Pico by connecting its VCC to VBUS, GND to GND, SDA to GPIO4, and SCL to GPIO5.
- Next, we paired the DFPlayer with the Pico by connecting the VCC of DFPlayer with the VBUS of Pico, GND to GND, the RX of DFPlayer will be connected to GPIO7, which is the TX of PICO, and the TX of DFPlayer will be connected to GPIO8, which is the RX of PICO.
- Speaker's positive is connected with DFPlayer's Speaker 1 port, and negative is connected with Speaker 2 port.
- We utilized a test board created for projects like this one, where we have to put together a setup on a breadboard, and it had a lot of buttons, so we used it for the buttons.
https://www.hackster.io/Arnov_Sharma_makes/joycon-button-and-analog-stick-board-3eed73
- The GND ports on each button are linked to one another and will be connected to PICO's GND. GPIO10 is connected to the Next button, GPIO11 to the Previous button, GPIO12 to the Select button, GPIO13 to GPIO14 to the Volume up and Volume down buttons, respectively.
-
2CODE
Here's the sketch used in this project, and its a simple one.
#include <Wire.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h> #include <SoftwareSerial.h> #include <DFRobotDFPlayerMini.h> #define SCREEN_WIDTH 128 #define SCREEN_HEIGHT 64 //#define OLED_RESET -1 // Reset pin not used #define SSD1306_I2C_ADDRESS 0x3C Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT); // DFPlayer connections SoftwareSerial mySerial(7, 8); // RX, TX DFRobotDFPlayerMini myDFPlayer; // Button pins const int buttonPinNext = 10; // Next song button const int buttonPinPrev = 11; // Previous song button const int buttonPinSelect = 12; // Select song button const int buttonPinVolumeUp = 13; // Volume up button const int buttonPinVolumeDown = 14; // Volume down button // Song data const char* songNames[] = { "Song 1", // Change to actual song names "Song 2", "Song 3", // Add more songs as needed }; const int totalSongs = sizeof(songNames) / sizeof(songNames[0]); int currentSongIndex = 0; // Start with the first song int volume = 10; // Initial volume level (0-30) void setup() { // Initialize Serial and the display Serial.begin(9600); mySerial.begin(9600); display.begin(SSD1306_SWITCHCAPVCC, SSD1306_I2C_ADDRESS); display.clearDisplay(); // Initialize DFPlayer if (!myDFPlayer.begin(mySerial)) { Serial.println("DFPlayer Mini not found"); while (true); } myDFPlayer.volume(volume); // Set initial volume // Set up button pins pinMode(buttonPinNext, INPUT_PULLUP); pinMode(buttonPinPrev, INPUT_PULLUP); pinMode(buttonPinSelect, INPUT_PULLUP); pinMode(buttonPinVolumeUp, INPUT_PULLUP); pinMode(buttonPinVolumeDown, INPUT_PULLUP); // Start playing the first song myDFPlayer.play(currentSongIndex + 1); // DFPlayer uses 1-based indexing } void loop() { // Display song menu display.clearDisplay(); display.setTextSize(1); display.setTextColor(SSD1306_WHITE); display.setCursor(0, 0); display.print("Select Song:"); // Display the list of songs for (int i = 0; i < totalSongs; i++) { if (i == currentSongIndex) { display.setTextColor(SSD1306_BLACK, SSD1306_WHITE); // Highlight current song } else { display.setTextColor(SSD1306_WHITE); } display.setCursor(0, 10 + i * 10); display.print(songNames[i]); } // Display current volume display.setTextColor(SSD1306_WHITE); display.setCursor(0, 50); display.print("Volume: "); display.print(volume); display.display(); // Check for button presses if (digitalRead(buttonPinNext) == LOW) { currentSongIndex = (currentSongIndex + 1) % totalSongs; // Loop back to start delay(100); // Simple debounce } if (digitalRead(buttonPinPrev) == LOW) { currentSongIndex = (currentSongIndex - 1 + totalSongs) % totalSongs; // Loop to end delay(100); // Simple debounce } if (digitalRead(buttonPinSelect) == LOW) { myDFPlayer.play(currentSongIndex + 1); // Play selected song delay(100); // Simple debounce playVisualizer(); } if (digitalRead(buttonPinVolumeUp) == LOW) { if (volume < 30) { // Max volume is 30 volume++; myDFPlayer.volume(volume); // Update volume on DFPlayer displayVolume(); } delay(100); // Simple debounce } if (digitalRead(buttonPinVolumeDown) == LOW) { if (volume > 0) { // Min volume is 0 volume--; myDFPlayer.volume(volume); // Update volume on DFPlayer displayVolume(); } delay(100); // Simple debounce } } // Function to display volume change void displayVolume() { display.clearDisplay(); display.setTextSize(2); display.setTextColor(SSD1306_WHITE); display.setCursor(0, 0); display.print("Volume: "); display.print(volume); display.display(); delay(100); // Show volume for 1 second } // Simple visualizer function void playVisualizer() { // Basic visualization while playing (you can expand this) display.clearDisplay(); display.setTextSize(2); display.setTextColor(SSD1306_WHITE); display.setCursor(0, 0); display.print("Now Playing:"); display.setTextSize(1); display.setCursor(0, 20); display.print(songNames[currentSongIndex]); display.display(); // Visualizer loop (you can customize this) for (int i = 0; i < 20; i++) { display.fillRect(i * 6, 40, 5, random(10, 30), SSD1306_WHITE); display.display(); delay(50); display.fillRect(i * 6, 40, 5, random(10, 30), SSD1306_BLACK); } }
This code implements a basic user interface for an audio player that can navigate through a list of songs, play the selected song, adjust volume, and display basic visualizations during playback.
The OLED display is used for displaying song titles and volume levels, while buttons allow user interaction with the DFPlayer Mini module for controlling music playback.
Make sure you install all the libraries needed for this code, including the ones listed below, before using the sketch.
#include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h> #include <DFRobotDFPlayerMini.h>
Also, you need to change the name of songs to SONG 1, 2, etc., which matches the array in code.
-
3Result
This extremely basic build culminated in a working audio player that can play music that is stored on the SD card. We can select the song we wish to listen to and control the volume with buttons.
Three songs that we added to the SD card, are read by the DFPlayer and output through a 3 Ohms 5W speaker.
The speaker in this instance is being powered straight from the DFPlayer; an audio amplifier can be connected to the output of the DFPlayer if we wish for creating a louder setup.
There is a lot of space for improvement when it comes to the menu. Additionally, we can add a visualizer or other such graphics to be displayed while the song is playing.
Additionally, two more buttons are required so that the user can rewind or fast-forward the song.
But for now, this arrangement seems to be working really nicely.
-
4What's Next? THIS!
We will now be getting ready for building a device like a Walkman, which will be composed of both 3D printed and PCB elements. In order to pair it with the audio player, it will also have a tiny built-in speaker and a 3.5mm Jack output.
Stay tuned for the upcoming update, which will have some graphical modifications, a few tweaks to the menu's user interface, and more buttons.
Overall, this project was a success and needs no further revisions.
Thanks for reaching this far, and I will be back with a new project pretty soon.
Peace.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.