MOD-MP3-X - UEXT playback mode - stream data via SPI

Started by mihaiadrian, August 19, 2024, 09:53:58 PM

Previous topic - Next topic

mihaiadrian

I have a MOD-MP3-X  and I would like to use it in this mode:  UEXT playback mode – in this mode the board can be connected as slave device to host microcontroller which streams data to the codec via SPI

Are there any examples for doing that ?  I did not find any. One approach would be to check in it's microcontroller sources , understand what happens there and than write from scratch the esp32-poe-iso code - but this is a lot of effort. I hope there is something already done.

Already searched the forum, nothing found. Example:
https://www.olimex.com/forum/index.php?topic=5231.msg21760#msg21760
https://www.olimex.com/forum/index.php?topic=2073.msg9260#msg9260



LubOlimex

I believe all demos we've provided are for UEXT smart control mode only.
Technical support and documentation manager at Olimex

mihaiadrian

thank you, in the meantime I found this:

https://github.com/Edzelf/Esp-radio
https://github.com/xtrinch/ESP-internet-radio
https://github.com/Edzelf/ESP32-Radio

So they stream the mp3 from a ESP32 to a VS1053 .  Need to check that into detail to see how they done it

mihaiadrian

#3
It works!

I managed to do it .... Changed the board jumpers according to documentation for UEXT playback mode. This is the code - works for Olimex ESP32 POE ISO + Olimex  MOD-MP3-X-LITE connected via UEXT . I hear the beep. ( Note: I use the board WITHOUT ST additional microcontroller ).  Will try next with more advanced stuff ( mp3 data to come from the network - I am pretty sure it will work ... My example just has a small mp3 hardcoded into actual program ).  Also need to check how to record.

What I am not happy about the fact the most ( if not whole ) UEXT is used - so this will be problematic when using with a i2c temp sensor and/or a SPI/i2c display. I need to see if I can replace some of the pins from UEXT with other board that can be controlled via I2C which extends the GPIO's  and then to replace the code in the actual library to use that ( already done a similar approach for SPI displays due to not enought available GPIO's )....

PS. Code works for me but for you - use it at you're own risk !

Adapted from:  https://github.com/baldram/ESP_VS1053_Library/tree/master/examples/Mp3PlayerDemo

#include "header.h"

#include <Arduino.h>
/* next header not present in Arduino, needs to be added manually in Arduino.
 *  go to https://github.com/baldram/ESP_VS1053_Library - and copy paste in Arduino/libraries */
#include <VS1053.h>
#include <ESP32_VS1053_Stream.h>

#define ETH_CLK_MODE ETH_CLOCK_GPIO17_OUT
#define ETH_PHY_POWER 12

#include <ETH.h>
#include <Ethernet.h>
WiFiClient client;

#define VS1053_CS    16
#define VS1053_DCS    5
#define VS1053_DREQ  4


// Default volume
#define VOLUME  100

VS1053 player(VS1053_CS, VS1053_DCS, VS1053_DREQ);


void setup() {
    Serial.begin(115200);

    delay(100);
    ETH.begin();

    // Wait for VS1053 and PAM8403 to power up
    // otherwise the system might not start up correctly
    delay(3000);


    SPI.begin(14, 15, 2);

    player.begin();
    if (player.getChipVersion() == 4) { // Only perform an update if we really are using a VS1053, not. eg. VS1003
        player.loadDefaultVs1053Patches();
    }
    if (player.isChipConnected())
        Serial.println("Yes, success, chip connected");   
    player.switchToMp3Mode();
    player.setVolume(VOLUME);

}

void loop() {

 player.playChunk(ding_mp3, sizeof(ding_mp3));
 delay(1000);
 
 Serial.print("Play");
 
}



header.h:
// use something like xxd -i your-sound.mp3 header.h  to create it then check/modify vars name

