Sketch for XY5300 Catalex module

 XY5300 Catalex Module

The XY5300 module used in this sketch

the XY5300 Catalex module and Arduino MEGA

The audio part of the home automation system has changed over time. In the first implementation I used the WaveShield of the Adafruit. Then I used the WTV020-SD-16P module that allowed me to simplify the hardware and software, although cumbersome in the creation of audio files to be passed to it. Then, when the SD card inserted in the module started to get damaged, I realized how much time had passed. The module accepted SD cards up to 1GB. Now unavailable. This, inevitably, led me to look for other solutions, finding in the CATALEX XY5300 a valid alternative. This card accepts up to 32GB of SDHC memory and plays MP3 files directly without the need for various conversions between audio formats. In addition, the audio quality is much higher than that of the previously used cards.

The sketch for XY5300 module

To use it, I had to transform the example sketch of the XY5300 card so that MP3 sound files are played without the main program to stop. In other words, I modified the sketch to avoid using delays or potentially infinite loops to read data on the serial port. This way of working has made the sketch easy to use in any other program. Thinking that it could be useful to others, the idea of sharing it. The audio management software section of the home automation system, extracted in a general purpose sketch for the XY5300 module

The audio management software section of the home automation system, extracted in a general purpose sketch for the XY5300 module

Anyone who already has a nice complex program that can not or does not want to make strong changes to give it additional functionality such as “voice messages” or “music” can merge between his and the sketch downloadable from the link on this page. In other words, to give the potential of the xy5300 card to your sketch, simply add the variables, the routines of the attached sketch and in the points of the program where you want to play MP3 files put the instruction:


As mentioned the MP3 file will be played in full while your sketch will continue its execution. However, a new instruction, which arrives before the previous mp3 file is finished, will interrupt it. If this behavior is not desired, it is possible to wait for the variable XY5300_Is_playing to go to zero before playing a new MP3 file.

All this works through the XY5300_Engine(); statement; to be put in the main loop and the xy5300_sendCommand statement (CMD_SEL_DEV, DEV_TF); to be put in the void setup (). The first instruction allows the system to periodically launch data receive routines from the serial port to update the XY5300_Is_playing variable. The second one, which is also necessary, instructs the card to use the SD memory.

To try the sketch:

If you want to test this program, upload eleven mp3 files to a folder named 01 in an SD card. Insert the SD card in the XY5300 module, connect it to an arduino in which you have loaded the sketch you find on this page. If you have less than 11 MP3s, change lines 132 and 133 by replacing the number 10 with the number of files you have less than one.
You can call your files as you wish, but they must be prefixed by a number in the form right-aligned and justified with zeros such as “001 song1.mp3”. Last consideration, the downloadable program is configured for the Arduino Mega. If you use different cards, uncomment the lines 60 to 62.


This sketch is distributed under license Postcardware (or cardware), freely usable on moral condition that you send me a postcard (or an email) from the point of the universe in which you are and that you mention the link of this page and author in the comments of the program.

Download sketch and some file MP3 for test