Hallo zusammen,
ich bastel gerade an meinem ersten größeren Arduino Projekt, mit MP3 Shield herum. Ich habe mir dazu neben einem Arduino UNO (Link) das Adafruit MP3 Shield VS1053 (Link) angeschafft. Es gibt bei diesem Shield grundsätzlich zwei Möglichkeiten einen Song abzuspielen, beide lassen sich über einen Beispiel Sketch aus der Library laden und ausprobieren (Code am Ende):
-
musicPlayer.playFullFile("track001.mp3");
Damit wird eine Datei vollständig abgespielt und während der Wiedergabe ist keine Aktion möglich. -
musicPlayer.startPlayingFile("track001.mp3");
Damit wird eine Datei "im Hintergrund" abgespielt, ich kann z.B. über die Konsole Befehle zum pausieren oder stoppen erteilen.
Ich habe den o.a. Beispiel Sketch (player_simple) geladen und Möglichkeit 1 funktioniert einwandfrei, Möglichkeit 2 nicht, es wird einfach kein Sound wiedergegeben.
Ich hatte zwischenzeitlich ein Poti zur Lautstärkeregelung (Code siehe unten) angeschlossen, sobald ich dieses bewegt habe hat die Wiedergabe kurzfristig gestartet, ist dann aber auch wieder abgebrochen. Ich vermute das es hier in irgendeiner Art und Weise zu Problemen mit dem Interrupt kommt, der ist auf Pin #3 festgelegt.
Ich habe leider kaum Erfahrung und komme hier einfach nicht weiter, vielleicht kann mir ja jemand von Euch helfen. Codefragmente habe ich Euch unten angefügt.
Danke und Viele Grüße,
Michael
Code des Beispiel Sketch:
/***************************************************
This is an example for the Adafruit VS1053 Codec Breakout
Designed specifically to work with the Adafruit VS1053 Codec Breakout
----> https://www.adafruit.com/products/1381
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, all text above must be included in any redistribution
****************************************************/
// include SPI, MP3 and SD libraries
#include <SPI.h>
#include <Adafruit_VS1053.h>
#include <SD.h>
// define the pins used
//#define CLK 13 // SPI Clock, shared with SD card
//#define MISO 12 // Input data, from VS1053/SD card
//#define MOSI 11 // Output data, to VS1053/SD card
// Connect CLK, MISO and MOSI to hardware SPI pins.
// See http://arduino.cc/en/Reference/SPI "Connections"
// These are the pins used for the breakout example
#define BREAKOUT_RESET 9 // VS1053 reset pin (output)
#define BREAKOUT_CS 10 // VS1053 chip select pin (output)
#define BREAKOUT_DCS 8 // VS1053 Data/command select pin (output)
// These are the pins used for the music maker shield
#define SHIELD_RESET -1 // VS1053 reset pin (unused!)
#define SHIELD_CS 7 // VS1053 chip select pin (output)
#define SHIELD_DCS 6 // VS1053 Data/command select pin (output)
// These are common pins between breakout and shield
#define CARDCS 4 // Card chip select pin
// DREQ should be an Int pin, see http://arduino.cc/en/Reference/attachInterrupt
#define DREQ 3 // VS1053 Data request, ideally an Interrupt pin
Adafruit_VS1053_FilePlayer musicPlayer =
// create breakout-example object!
//Adafruit_VS1053_FilePlayer(BREAKOUT_RESET, BREAKOUT_CS, BREAKOUT_DCS, DREQ, CARDCS);
// create shield-example object!
Adafruit_VS1053_FilePlayer(SHIELD_RESET, SHIELD_CS, SHIELD_DCS, DREQ, CARDCS);
void setup() {
Serial.begin(9600);
Serial.println("Adafruit VS1053 Simple Test");
if (! musicPlayer.begin()) { // initialise the music player
Serial.println(F("Couldn't find VS1053, do you have the right pins defined?"));
while (1);
}
Serial.println(F("VS1053 found"));
SD.begin(CARDCS); // initialise the SD card
Serial.println("SD Card done");
// Set volume for left, right channels. lower numbers == louder volume!
musicPlayer.setVolume(30,30);
Serial.println("Volume set");
// Timer interrupts are not suggested, better to use DREQ interrupt!
//musicPlayer.useInterrupt(VS1053_FILEPLAYER_TIMER0_INT); // timer int
// If DREQ is on an interrupt pin (on uno, #2 or #3) we can do background
// audio playing
if (! musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT))
{
Serial.println(F("DREQ pin is not an interrupt pin"));
} // DREQ int
musicPlayer.sineTest(0x44, 200); // Make a tone to indicate VS1053 is working
// Play one file, don't return until complete
Serial.println(F("Playing track 001"));
musicPlayer.playFullFile("track001.mp3");
// Play another file in the background, REQUIRES interrupts!
if (! musicPlayer.startPlayingFile("track001.mp3")) {
Serial.println("Could not open file track001.mp3");
while (1);
}
Serial.println(F("Started playing"));
}
void loop() {
// File is playing in the background
if (musicPlayer.stopped()) {
Serial.println("Done playing music");
while (1);
}
if (Serial.available()) {
char c = Serial.read();
// if we get an 's' on the serial console, stop!
if (c == 's') {
musicPlayer.stopPlaying();
}
// if we get an 'p' on the serial console, pause/unpause!
if (c == 'p') {
if (! musicPlayer.paused()) {
Serial.println("Paused");
musicPlayer.pausePlaying(true);
} else {
Serial.println("Resumed");
musicPlayer.pausePlaying(false);
}
}
}
delay(100);
}
Code den ich zusammen mit dem Poti genutzt habe (basiert auf dem Code hier), die checkVolume Routine wird aus void loop() heraus aufgerufen.
void checkVolume()
{
// read the state of the volume potentiometer
int read = analogRead(volumePin);
// set the range of the volume from max=0 to min=254
// (limit max volume to 20 and min to 60)
byte state = map(read, 0, 1023, 20, 60);
// recognize state (volume) changes in steps of two
if (state < volumeState - 1 || state > volumeState + 1)
{
// remember the new volume state
volumeState = state;
// set volume max=0, min=254
musicPlayer.setVolume(volumeState, 254);
// print out the state of the volume
Serial.print(volumePin);
Serial.print(" volume ");
Serial.println(volumeState);
}
}