Serial MP3 playback module with 1W speaker (HCMODU0138)

All modules related to sound (recoding/playback, amplifiers, speakers etc.)
Post Reply
admin
Site Admin
Posts: 743
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.

Post Reply