Hi there. I'm stuck at a to me very surprising spot. I have a mp3 shield running fine, but when i try to use the still (i thought) unused pins on my arduino while using the mp3 shield nothing works. The aim is to use a led strip together with the mp3 shield. But i can't even get a single blinking led working. Any suggestions?
//LED
#include <FastLED.h>
#define LED_PIN 3
#define NUM_LEDS 8
CRGB leds[NUM_LEDS];
/*
VS1053 example
using SparkFun MP3 shield
and Adafruit VS1053 library
in beatiful harmony
A potentiometer controls the volume.
A pushbutton plays/pauses the sound
circuit:
* VS1053 module attached to the pins described below
* Potentiometer attached to pin A0
* Pushbutton on pin 1, connected to ground
note: on the MKR Zero, use the SD card on the MKR rather than
one on the sound player module. To do this, set CARDCS to SDCARD_SS_PIN
created 30 Nov 2018
modified 14 Dec 2018
by Tom Igoe
*/
#include <SPI.h>
#include <SD.h>
#include <Adafruit_VS1053.h>
// the VS1053 chip and SD card are both SPI devices.
// Set their respective pins:
#define VS1053_RESET 8 // VS1053 reset pin
#define VS1053_CS 6 // VS1053 chip select pin
#define VS1053_DCS 7 // VS1053 Data/command select pin
#define CARDCS 9 // SD card chip select pin
#define VS1053_DREQ 2 // VS1053 Data request
// make an instance of the MP3 player library:
Adafruit_VS1053_FilePlayer mp3Player =
Adafruit_VS1053_FilePlayer(VS1053_RESET, VS1053_CS, VS1053_DCS, VS1053_DREQ, CARDCS);
// sound file name must be 8 chars .3 chars:
const char soundFile[] = "SOUND001.mp3";
//const char soundFile[2] = "SOUND002.mp3";
void setup() {
Serial.begin(9600);
// set the pushbutton pin as an input, using internal pullups:
// pinMode(buttonPin, INPUT_PULLUP);
// reset the VS1053 by taking reset low, then high:
pinMode(VS1053_RESET, OUTPUT);
digitalWrite(VS1053_RESET, LOW);
delay(10);
digitalWrite(VS1053_RESET, HIGH);
// initialize the MP3 player:
if (!mp3Player.begin()) {
Serial.println("VS1053 not responding. Check to see if the pin numbers are correct.");
while (true); // stop
}
// initialize the SD card on the module:
if (!SD.begin(CARDCS)) {
Serial.println("SD failed, or not present");
while (true); // stop
}
// Set volume for left and right channels.
// 0 = loudest, 100 = silent:
mp3Player.setVolume(10, 10);
// use the VS1053 interrrupt pin so it can
// let you know when it's ready for commands.
mp3Player.useInterrupt(VS1053_FILEPLAYER_PIN_INT);
// play file:
//mp3Player.startPlayingFile(soundFile);
//Serial.println("playing");
FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
}
void loop() {
leds[1] = CRGB(155, 0, 0);
FastLED.show();
mp3Player.startPlayingFile("SOUND001.mp3");
delay(10100);
leds[1] = CRGB(0, 0, 0);
FastLED.show();
mp3Player.pausePlaying(true);
delay(100);
leds[2] = CRGB(155, 0, 0);
FastLED.show();
mp3Player.startPlayingFile("SOUND002.mp3");
delay(10000);
leds[2] = CRGB(0, 0, 0);
FastLED.show();
mp3Player.pausePlaying(true);
delay(100);
}
Thanks for your respons. I'm using an Arduino UNO r3 and a WS2812B addressable LED strip. And yes. The LED strip works fine while both strip and mp3 shield are connected, but I'm not using the shield. It seems as if all pins are claimed by the code running the shield. Also the pins it doesn't seem to use.
The code you posed uses D3 for the strip. You'll need to change that to something that the shield doesn't use.
Now, an UNO r3 doesn't have much performance or memory which may result in running out of memory. If that happens when allocating the buffer for the strip it will quietly fail and not give you any lights.
Also playing MP3s and updating the strip are both are fairly hard realtime activities which might also cause a problem.
If changing the pin for the strip doesn't improve things you might need to upgrade to a more capcble board. Maybe a Metro M0 Express or M4 Express.
Ok. I also tried the same thing using pin 1, 2 and 10. same thing. i even tried just a single led to try to get anything running next to the mp3 shield. all without success. could that be a memory issue then? Would longer delays between commands be a solution perhaps, or would the only solution be upgrading to another board?
Making delays longer is easy enough to try. I'm doubtful, though.
I'm not that familiar with FastLED, but usually the NeoPixel driver code will take advantage of DMA on the MCUs that have it (the '328 on the UNO doesn't) to do the timing sensitive updates in the background. An SAMD21 (M0) or SAMD51 (M4) based Metro will have that.
To test I only run the adafruit basic example, removed the button function and added a led blink test in de void loop. The assigned pin 1 just gives a static value... Shouldn't be possible to get at least one simple task running on an arduino uno next to the adafruit library?
#include <SPI.h>
#include <SD.h>
#include <Adafruit_VS1053.h>
// the VS1053 chip and SD card are both SPI devices.
// Set their respective pins:
#define VS1053_RESET 6 // VS1053 reset pin
#define VS1053_CS 7 // VS1053 chip select pin
#define VS1053_DCS 4 // VS1053 Data/command select pin
#define CARDCS 3 // SD card chip select pin
#define VS1053_DREQ 5 // VS1053 Data request
// make an instance of the MP3 player library:
Adafruit_VS1053_FilePlayer mp3Player =
Adafruit_VS1053_FilePlayer(VS1053_RESET, VS1053_CS, VS1053_DCS, VS1053_DREQ, CARDCS);
// sound file name must be 8 chars .3 chars:
const char soundFile[] = "SOUND001.mp3";
void setup() {
Serial.begin(9600);
// reset the VS1053 by taking reset low, then high:
pinMode(VS1053_RESET, OUTPUT);
digitalWrite(VS1053_RESET, LOW);
delay(10);
digitalWrite(VS1053_RESET, HIGH);
// initialize the MP3 player:
if (!mp3Player.begin()) {
Serial.println("VS1053 not responding. Check to see if the pin numbers are correct.");
while (true); // stop
}
// initialize the SD card on the module:
if (!SD.begin(CARDCS)) {
Serial.println("SD failed, or not present");
while (true); // stop
}
// Set volume for left and right channels.
// 0 = loudest, 100 = silent:
mp3Player.setVolume(10, 10);
// use the VS1053 interrrupt pin so it can
// let you know when it's ready for commands.
mp3Player.useInterrupt(VS1053_FILEPLAYER_PIN_INT);
// play file:
mp3Player.startPlayingFile(soundFile);
Serial.println("playing");
pinMode(1, OUTPUT);
}
void loop() {
digitalWrite(1, HIGH);
delay(1000);
digitalWrite(1, LOW);
delay(1000);
}
I'm thinking perhaps the issue is more in the use of the library in the loop. Is there a command to play the full mp3 file and then continue in the loop once it has come to an end? mp3Player.startPlayingFile doesn't do exactly that it seems.
digitalWrite(10, HIGH);
mp3Player.startPlayingFile("SOUND001.mp3");
if (mp3Player.stopped()) {
digitalWrite(10, LOW);
}
/*!
* @brief Play the complete file. This function will not return until the
* playback is complete
* @param *trackname File to play
* @return Returns true when file starts playing
*/
boolean playFullFile(const char *trackname);
#include <FastLED.h>
#define LED_PIN 10
#define NUM_LEDS 8
CRGB leds[NUM_LEDS];
#include <SPI.h>
#include <SD.h>
#include <Adafruit_VS1053.h>
// the VS1053 chip and SD card are both SPI devices.
// Set their respective pins:
#define VS1053_RESET 8 // VS1053 reset pin
#define VS1053_CS 6 // VS1053 chip select pin
#define VS1053_DCS 7 // VS1053 Data/command select pin
#define CARDCS 9 // SD card chip select pin
#define VS1053_DREQ 2 // VS1053 Data request
// make an instance of the MP3 player library:
Adafruit_VS1053_FilePlayer mp3Player =
Adafruit_VS1053_FilePlayer(VS1053_RESET, VS1053_CS, VS1053_DCS, VS1053_DREQ, CARDCS);
// sound file name must be 8 chars .3 chars:
const char soundFile[] = "SOUND001.mp3";
//const char soundFile[2] = "SOUND002.mp3";
void setup() {
Serial.begin(9600);
// set the pushbutton pin as an input, using internal pullups:
// pinMode(buttonPin, INPUT_PULLUP);
// reset the VS1053 by taking reset low, then high:
pinMode(VS1053_RESET, OUTPUT);
digitalWrite(VS1053_RESET, LOW);
delay(10);
digitalWrite(VS1053_RESET, HIGH);
// initialize the MP3 player:
if (!mp3Player.begin()) {
Serial.println("VS1053 not responding. Check to see if the pin numbers are correct.");
while (true); // stop
}
// initialize the SD card on the module:
if (!SD.begin(CARDCS)) {
Serial.println("SD failed, or not present");
while (true); // stop
}
// Set volume for left and right channels.
// 0 = loudest, 100 = silent:
mp3Player.setVolume(10, 10);
// use the VS1053 interrrupt pin so it can
// let you know when it's ready for commands.
mp3Player.useInterrupt(VS1053_FILEPLAYER_PIN_INT);
FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
//pinMode(10, OUTPUT);
}
void loop() {
ledAan(0);
mp3Player.playFullFile("SOUND004.mp3");
ledUit(0);
ledAan(1);
mp3Player.playFullFile("SOUND005.mp3");
ledUit(1);
}
void ledAan(int ledNummer){
delay(10);
leds[ledNummer] = CRGB(155, 0, 0);
FastLED.show();
delay(10);
}
void ledUit(int ledNummer){
delay(10);
leds[ledNummer] = CRGB(0, 0, 0);
FastLED.show();
}