Reading from SD card while having a song played in the backg

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
eranbenjamin
 
Posts: 11
Joined: Wed Mar 10, 2021 2:03 pm

Reading from SD card while having a song played in the backg

Post by eranbenjamin »

Hi,
I am using the Adafruit Music Maker with the Arduino Mega2560 - I would like to read a binary file while the music (mp3 file) is played in the background.
My code is based on the Adafruit player_simple - after start playing a song in the background I am opening the binary file for reading. Thereafter I hear white noise in my earphone instead of the song.
I guess I have a race in approaching the SD card, is it!?
Any idea how can I overcome this issue?
Thanks!

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: Reading from SD card while having a song played in the b

Post by mikeysklar »

@eranbenjamin,

Are you using a single SD library for the playback and writing or are there two different libraries involved? In player_simple.ino we are using SD.h are you including any other SD related libraries? Just looking for conflicts there.

What kind of SD card are you using? One thought I have is that access speed could be an issue and would be a simple solution. There are various Speed Classes typically labled on the SD card with a 3/4 circle around them that look like this. Ideally yours would be a 10 for 10MB/s performance or higher with the other UHS and Video marks.
7E4DA479-A341-4D74-8A4A-1F3B6BCEF902.jpeg
7E4DA479-A341-4D74-8A4A-1F3B6BCEF902.jpeg (658.47 KiB) Viewed 480 times
https://www.sdcard.org/developers/sd-st ... eed-class/

User avatar
eranbenjamin
 
Posts: 11
Joined: Wed Mar 10, 2021 2:03 pm

Re: Reading from SD card while having a song played in the b

Post by eranbenjamin »

Thanks for your support @mikeysklar!

1. The SD card is https://www.amazon.com/gp/product/B000S ... UTF8&psc=1 (Amazon's title: "Sandisk 4GB MicroSDHC Memory Card with SD Adapter"). It has the sign "HC" on one hand, but on the other hand it has the number #3 sign. So I am not sure where this 'creature' falls in the table you included in your response, let alone the speed.

2. as for your second question - I am using the following libraries (i.e. there is no conflicting libraries as far as I can tell):

Code: Select all

// include SPI, MP3 and SD libraries
#include <SPI.h>
#include <Adafruit_VS1053.h>
#include <SD.h>
#ifdef __AVR__
#include <avr/power.h>   //Includes the library for power reduction registers if your chip supports them. 
#endif                   //More info: http://www.nongnu.org/avr-libc/user-manual/group__avr__power.htlm

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: Reading from SD card while having a song played in the b

Post by mikeysklar »

Thank you for the confirmation about the libraries being included. You are right there does not appear to be any conflict there.

I suspect you card is slow Class 2 based on the link you provided and the customer questions and seller answers. I'd upgrade the card first to a class 10 or better.

User avatar
eranbenjamin
 
Posts: 11
Joined: Wed Mar 10, 2021 2:03 pm

Re: Reading from SD card while having a song played in the b

Post by eranbenjamin »

Hi,
I just tested my SD card in accordance with the tool posted in this web page: https://android.stackexchange.com/quest ... ro-sd-card.
The tool can be found here: http://www.heise.de/ct/Redaktion/bo/dow ... tw_1.4.zip

My SD card which carries the symbol #3 works in accordance to the table you presented which shows that this kind of SD cards has a speed of, at least, 30MB/sec. I tested the speed of 1GB writing and it showed a speed ~60MB/sec.
Therefore I believe the problem I experience is not related to the speed of the read from the SD card.

Any other ideas?

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: Reading from SD card while having a song played in the b

Post by mikeysklar »

@eranbenjamin,

Thank you for taking the time to speedtest your card. That is helpful at removing the SD card as a culprit.

Would it be a big deal to change your code so that that it checks for the song playing to be finished before writing out the bit of data you wanted to put on the SD card? There is are two variables you can query to see if music is playing.

Code: Select all

playingMusic
musicPlayer.stopped

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

Return to “Arduino Shields from Adafruit”