MP3 shield together with LED strip

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
ajreijn
 
Posts: 8
Joined: Tue May 03, 2022 7:48 am

MP3 shield together with LED strip

Post by ajreijn »

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?

Code: Select all


//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);

}


User avatar
dastels
 
Posts: 15667
Joined: Tue Oct 20, 2015 3:22 pm

Re: MP3 shield together with LED strip

Post by dastels »

What microcontroller board (by now, "arduino" is a fairly meaningless term) are you using? What led strip?

Does the led strip work without the MP3 shield attached? Does it work with the shield attached but not using the MP3 player?

Dave

User avatar
ajreijn
 
Posts: 8
Joined: Tue May 03, 2022 7:48 am

Re: MP3 shield together with LED strip

Post by ajreijn »

Hi Dave,

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.

Anne-Jan

User avatar
dastels
 
Posts: 15667
Joined: Tue Oct 20, 2015 3:22 pm

Re: MP3 shield together with LED strip

Post by dastels »

It looks like the shield uses these digital pins: 3, 4, 6, 7, 11, 12, and 13.

I assume you are familiar with the shield guide https://learn.adafruit.com/adafruit-mus ... bis-player.

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.

Dave

User avatar
ajreijn
 
Posts: 8
Joined: Tue May 03, 2022 7:48 am

Re: MP3 shield together with LED strip

Post by ajreijn »

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?

User avatar
dastels
 
Posts: 15667
Joined: Tue Oct 20, 2015 3:22 pm

Re: MP3 shield together with LED strip

Post by dastels »

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.

Dave

User avatar
ajreijn
 
Posts: 8
Joined: Tue May 03, 2022 7:48 am

Re: MP3 shield together with LED strip

Post by ajreijn »

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?

Code: Select all




#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);

}


User avatar
dastels
 
Posts: 15667
Joined: Tue Oct 20, 2015 3:22 pm

Re: MP3 shield together with LED strip

Post by dastels »

The UNO is pretty much the most limited and basic MCU board commonly in use: 8-bit, relatively slow, with very little memory.

In this code, the loop is mostly delay calls. That might be interfering with the realtiome streaming of data to the MP3 player.

Dave

User avatar
ajreijn
 
Posts: 8
Joined: Tue May 03, 2022 7:48 am

Re: MP3 shield together with LED strip

Post by ajreijn »

So both code examples posted should work fine on a Metro M0 Express or M4 Express?

User avatar
ajreijn
 
Posts: 8
Joined: Tue May 03, 2022 7:48 am

Re: MP3 shield together with LED strip

Post by ajreijn »

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);
}

mp3Player.startPlayingFile("SOUND002.mp3");

User avatar
dastels
 
Posts: 15667
Joined: Tue Oct 20, 2015 3:22 pm

Re: MP3 shield together with LED strip

Post by dastels »

Code: Select all

  /*!
   * @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);
Dave

User avatar
dastels
 
Posts: 15667
Joined: Tue Oct 20, 2015 3:22 pm

Re: MP3 shield together with LED strip

Post by dastels »

The return value comment is a little misleading. It returns true if it was able to play the file, false if it wasn't.

Dave

User avatar
ajreijn
 
Posts: 8
Joined: Tue May 03, 2022 7:48 am

Re: MP3 shield together with LED strip

Post by ajreijn »

I'm really sorry, but is there some example code on this? I guess I lack the knowledge to fully understand your response.

What command would play the complete file?


p.s. I'm really impressed and thankful for the help/service you've already given me

User avatar
dastels
 
Posts: 15667
Joined: Tue Oct 20, 2015 3:22 pm

Re: MP3 shield together with LED strip

Post by dastels »

If you want to play a file, say "SOUND001.mp3", call

Code: Select all

mp3Player.playFullFile("SOUND001.mp3",);
It won't return until the file has finished playing and teh result will be true. If it returns false, it means the file wasn't played for some reason.

Dave

User avatar
ajreijn
 
Posts: 8
Joined: Tue May 03, 2022 7:48 am

Re: MP3 shield together with LED strip

Post by ajreijn »

Yes that does the trick!! Thank you!!!

Code: Select all


#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();


       
 }


Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”