unsigned char ding_mp3[] = {
  0x49, 0x44, 0x33, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x23, 0x54, 0x53,
        0x53, 0x45, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x03, 0x4c, 0x61, 0x76,
        0x66, 0x35, 0x38, 0x2e, 0x32, 0x30, 0x2e, 0x31, 0x30, 0x30, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xe3, 0x40,
        0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x49, 0x6e,
        0x66, 0x6f, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00,
        0x04, 0x14, 0x00, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c,
        0x4c, 0x4c, 0x4c, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66,
        0x66, 0x66, 0x66, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f,
        0x7f, 0x7f, 0x7f, 0x7f, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99,
        0x99, 0x99, 0x99, 0x99, 0xb3, 0xb3, 0xb3, 0xb3, 0xb3, 0xb3, 0xb3, 0xb3,
        0xb3, 0xb3, 0xb3, 0xb3, 0xb3, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
        0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xe6, 0xe6, 0xe6, 0xe6, 0xe6, 0xe6, 0xe6,
        0xe6, 0xe6, 0xe6, 0xe6, 0xe6, 0xe6, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
        0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x4c, 0x61,
        0x76, 0x63, 0x35, 0x38, 0x2e, 0x33, 0x35, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x02, 0xfa, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x04, 0x14, 0x18, 0x80, 0x8d, 0xcc, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0xff, 0xe3, 0x20, 0xc4, 0x00, 0x14, 0x11, 0xaa, 0xee, 0x5f, 0x41,
        0x10, 0x02, 0x1b, 0x6d, 0xb6, 0xd6, 0xd8, 0xc0, 0xb2, 0xcb, 0xc6, 0x31,
        0x8c, 0x63, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0x31, 0x8c, 0x63,
        0x18, 0xc8, 0x42, 0x10, 0x84, 0xf9, 0xce, 0x73, 0xfd, 0x08, 0x46, 0xe7,
        0x39, 0xff, 0xd0, 0x84, 0x21, 0x3f, 0x39, 0xce, 0xfd, 0x3f, 0xfe, 0xa7,
        0x21, 0x19, 0x4e, 0x1c, 0x0c, 0x3f, 0xff, 0x04, 0x01, 0x00, 0xc6, 0x27,
        0x07, 0xdf, 0xff, 0x82, 0x00, 0x84, 0xe1, 0x70, 0xff, 0x7f, 0xfe, 0xa0,
        0x40, 0x13, 0x07, 0xc3, 0xff, 0xff, 0xfe, 0x08, 0x02, 0x07, 0x15, 0x6d,
        0xd0, 0x28, 0x14, 0x0b, 0x45, 0xb6, 0xd0, 0x84, 0x01, 0xff, 0xe3, 0x22,
        0xc4, 0x0a, 0x17, 0x31, 0xd6, 0xf6, 0x5f, 0x81, 0x68, 0x02, 0xa1, 0x5d,
        0xae, 0xd5, 0x55, 0x11, 0xfa, 0x3f, 0xd2, 0xfe, 0xc8, 0xd5, 0xfd, 0x24,
        0x91, 0x5a, 0xef, 0x5b, 0x7a, 0x29, 0x24, 0xc6, 0x4e, 0xb6, 0xb7, 0xff,
        0x55, 0x4b, 0x32, 0xff, 0x5d, 0x48, 0x53, 0x5b, 0x13, 0x43, 0xc8, 0xe6,
        0x45, 0x97, 0xd4, 0x3c, 0x9f, 0xde, 0xc0, 0xe5, 0x37, 0x41, 0x89, 0xbb,
        0xfe, 0x5c, 0x71, 0xc2, 0xfe, 0x13, 0x11, 0x0e, 0x5e, 0x84, 0xaa, 0xd8,
        0x26, 0xb2, 0x42, 0xe1, 0x47, 0x94, 0xac, 0x1b, 0x1c, 0xfd, 0x9e, 0x50,
        0x2f, 0x42, 0x17, 0x6a, 0x41, 0x15, 0x6a, 0x7e, 0x6d, 0xb6, 0xdb, 0x49,
        0x00, 0x0a, 0x45, 0xb5, 0x55, 0x7f, 0xff, 0xe3, 0x20, 0xc4, 0x09, 0x16,
        0x6a, 0x5e, 0xd8, 0x1f, 0x81, 0x88, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff,
        0xfd, 0x49, 0xea, 0x32, 0x34, 0x33, 0xf2, 0x91, 0x12, 0x76, 0x41, 0x33,
        0x35, 0xbb, 0x2d, 0x05, 0xa2, 0x64, 0xb5, 0x7f, 0x49, 0x8c, 0x8b, 0xcc,
        0xcc, 0x9f, 0xa3, 0x53, 0xff, 0xef, 0xad, 0x32, 0x44, 0x5c, 0xe5, 0x72,
        0xfa, 0x6f, 0x52, 0x4e, 0x43, 0x4b, 0x80, 0xd2, 0x85, 0xf0, 0x1a, 0x49,
        0x52, 0x5f, 0xc4, 0x62, 0x1c, 0xd3, 0x98, 0x38, 0x70, 0xfc, 0x9d, 0x47,
        0x6a, 0xff, 0xfa, 0xd2, 0xb3, 0x18, 0x5e, 0xc5, 0xcf, 0x38, 0xab, 0x92,
        0xa7, 0x95, 0xec, 0x4a, 0x12, 0xed, 0xa6, 0x8c, 0x76, 0x98, 0x2b, 0x7f,
        0xff, 0xfd, 0xff, 0xe3, 0x22, 0xc4, 0x0a, 0x16, 0xe2, 0x96, 0xb4, 0x7f,
        0xc5, 0x88, 0x00, 0x93, 0x47, 0x55, 0xd1, 0xaf, 0x7d, 0x14, 0x96, 0xa4,
        0x1d, 0x6a, 0x4d, 0x4b, 0x56, 0xa4, 0x57, 0xff, 0x54, 0x7a, 0x2f, 0x18,
        0x3b, 0x56, 0xd4, 0x2e, 0x82, 0x94, 0xf5, 0xd7, 0x7b, 0xdb, 0x7d, 0x5a,
        0xfe, 0xdd, 0x17, 0xa4, 0xbf, 0xff, 0xe8, 0xa3, 0x44, 0x7c, 0x01, 0x72,
        0x44, 0x51, 0x90, 0x21, 0xce, 0x22, 0xa6, 0xac, 0xb3, 0x95, 0x23, 0x49,
        0x49, 0x16, 0x56, 0xc7, 0xcc, 0xd0, 0x29, 0x9f, 0x40, 0x55, 0x8f, 0x1d,
        0x62, 0x69, 0x3f, 0x25, 0x56, 0x77, 0xd9, 0xff, 0xfc, 0xb3, 0x7c, 0x56,
        0xaa, 0x92, 0x5b, 0x25, 0x8c, 0x66, 0x02, 0xff, 0xff, 0xd8, 0xc7, 0xff,
        0xe3, 0x20, 0xc4, 0x0a, 0x13, 0xaa, 0xa2, 0xcc, 0x7e, 0x0a, 0x93, 0x72,
        0x14, 0xa9, 0x5e, 0x81, 0x19, 0x80, 0x40, 0x68, 0xc0, 0x61, 0x35, 0x5c,
        0x26, 0x45, 0xeb, 0xf1, 0x78, 0x53, 0x1a, 0x88, 0x64, 0xe1, 0xf2, 0x9b,
        0x53, 0xc9, 0xaa, 0x8a, 0xea, 0x52, 0xed, 0xa1, 0xa8, 0x9e, 0x65, 0xd1,
        0xbe, 0xfe, 0xff, 0xff, 0xf8, 0xc8, 0x0b, 0xdf, 0x21, 0x68, 0xa1, 0x82,
        0x6b, 0x82, 0xad, 0x2a, 0xe9, 0xb2, 0xc0, 0xcb, 0xe4, 0x48, 0x28, 0x7a,
        0x35, 0x88, 0x02, 0x9a, 0x8f, 0xaf, 0xbb, 0x6f, 0x55, 0x92, 0xdb, 0x6d,
        0x8c, 0x66, 0xc2, 0xff, 0xff, 0xc2, 0x89, 0x97, 0xae, 0xae, 0x16, 0x2e,
        0x2a, 0xe1, 0xb5, 0x78, 0x59, 0x85, 0x66, 0xff, 0xe3, 0x22, 0xc4, 0x16,
        0x19, 0x4a, 0xa2, 0xc8, 0x7f, 0x41, 0x40, 0x02, 0x74, 0xd0, 0xa6, 0xca,
        0x9d, 0x6e, 0x25, 0xa7, 0x90, 0x2c, 0x3c, 0x65, 0x56, 0xe4, 0x64, 0xc6,
        0xb5, 0x23, 0x2b, 0x8f, 0x8f, 0xb4, 0xf5, 0x97, 0xb8, 0xff, 0xfa, 0xfa,
        0x8b, 0xaf, 0x9b, 0xff, 0xff, 0xff, 0xff, 0xfc, 0xb0, 0x03, 0x7e, 0x21,
        0x02, 0xf0, 0x1e, 0x22, 0x8c, 0x12, 0x8a, 0x0a, 0x07, 0x25, 0x04, 0x61,
        0xf8, 0xd8, 0x51, 0x00, 0x41, 0x15, 0x2a, 0xc2, 0x61, 0x0e, 0x82, 0x12,
        0x85, 0x4d, 0x6e, 0x5b, 0x08, 0xcb, 0x5a, 0x8f, 0x63, 0x1e, 0x7b, 0x4f,
        0x16, 0x3a, 0xf6, 0xaa, 0x40, 0x06, 0xa8, 0x35, 0x7f, 0xf4, 0x5f, 0xa4,
        0xda, 0x5d, 0x24, 0x5f, 0xff, 0xe3, 0x20, 0xc4, 0x0c, 0x15, 0xd3, 0x5a,
        0x80, 0x03, 0x8a, 0x98, 0x02, 0xff, 0xd5, 0xff, 0xec, 0xa3, 0x52, 0x89,
        0x57, 0x55, 0x6d, 0xfa, 0x28, 0xa0, 0x9b, 0xba, 0xf7, 0x7f, 0xfd, 0x90,
        0x6a, 0xee, 0x9a, 0x0b, 0x47, 0xd1, 0x5a, 0xbf, 0xe8, 0xb5, 0x70, 0x29,
        0xf0, 0x5b, 0x84, 0x82, 0xd6, 0xb5, 0xba, 0xe8, 0xb8, 0x10, 0xa8, 0x07,
        0xd4, 0x90, 0x52, 0x9f, 0xe8, 0x98, 0x9e, 0x4b, 0xd1, 0x3c, 0xba, 0xd0,
        0x41, 0x75, 0x2d, 0x2f, 0xff, 0xff, 0xff, 0xfd, 0x6d, 0x65, 0xd1, 0xad,
        0x04, 0x4d, 0x4b, 0x2c, 0xeb, 0x19, 0xd9, 0x88, 0xaa, 0x10, 0x01, 0x00,
        0xb5, 0xb0, 0x69, 0x00, 0x80, 0x8d, 0x29, 0x66, 0x6f, 0xff, 0xff, 0xf4,
        0xff, 0xe3, 0x22, 0xc4, 0x0f, 0x0d, 0xe2, 0x2d, 0xc5, 0x1d, 0xc2, 0x10,
        0x00, 0x37, 0xff, 0xff, 0xff, 0xf5, 0x2f, 0xf9, 0xbf, 0xff, 0xfa, 0x3f,
        0xf5, 0x6f, 0xff, 0xff, 0x52, 0xb4, 0xc6, 0x0c, 0x02, 0x02, 0x02, 0x24,
        0x61, 0xe5, 0x82, 0xa0, 0xa9, 0xdf, 0xff, 0xfd, 0x5f, 0x5f, 0xf8, 0x94,
        0xec, 0x8f, 0xff, 0xa8, 0xf1, 0x6a, 0x4c, 0x41, 0x4d, 0x45, 0x33, 0x2e,
        0x31, 0x30, 0x30, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
        0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
        0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
        0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa
};
unsigned int ding_mp3_len = 3760;