Serial MP3 playback module with 1W speaker (HCMODU0138)

All modules related to sound (recoding/playback, amplifiers, speakers etc.)
Post Reply
admin
Site Admin
Posts: 880
Joined: Sun Aug 05, 2012 4:02 pm

Serial MP3 playback module with 1W speaker (HCMODU0138)

Post by admin » Fri May 10, 2019 10:36 am

Image




This modules is a simple MP3 player device which is based on a high-quality MP3 audio chip. It can support 8k Hz ~ 48k Hz sampling frequency MP3 and WAV file formats. There is a TF card socket on board, so you can plug in the micro SD card that stores audio files. MP3 Playback can be controlled via a Microcontroller such as an Arduino by sending commands to the module via serial UART port, e.g. switch songs, change the volume, play mode and so on. It is compatible with most Microcontrollers capable of serial communication at 9600 BAUD (Arduino / AVR / ARM / PIC). The module also includes a 3 Watt amplifier and comes complete with a 1 Watt speaker.

For Arduino users we have created an exclusive library (HCMP3) which can be downloaded from the software section of our support forum (see link below).

ImageImage


Specification:

- Product code: HCMODU0138
- Compatible with Arduino UNO / Leonardo / Mega2560 / DUE
- Supports sampling frequency (kHz): 8 / 11.025 / 12 / 16 / 22.05 / 24 / 32 / 44.1 / 48
- Supports file formats: MP3 / WAV
- Support Micro SD card, Micro SDHC Card
- On-board 3-watt mono amplifier
- On-board speaker interface XH2.54-2P, can connect to external speakers such as 8 ohm 1 to 3-watt
- 30 class adjustable volume
- UART TTL serial control playback mode, baud rate is 9600bps
- Serial communication format: 8N1
- Control logic interface can be 3.3V / 5V TTL
- Working voltage: 3.7 - 5.25VDC
- On-board headphone jack for connection to headphones or external amplifier
- On-board TF card connector



Image


Image


Image

Return bytes from a command status query are preceded with the original status command. For Example:

To get the current play status send the command: 7E 02 10 EF
If the module is currently playing a file it will return: 7E 02 00 EF 7E 03 10 01 EF
If the module is currently paused it will return: 7E 02 00 EF 7E 03 10 02 EF




Example Arduino Sketch Using HCMP3 Library:


