Need help with VS1053B and a PICO

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Post Reply
User avatar
KaeFenn
 
Posts: 5
Joined: Sun Feb 02, 2025 6:41 pm

Need help with VS1053B and a PICO

Post by KaeFenn »

Greetings,
I have been trying for days, is there any way to get a VS1053B to talk to a PICO?

The sineTest function does not seem to do anything.

Code: Select all

#include <SPI.h>
#include <Adafruit_VS1053.h>
#include <SD.h>

#define CLK 18 // SPI Clock, shared with SD card
#define MISO 16 // Input data, from VS1053/SD card
#define MOSI 19 // Output data, to VS1053/SD card
#define RST 20 // VS1053 reset pin (output)
#define CS 17 // VS1053 chip select pin (output)
#define XDCS 14 // VS1053 Data/command select pin (output)
#define SDCS 15 // Card chip select pin
#define DREQ 5 // VS1053 Data request, ideally an Interrupt pin
Adafruit_VS1053_FilePlayer mp3 = Adafruit_VS1053_FilePlayer(MOSI, MISO, CLK, RST, CS, XDCS, DREQ, SDCS);

void setup() {
  Serial.begin(9600);
  while (!Serial) {
    delay(1);
  }

  Serial.println("Adafruit VS1053 Library Test");
  if (mp3.begin()) Serial.println("VS1053 found");

  mp3.sineTest(0x44, 1500); // does nothing?
 
  if (SD.begin(SDCS)) Serial.println("SD OK!");
  printDirectory(SD.open("/"), 0);

  /***** Two interrupt options! *******/ 
  // This option uses timer0, this means timer1 & t2 are not required
  // (so you can use 'em for Servos, etc) BUT millis() can lose time
  // since we're hitchhiking on top of the millis() tracker
  //musicPlayer.useInterrupt(VS1053_FILEPLAYER_TIMER0_INT);
  
  // This option uses a pin interrupt. No timers required! But DREQ
  // must be on an interrupt pin. For Uno/Duemilanove/Diecimilla
  // that's Digital #2 or #3
  // See http://arduino.cc/en/Reference/attachInterrupt for other pins
  // *** This method is preferred
  
  // digitalPinToInterrupt(5)
  // digitalPinToInterrupt(DREQ)
  // 5
  if (! mp3.useInterrupt(VS1053_FILEPLAYER_PIN_INT)) Serial.println("DREQ pin is not an interrupt pin");
  mp3.setVolume(1,100);
}

void loop() {
  // Sync
  Serial.println("Trying file 1");
  if(! mp3.playFullFile("/test.mp3")) {
    Serial.println("Could not open file 1");
    while (1);
  }

  // Async
  Serial.println("Trying file 2");
  if (! mp3.startPlayingFile("/test.wav")) {
    Serial.println("Could not open file 2");
    while (1);
  }
  Serial.println("Started playing");
  while (mp3.playingMusic) {
    Serial.print(".");
    delay(1000);
  }
  Serial.println("Done playing music");
}

void printDirectory(File dir, int numTabs) {
   while(true) {
     
     File entry =  dir.openNextFile();
     if (! entry) break;
     for (uint8_t i = 0; i < numTabs; i++) {
       Serial.print('\t');
     }
     Serial.print(entry.name());
     if (entry.isDirectory()) {
       Serial.println("/");
       printDirectory(entry, numTabs+1);
     } else {
       Serial.print("\t\t");
       Serial.println(entry.size(), DEC);
     }
     entry.close();
   }
}

adafruit_1.png
adafruit_1.png (582.73 KiB) Viewed 41 times
adafruit_2.png
adafruit_2.png (585.7 KiB) Viewed 41 times

I get:
VS1053 Found
SD OK!
<list of files>
Trying file 1

and then it freezes and wont take an upload or serial port connection.

I have tested the headphones as working and made sure the jack is seated fully, resistance at the connector is 37ohms.

SD card is 32gb sandisk, formatted using FormatUSB.com utility, a fork of Rufus using FAT32 with 16k cluster.

This is my first post. Any help is appreciated!
Thanks!

User avatar
adafruit_support_carter
 
Posts: 31635
Joined: Tue Nov 29, 2016 2:45 pm

Re: Need help with VS1053B and a PICO

