pschatzmann / arduino-vs1053

An Arduino library for VS1053, VS1003 Codec Breakout Boards
GNU General Public License v3.0
22 stars 2 forks source link

Now broken on RP2040 -MP3playerDemo #6

Open madias123 opened 1 year ago

madias123 commented 1 year ago

Hello, sadly the library seems to be broken on the RP2040 architecture: While the midi demo works, the mp3 demo plays the sample only one time, the second time a short click and then silence. The serial output works, so there is no freeze. Maybe the MP3playerDemo is broken on other architectures also? Have no ESP32 right here to check it out.

used core: https://github.com/earlephilhower/arduino-pico

working reference: https://github.com/episource/ESP_VS1053_Library

used modul: VS1053B (red breakout board)

I modified the main loop with complete reinitialize the modul: hard reset and spi end/begin, without success: sample played one time, then a short "click" and nothing.

#define VS1053_CS 6
#define VS1053_RST 7
#define VS1053_DCS 8
#define VS1053_DREQ 9

// This ESP_VS1053_Library
#include <VS1053Driver.h>
#include <VS1053SPI.h>
// Please find SampleMp3.h file here:
//   github.com/baldram/ESP_VS1053_Library/blob/master/examples/Mp3PlayerDemo/SampleMp3.h
#include "SampleMp3.h"
#define UNDEFINED -1
#define VOLUME 100  // volume level 0-100
VS1053 player(VS1053_CS, VS1053_DCS, VS1053_DREQ, UNDEFINED, SPI);
void setup() {
  pinMode(VS1053_RST, OUTPUT);
  digitalWrite(VS1053_RST, 0);
  delay(10);
  digitalWrite(VS1053_RST, 1);
  Serial.begin(115200);
  // initialize SPI
  SPI.begin();
  player.begin();
  if (player.getChipVersion() == 4) {  // Only perform an update if we really are using a VS1053, not. eg. VS1003
    player.loadDefaultVs1053Patches();
  }
  player.setVolume(VOLUME);
  player.switchToMp3Mode();
  // player.beginOutput();
  player.setVolume(VOLUME);
}

void loop() {
  Serial.println("Playing sound... ");

  // play mp3 flow each 3s
  player.writeAudio(sampleMp3, sizeof(sampleMp3));

  delay(3000);
  player.stopSong();
  player.end();
  player.hardReset();
  digitalWrite(VS1053_RST, 0);
  delay(10);
  digitalWrite(VS1053_RST, 1);
  SPI.end();
  delay(10);
  SPI.begin();
  delay(10);
  player.begin();
  if (player.getChipVersion() == 4) {  // Only perform an update if we really are using a VS1053, not. eg. VS1003
    player.loadDefaultVs1053Patches();
  }
  player.switchToMp3Mode();
  player.startSong();
  player.setVolume(VOLUME);
  delay(10);
}
poetaster commented 8 months ago

I'm not sure if it's related but on the rp2040 pico (no wifi) I had the driver not intializing consistently with some sketches.

I added (line 122) do VS1053Driver.cpp:

111 bool VS1053::testComm(const char *header) {
112     // Test the communication with the VS1053 module.  The result will be returned.
113     // If DREQ is low, there is problably no VS1053 connected.  Pull the line HIGH
114     // in order to prevent an endless loop waiting for this signal.  The rest of the
115     // software will still work, but readbacks from VS1053 will fail.
116     int i; // Loop control
117     uint16_t r1, r2, cnt = 0;
118     uint16_t delta = 300; // 3 for fast SPI
119     delay(300);
120     VS1053_LOGW("is dreq there?");
121 
122     data_mode_on();

It's a bit odd. I'm using configs with the audio-tools from the same author and used his recommended (?) pins:

#define VS1053_CS     17
#define VS1053_DCS    9
#define VS1053_DREQ   10

These bein the rest

#define VS_XCS    17 // 6 Control Chip Select Pin (for accessing SPI Control/Status registers)
#define VS_XDCS   9 // 7 Data Chip Select / BSYNC Pin
#define VS_DREQ   10 // 9 Data Request Pin: Player asks for more data
#define VS_RESET  11 // 8 Reset is active low

VS1053 player(VS1053_CS, VS1053_DCS, VS1053_DREQ, VS_RESET, SPI);