Image


  1. /* FILE:    HCMP3_Example.cpp
  2.    DATE:    09/05/19
  3.    VERSION: 1.0
  4.    AUTHOR:  Andrew Davies
  5.    
  6. 09/05/19 version 1.0: Original version
  7.  
  8. This example sketch demonstrates how to use the HCMP3 library to control
  9. an audio playback device.
  10.  
  11. Currently this library supports the following module:
  12.  
  13. Serial MP3 playback module with 1W speaker (SKU: HCARDU0138)
  14.  
  15. Connect the above module as follows:
  16.  
  17. Arduino.........MP3 Module
  18. RX..............3
  19. TX..............2
  20. VCC.............5V
  21. GND.............GND
  22.  
  23. Within the HCMP3 library folder you will find a folder called 'MP3_Files'
  24. Copy the contents of this folder to the root directory of your flash card.
  25.  
  26. This library is provided free to support the open source community.
  27. We spend most of our time creating free content like this because we genuinely
  28. want to support the open source community. PLEASE SUPPORT US so that we can
  29. continue to create free content by purchasing products from our store -
  30. HOBBYCOMPONENTS.COM
  31.  
  32. You may copy, alter and reuse this code in any way you like, but please leave
  33. reference to HobbyComponents.com in your comments if you redistribute this code.
  34. This software may not be used directly for the purpose of selling products that
  35. directly compete with Hobby Components Ltd's own range of products.
  36. THIS SOFTWARE IS PROVIDED "AS IS". HOBBY COMPONENTS MAKES NO WARRANTIES, WHETHER
  37. EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
  38. MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ACCURACY OR LACK OF NEGLIGENCE.
  39. HOBBY COMPONENTS SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR ANY DAMAGES,
  40. INCLUDING, BUT NOT LIMITED TO, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY
  41. REASON WHATSOEVER.
  42. */
  43.  
  44.  
  45. /* Include the library */
  46. #include "HCMP3.h"
  47.  
  48. /* Digital pins used for serial communication */
  49. #define RX_PIN 2
  50. #define TX_PIN 3
  51.  
  52.  
  53. /* Create an instance of the library */
  54. HCMP3 HCMP3(TX_PIN, RX_PIN);
  55.  
  56. void setup()
  57. {
  58.   Serial.begin(9600);
  59.   HCMP3.reset();
  60.  
  61.   /* Get the current status of the module */
  62.   Serial.println("MODULE STATUS");
  63.   Serial.print("Card state....");
  64.   PrintCardState();
  65.   Serial.print("Playback state.....");
  66.   PrintPlaybackState();
  67.   Serial.print("Volume level....");
  68.   Serial.println(HCMP3.getVolumeState());
  69.   Serial.println("");
  70.   delay(2000);
  71.  
  72.   /* Change the volume level */
  73.   Serial.print("Setting volume level to....");
  74.   HCMP3.volume(10);
  75.   Serial.println(HCMP3.getVolumeState());
  76.   delay(2000);
  77. }
  78.  
  79. void loop()
  80. {
  81.   /* Play the first file */
  82.   Serial.println("Playing first file on card");
  83.   HCMP3.play();
  84.   delay(2000);
  85.  
  86.   /* Play the next file */
  87.   Serial.println("Playing next file");
  88.   HCMP3.playNext();
  89.   delay(2000);
  90.  
  91.   /* Play the previous file */
  92.   Serial.println("Playing previous file");
  93.   HCMP3.playPrevious();
  94.   delay(2000);
  95.  
  96.   /* Play the first file in folder 1 */
  97.   Serial.println("Playing file 1 in folder 1");
  98.   HCMP3.play(1,1);
  99.   delay(5000);
  100.  
  101.   /* Pause playback */
  102.   Serial.print("Pausing....");
  103.   HCMP3.pause();
  104.   PrintPlaybackState();
  105.   delay(2000);
  106.  
  107.   /* Resume playback */
  108.   Serial.print("Resuming....");
  109.   HCMP3.play();
  110.   PrintPlaybackState();
  111.   delay(2000);
  112.  
  113.   /* Turn the volume down in increments */
  114.   Serial.print("Volume down");
  115.   for(byte i = 0; i < 20; i++)
  116.   {
  117.     Serial.print(".");
  118.     HCMP3.volumeDown();
  119.     delay(100);
  120.   }
  121.   Serial.println("");
  122.  
  123.  
  124.   /* Turn the volume up in increments */
  125.   Serial.print("Volume up");
  126.   for(byte i = 0; i < 20; i++)
  127.   {
  128.     Serial.print(".");
  129.     HCMP3.volumeUp();
  130.     delay(100);
  131.   }
  132.   Serial.println("");
  133.  
  134.   delay(5000);
  135.  
  136.   /* Stop the playback */
  137.   Serial.print("Playback...");
  138.   HCMP3.stop();
  139.   PrintPlaybackState();
  140.  
  141.   while(1);
  142.  
  143. }
  144.  
  145.  
  146. /* Prints out the current playback state */
  147. void PrintPlaybackState()
  148. {
  149.   switch(HCMP3.getPlayState())
  150.   {
  151.     case(STATUS_STOP):
  152.       Serial.println("Stopped");
  153.       break;
  154.  
  155.     case(STATUS_PLAY):
  156.       Serial.println("Playing");
  157.       break;
  158.  
  159.     case(STATUS_PAUSED):
  160.       Serial.println("Paused");
  161.       break;      
  162.   }
  163. }
  164.  
  165.  
  166. /* Prints out the current flash card state */
  167. void PrintCardState()
  168. {
  169.   switch(HCMP3.getCardState())
  170.   {
  171.     case(CARD_EJECTED):
  172.       Serial.println("Ejected");
  173.       break;
  174.  
  175.     case(CARD_INSERTED):
  176.       Serial.println("Inserted");
  177.       break;
  178.  
  179.     case(CARD_UNKOWN):
  180.       Serial.println("Unknown");
  181.       break;      
  182.   }
  183. }



Image


The HCMP3 Arduino library for the above sketch can be downloaded from the software section of our support forum here:


http://forum.hobbycomponents.com/viewto ... =58&t=2884



Disclaimer: Libraries, example code, and diagrams within this forum thread are provided as an additional free service by Hobby Components and are not sold as part of any product. We do not provide any guarantees or warranties as to their accuracy or fitness for purpose.

Descriptions and diagrams on this page are copyright Hobby Components Ltd and may not be reproduced without permission.

TinkerSpike
Posts: 5
Joined: Wed Jan 29, 2020 7:37 pm

Re: Serial MP3 playback module with 1W speaker (HCMODU0138)

Post by TinkerSpike » Thu Sep 24, 2020 3:25 am

Hi,
thank you for making this library :)
it has helped me get quite a few projects done in a snap :)
However, I seem to be unable to get the function "HCMP3.getPlayState()" to work or get a proper responce through the example. atm it seems to only reply with a 255 (high) state if I print the status out to the serial monitor.. Does not matter if it plays or not, same value. Not quite sure what to do here XD
even the example sketch does not give a proper print out on statuses so idk.
Appreciate any help you might be able to pass on :)
Thanks,
Tinkerspike

andrew
Site Admin
Posts: 1411
Joined: Sun Aug 05, 2012 4:15 pm

Re: Serial MP3 playback module with 1W speaker (HCMODU0138)

Post by andrew » Thu Sep 24, 2020 8:53 am

