0

Reading from SD card while having a song played in the backg
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

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

by eranbenjamin on Tue May 04, 2021 5:25 pm

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!

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

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

by mikeysklar on Thu May 06, 2021 5:32 pm

@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 270 times


https://www.sdcard.org/developers/sd-st ... eed-class/

mikeysklar
 
Posts: 4624
Joined: Mon Aug 01, 2016 8:10 pm

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

by eranbenjamin on Thu May 06, 2021 6:19 pm

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 | TOGGLE FULL SIZE
// 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

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

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

by mikeysklar on Thu May 06, 2021 6:26 pm

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.

mikeysklar
 
Posts: 4624
Joined: Mon Aug 01, 2016 8:10 pm

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

by eranbenjamin on Tue May 11, 2021 12:34 am

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?

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

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

by mikeysklar on Tue May 11, 2021 9:42 am

@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 | TOGGLE FULL SIZE
playingMusic
musicPlayer.stopped

mikeysklar
 
Posts: 4624
Joined: Mon Aug 01, 2016 8:10 pm

Please be positive and constructive with your questions and comments.