Post by adafruit_support_carter »

Does the file test.mp3 show in the file listing as expected?

User avatar
KaeFenn
 
Posts: 5
Joined: Sun Feb 02, 2025 6:41 pm

Re: Need help with VS1053B and a PICO

Post by KaeFenn »

Yup! I have test.mp3, test.ogg and test.wav just to make sure its not a format issue. My hunch is that DREQ is part of the issue somehow.

I did get sineTest to work! It turns out the headphone connector does not work with pins 2,3,4 connected, it only works with pins 1,3,5!

But music still is not playing. Im going to keep messing with the format utility as file read is the breaking part. Going to try FAT16 next.

Thanks!

User avatar
KaeFenn
 
Posts: 5
Joined: Sun Feb 02, 2025 6:41 pm

Re: Need help with VS1053B and a PICO

Post by KaeFenn »

Still no luck. Tried multiple formatting programs including windows at 2GB FAT16 and the one from the SD foundation themselves.

I also ran the Example -> SD -> Dumpfile sketch and that worked and read the txt file correctly.
Double checked that all 3 file types play off the SD card in Windows too.

So everything is working except the ability to play music.

The VS1053B tutorial is for OG Arduino like the UNO which have a "dedicated interrupt" pin. I do not see a way to setup a DREQ interrupt on the PICO because attachInterrupt() requires a function to be passed to attach to the pin.

Would it be possible to reproduce the issue on your side?
Thanks

User avatar
KaeFenn
 
Posts: 5
Joined: Sun Feb 02, 2025 6:41 pm

Re: Need help with VS1053B and a PICO

Post by KaeFenn »

Finally found it, after 3 days.

Code: Select all

// Use This
Adafruit_VS1053_FilePlayer mp3 = Adafruit_VS1053_FilePlayer(RST, CS, XDCS, DREQ, SDCS);

// NOT THIS
Adafruit_VS1053_FilePlayer mp3 = Adafruit_VS1053_FilePlayer(MOSI, MISO, CLK, RST, CS, XDCS, DREQ, SDCS);
Following the tooltips leads to problems.

You will still need to uncomment out these to use custom pins:

Code: Select all

#define CLK 18 // SPI Clock, shared with SD card
#define MISO 16 // Input data, from VS1053/SD card
#define MOSI 19 // Output data, to VS1053/SD card
#define RST 20 // VS1053 reset pin (output)
#define CS 17 // VS1053 chip select pin (output)
#define XDCS 14 // VS1053 Data/command select pin (output)
#define SDCS 15 // Card chip select pin
#define DREQ 5 // VS1053 Data request, ideally an Interrupt pin
Somehow magically your pins will be found by the includes and use them even though they do not appear elsewhere in your code.

Hope this helps someone.

User avatar
adafruit_support_carter
 
Posts: 31635
Joined: Tue Nov 29, 2016 2:45 pm

Re: Need help with VS1053B and a PICO

Post by adafruit_support_carter »

It should nominally work with either constructor. What you did switched from software SPI to hardware SPI. Hardware SPI is generally preferred when available. So fine to just stick with that.

The actual pins used for hardware SPI would depend on the Arduino Board Support Package.

The other pins (RST, CS, XDCS, DREQ, SDCS) are any available GPIO pins, but software must be changed to match the ones being used.

Glad you got it working!

User avatar
KaeFenn
 
Posts: 5
Joined: Sun Feb 02, 2025 6:41 pm

Re: Need help with VS1053B and a PICO

Post by KaeFenn »

Ya, it definitely breaks when using the extra #defines in the adafruit function call.

Additionally, commenting out MISO/MOSI/CLK does not break the program.

Turns out the PICO has a bunch of pre-defined SPI pins that are not mentioned in any tutorials I have come across.
After doing some searching, you can only use certain pins. They are:
MISO(GP0, GP4, GP16)
MOSI(GP3, GP7, GP19)
CLK (GP2, GP6, GP18)
CS (GP1, GP5, GP17)

So using pins 16-19 just happened to be correct.

Here is more info about how the pins work.
https://randomnerdtutorials.com/raspber ... gpios/#spi

Hope this helps

Post Reply
Please be positive and constructive with your questions and comments.

Return to “General Project help”