However, I seem to be unable to get the function "HCMP3.getPlayState()" to work or get a proper responce through the example.
Can you confirm if you are getting a response from any of the other commands? I.e. is it completely unresponsive to any command or is it doing something?

When you run the above test sketch you should see something like this in the monitor window:

MODULE STATUS
Card state....Inserted
Playback state.....Stopped
Volume level....12

Setting volume level to....10

etc...

Do you at least see the status for the card state line as above? If not can you paste what you're actually seeing. Also can you let me know what type of Arduino you are using?
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

TinkerSpike
Posts: 5
Joined: Wed Jan 29, 2020 7:37 pm

Re: Serial MP3 playback module with 1W speaker (HCMODU0138)

Post by TinkerSpike » Thu Sep 24, 2020 10:17 am

When I run the test sketch and open the serial monitor this is what I get:

==========
MODULE STATUS
Card state....Playback state.....Volume level....100

Setting volume level to....100
Playing first file on card
Playing next file
Playing previous file
Playing file 1 in folder 1
Pausing....Resuming....Volume down....................
Volume up....................
Playback...
==========

"HCMP3.getVolumeState()" seems to work fine as well as others, however the cardstate and playstate does not seem to get a response from the module for some reason :/ I've checked wiring multiple times and I am using a Arduino Uno for this (tried a genuine UNO as well as a few clones.. same result), the module plays audio just fine, both through speaker and line out. Now I only have 1 of theses mp3 modules so am unable to try and see if it is a firmware issue causing it. I am no code writer per say, so even just looking at the .cpp and .h files and the various status commands (comparing those that work and not) I don't really see anything wrong, although slightly above my own pay grade tbh..

TinkerSpike
Posts: 5
Joined: Wed Jan 29, 2020 7:37 pm

Re: Serial MP3 playback module with 1W speaker (HCMODU0138)

Post by TinkerSpike » Thu Sep 24, 2020 11:09 am

Hmm.. now that I have also played around with the getVolume command.. it also seems to only give a 100 value back no matter what I do. volumeUp and volumeDown works just fine however.. just cannot get the statuses of this module :/

TinkerSpike
Posts: 5
Joined: Wed Jan 29, 2020 7:37 pm

Re: Serial MP3 playback module with 1W speaker (HCMODU0138)

Post by TinkerSpike » Thu Sep 24, 2020 11:40 am

Ok.. so done some further testing and even gone back to the original RedMp3 library and it does not give me any responses either on status commands.. so idk.. faulty firmware? kinda odd all other commands work fine though so I'm at a loss here lol

andrew
Site Admin
Posts: 1411
Joined: Sun Aug 05, 2012 4:15 pm

Re: Serial MP3 playback module with 1W speaker (HCMODU0138)

Post by andrew » Thu Sep 24, 2020 1:50 pm

Thanks for checking. The example sketch is a known working sketch so should defiantly work. If it's not even getting as far as reporting the card status then this would suggest there is something more fundamentally wrong somewhere.

the module plays audio just fine, both through speaker and line out.
Can I check how you are getting the module to play an MP3?
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

TinkerSpike
Posts: 5
Joined: Wed Jan 29, 2020 7:37 pm

Re: Serial MP3 playback module with 1W speaker (HCMODU0138)

Post by TinkerSpike » Thu Sep 24, 2020 2:45 pm

Here is a snippet out of my own code but no real difference vs the example per say.
I am using a ps2 controller atm to activate sounds. Using the HCMP3.play() with directory and file and it works just fine.
The reason I want the status is to check if a file is playing to activate say a led string or servo movement while it plays.
I do think you are right though, might be a firmware issue or breakdown there of. I do appreciate the help though as I has loosing hair in the process LOL
I guess one option is to tap into the "play" LED on the board to a input on the arduino and just check it for HIGH/LOW.
I do love these little mp3 boards, small footprint and plenty of features (like the onboard amp/speaker output).

--------
if(ps2x.ButtonPressed(PSB_R2) == 1)
{
HCMP3.play(6, 1);
}
--------

andrew
Site Admin
Posts: 1411
Joined: Sun Aug 05, 2012 4:15 pm

Re: Serial MP3 playback module with 1W speaker (HCMODU0138)

Post by andrew » Fri Sep 25, 2020 7:41 am

Using the HCMP3.play() with directory and file and it works just fine.
Oh ok, so it is actually communicating with the module then. That does rule out a lot of possibilities. I've taken one out of our current stock and tested it and it works fine. Here is the output from the example sketch:

MODULE STATUS
Card state....Inserted
Playback state.....Stopped
Volume level....12

Setting volume level to....10
Playing first file on card
Playing next file
Playing previous file
Playing file 1 in folder 1
Pausing....Paused
Resuming....Playing
Volume down....................
Volume up....................

Did you buy the module from us or did it come from somewhere else? If it came from somewhere else that would point to the issue being a difference in firmware.
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

Post Reply

Return to “Audio”