Help with getting RFID, SD card and audio to work together

Hi

I am a front end developer but I am quite new to the micro controller world.

The Project
I am trying to create a RFID tag controlled mp3 player for my son (kind of like a "tonieBox" clone.
The idea is to build something like this:

  • When we put an RFID tag on the device, we must read the tag and start playing mp3 from the corresponding folder on the sd card
  • When we remove the RFID we should stop playing

The parts

  • I have started out with an Arduino Uno, but now changed to a ESP32 doit devkit v1 (because of the builtin wifi)
  • RFID reader: RFID-RC522
  • SD card reader: micro sd card adapter (nothing else written. SD, SCK, MOSI, MISO, VCC, GND pins)
  • Audio: MAX98357A

What i have done
I have been following some tutorials and tackling the problem piece by piece.

  • I have the RFID tag reader working
  • I have buttons for start, stop, volume up and down working
  • I have connected the SD card and could read the content of a test txt file

My problem
I now need to play the correct m3 file when a tag is present.
I thought this would be something easy, but after trying for a week i am about to give up. i have no idea what i am doing wrong.
I get no sound!
If i add a Serial.println to the code where i read the tag, i see it on the Serial Monitor, but i can't get the audio to work!

The code
I'm not sure what code to post.
I have split the code into several smaller files, you can see it all on the github page for the project

I would really thankful for any help.
Please let me know if there is any other information you need.

Thank you!

Do you have a sample program for JUST the mp3 player and does it work? You need to test the hardware set up.

1 Like

Posting the part where the problem appeared, the SD card being execised, would be good.
Does using Serial.println of the filename of the mp3 file tell anything?
Having a number of predefined files used according to the selection ought to be easy.

1 Like

Following the advice from both of you i have tried a couple of different things to see if it works just the mp3 player.
The first thing i did was to use a different speaker. No change... :frowning:
Then i tried adding some serial prints to the see if the audioPlayer is getting initialized:
Added this:

Serial.println("AFTER SETUP ========================");
  Serial.println(audioPlayer.isRunning());
  Serial.println(audioPlayer.getVolume());
  Serial.println(audioPlayer.getBitsPerSample());
  Serial.println(audioPlayer.getFileSize());

  audioPlayer.connecttoSD("/amaze.mp3", 0);

  Serial.println("AFTER CONNECT ========================");
  Serial.println(audioPlayer.isRunning());
  Serial.println(audioPlayer.getVolume());
  Serial.println(audioPlayer.getBitsPerSample());
  Serial.println(audioPlayer.getFileSize());

and get:

AFTER SETUP ========================
0
15
16
0
AFTER CONNECT ========================
1
15
16
3980786

3.980.786 is indeed the number of bytes on the file (as i see it on my mac).
So i think the audio player is getting initialized and it can get the mp3 file from the SD card. Am i wrong assuming this?

So i think the problem is with the MAX89357A module or with how i have it wired.
I have another module around. just need to solder some pins so i can try it (will do tomorrow).
I have tried connecting to different pins, but no luck either.

I have some problem understanding what the ESP32 pins are for. It's not like just analog or digital pins like on my UNO. The pins have some "roles", so maybe i am connecting to some wrong pins?
Currently:

  • LRC: pin 26
  • BCLK: pin 12 (also tried on 22)
  • DIN: pin 25
    Could this be the problem?

Any other ideas on how i could debug this?
Would it be possible to connect a speaker directly to the board?

Certainly, but will be the same as a short circuit. Will kill your Arduino.

Please post the entire code. The mistake is for sure not in the snippet You posted.

@Railroader The code is split into smaller files, so i am not sure how to post that correctly.
On the question i have posted a link to the github, is that ok? enough?

Here it is again: the github for the project where you can see all the code

thank you

I have just tried a new MAX98357A. Still no sound.
Not sure how to debug this any further. Any ideas?

I have added the following auxiliar functions from the ESP32-audioI2S library:

void audio_info(const char *info){
    Serial.print("info        "); Serial.println(info);
}
void audio_id3data(const char *info){  //id3 metadata
    Serial.print("id3data     ");Serial.println(info);
}
void audio_eof_mp3(const char *info){  //end of file
    Serial.print("eof_mp3     ");Serial.println(info);
}
void audio_showstation(const char *info){
    Serial.print("station     ");Serial.println(info);
}
void audio_showstreaminfo(const char *info){
    Serial.print("streaminfo  ");Serial.println(info);
}
void audio_showstreamtitle(const char *info){
    Serial.print("streamtitle ");Serial.println(info);
}
void audio_bitrate(const char *info){
    Serial.print("bitrate     ");Serial.println(info);
}
void audio_commercial(const char *info){  //duration in sec
    Serial.print("commercial  ");Serial.println(info);
}
void audio_icyurl(const char *info){  //homepage
    Serial.print("icyurl      ");Serial.println(info);
}
void audio_lasthost(const char *info){  //stream URL played
    Serial.print("lasthost    ");Serial.println(info);
}
void audio_eof_speech(const char *info){
    Serial.print("eof_speech  ");Serial.println(info);
}

an now the serial output looks like this:

Setting up audio player...
AFTER SETUP ========================
0
21
16
0
info        PSRAM not found, inputBufferSize: 6399 bytes
info        buffers freed, free Heap: 149252 bytes
info        Reading file: "/amaze.mp3"
info        MP3Decoder has been initialized, free Heap: 121536 bytes
AFTER CONNECT ========================
1
21
16
3980786
info        Closing audio file
info        End of file "amaze.mp3"
eof_mp3     amaze.mp3

So it opens the file but it immediately closes it!
Any ideas?!

I am still struggling with this problem, and i have really no idea what is going on.

I have added another help function to my code:

void audio_info(const char *info){
    Serial.print("audio_info: "); Serial.println(info);
    if(strcmp(info, "stream ready") == 0){
        Serial.printf("FileSize is %i bytes\n", audioPlayer.getFileSize());
    }
}

The Serial Output now looks like this:

AFTER SETUP ========================
0
21
16
0
audio_info: PSRAM not found, inputBufferSize: 6399 bytes
audio_info: buffers freed, free Heap: 149260 bytes
audio_info: Reading file: "/amaze.mp3"
audio_info: MP3Decoder has been initialized, free Heap: 121544 bytes
1111111111
2
0
AFTER CONNECT ========================
1
21
16
3980786
audio_info: Content-Length: 3980786
audio_info: ID3 framesSize: 144
audio_info: ID3 version: 2.4
audio_info: ID3 normal frames
id3data     UserDefinedText: major_brandisom
id3data     UserDefinedText: minor_version512
id3data     UserDefinedText: compatible_brandsisomiso2mp41
id3data     SettingsForEncoding: Lavf58.45.100
audio_info: Audio-Length: 3980642
audio_info: stream ready
FileSize is 3980786 bytes
audio_info: syncword found at pos 0
audio_info: Channels: 2
audio_info: SampleRate: 44100
audio_info: BitsPerSample: 16
audio_info: BitRate: 128000

I am really lost here. If some one could help me debug this problem i would be really grateful!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.