OMG this seems so simple but…Help sending Serial Data from ESP32 to Serial MP3 Player

So this is really Arduino adjacent ESP32 question:

I'm new to Arduino and ESP32, to please take that into account.

I am trying to control a Serial .MP3 player from my ESP32 (DIYables MP3 Player Module for Arduino, ESP32, ESP8266, Raspberry Pi).

To, for example,to play the first song on the SD card on the .MP3 module, it expects:
0x7E, 0xFF, 0x06, 0x03, 0x00, 0x00, 0x01, 0xEF

I can send this from Arduino and the mp3 player works fine. When I try to send from ESP32 it doesn't.

I looked at the serial output from both Arduino and ESP32 and there is an extra null byte (0x0) in the serial transmission at the beginning of the Arduino output that is not in ESP32's send.
I’m also not sure why the ESP32 is sending 8-bit 0xEF as 32-bit 0xFFFFFFEF and 0xFF as 0xFFFFFFFF

The serial outputs looks like this:

Received from Arduino------------------Received from ESP32
Received: 0x0-------------------Received: 0x7E
Received: 0x7E-------------------Received: 0xFFFFFFFF
Received: 0xFF-------------------Received: 0x6
Received: 0x6------------------Received: 0x9
Received: 0x9------------------Received: 0x0
Received: 0x0------------------Received: 0x0
Received: 0x0------------------Received: 0x2
Received: 0x2------------------Received: 0xFFFFFFEF
Received: 0xEF------------------Received: 0x7E
Received: 0x7E------------------Received: 0xFFFFFFFF
Received: 0xFF------------------Received: 0x6
Received: 0x6------------------Received: 0x6
Received: 0x6------------------Received: 0x0
Received: 0x0------------------Received: 0x0
Received: 0x0------------------Received: 0x1E
Received: 0x1E------------------Received: 0xFFFFFFEF
Received: 0xEF------------------Received: 0x7E
Received: 0x7E------------------Received: 0xFFFFFFFF
Received: 0xFF------------------Received: 0x6
Received: 0x6------------------Received: 0x3
Received: 0x3------------------Received: 0x0
Received: 0x0------------------Received: 0x0
Received: 0x0------------------Received: 0x1
Received: 0x1------------------Received: 0xFFFFFFEF
Received: 0xEF ---------

The code I’m using is:
Arduino:

#include <SoftwareSerial.h>

#define ARDUINO_RX 2  // Arduino Pin connected to the TX of the Serial MP3 Player module
#define ARDUINO_TX 3  // Arduino Pin connected to the RX of the Serial MP3 Player module

SoftwareSerial mp3(ARDUINO_RX, ARDUINO_TX);

void setup() {
  Serial.begin(9600);
  mp3.begin(9600);
  delay(500);  // wait chip initialization is complete

  byte selecttf[] = { 0x7E, 0xFF, 0x06, 0x09, 0x00, 0x00, 0x02, 0xEF };
  delay(200);                        // wait for 200ms

  mp3.write(selecttf, sizeof(selecttf));  //Select TF Card
  delay(200);  
  byte volume[] = { 0x7E, 0xFF, 0x06, 0x06, 0x00, 0x00, 0x1E, 0xEF };
  delay(200);  

mp3.write(volume, sizeof(volume)); //Set volume to full

}

void loop() {
  byte play[] = { 0x7E, 0xFF, 0x06, 0x03, 0x00, 0x00, 0x01, 0xEF };
 delay(20000);

mp3.write(play, sizeof(play));  //play first song on SD card

}

ESP32:

#include <HardwareSerial.h>

HardwareSerial mp3(1);

void setup() {
  Serial.begin(9600);
  mp3.begin(9600, SERIAL_8N1, 21, 19); //RX21 TX19
  delay(5000);  // wait chip initialization is complete
  
  byte selecttf[] = { 0x7E, 0xFF, 0x06, 0x09, 0x00, 0x00, 0x02, 0xEF };

  mp3.write(selecttf, sizeof(selecttf)); // select the TF card
delay(2000);
  byte volume[] = { 0x7E, 0xFF, 0x06, 0x06, 0x00, 0x00, 0x1E, 0xEF };

  mp3.write(volume, sizeof(volume)); //set volume to max
  delay(2000);
}

void loop() {

byte play[] = { 0x7E, 0xFF, 0x06, 0x03, 0x00, 0x00, 0x01, 0xEF }; //// Play first mp3 on card

mp3.write(play, sizeof(play));
delay(20000);

}

I know this must be really simple and obvious, but I’m at a loss. Any help is appreciated!

What makes you believe that this is true? I don't see anything in the code you've shown that would produce this output.

And why not use the already existing Serial1 object?

Thanks for your reply van-der-decken

What makes you believe that this is true? I don't see anything in the code you've shown that would produce this output.

I monitored the serial communication. In the original post I list what comm was received when sent from Arduino (as expected) and ESP32 which produced those anomalies

And why not use the already existing Serial1 object?

It wasn't sending serial. It's a problem others have had with ESP32 UART 1 & 2 also, so have resorted to using the HardwareSerial library.

Are the logic voltage levels consistent throughout ? The ESP32 is 3.3v. Otherwise use a level shifter.

Uh huh. Well, I'm a "I'll believe it when I see it" kind of person. So I wired up a handy ESP32 board with a DFplayer using the sketch below (which uses Serial1) and it worked just fine. With no unseen "take my word for it" "communication anomalies". The DFPlayer played the track as instructed.

void setup() {
   Serial.begin(9600);
   Serial1.begin(9600, SERIAL_8N1, 21, 19);  //RX21 TX19
   delay(5000);                          // wait chip initialization is complete

   byte selecttf[] = { 0x7E, 0xFF, 0x06, 0x09, 0x00, 0x00, 0x02, 0xEF };

   Serial1.write(selecttf, sizeof(selecttf));  // select the TF card
   delay(2000);
   byte volume[] = { 0x7E, 0xFF, 0x06, 0x06, 0x00, 0x00, 0x1E, 0xEF };

   Serial1.write(volume, sizeof(volume));  //set volume to max
   delay(2000);
}

void loop() {

   byte play[] = { 0x7E, 0xFF, 0x06, 0x03, 0x00, 0x00, 0x01, 0xEF };  //// Play first mp3 on card

   Serial1.write(play, sizeof(play));
   delay(20000);
}

You will notice that the BUSY LED on the DFPlayer is lit, indicating that the module has received the command to play a track, and is in fact doing so.

Conclusions: Serial1 in fact works. And there are no unseen, mysterious communication anomalies with the ESP32. Your problems are elsewhere.

Are the logic voltage levels consistent throughout ? The ESP32 is 3.3v. Otherwise use a level shifter.

Thanks 6v6gt - I hadn't thought of that. The mp3 module may require 5v logic. I just ordered a shifter and I'll give that a try.

Conclusions: Serial1 in fact works. And there are no unseen, mysterious communication anomalies with the ESP32. Your problems are elsewhere.

I'll be happy to try Serial1, but I suspect you're right that the problem is not there.
I am not using a DFPlayer Mini - this is a serial mp3 module from DIYables (DIYables MP3 Player Module for Arduino, ESP32, ESP8266, Raspberry Pi)

I do have a DFPlayer around somewhere and I'll bust that out and try it - it might work fine with the ESP32. Not the problem I'm trying to solve here, however.

Thanks

Don't get hung up on the DFplayer; it's just what I had on hand. And neither the Uno nor the ESP32 knows or cares which module it's talking to.

Did this fix your problem ? Level Shifter

Nope - a level shifter did not fix the problem.

Did you try the DFR player as you said you might six months ago?

And on what Arduino device did your sketch work successfully?

Yes, I purchased a DF Player Mini which also didn’t work, likely for the same reasons. The devices worked with an old Arduino Uno I’ve had for about 10 years.

If i did indeed delete it then it must have been accidentally!

Anyway, I’ll try to restore it when I get time if there’s still any interest from the OP. First paragraph was this:
———
The simple DFR MP3 Player sketch below works as expected on a Uno and Nano. And after appropriate editing it also works on my recently purchased 'ESP32-C3 Development Board'. Hope the pair help in your project.

Take care with pin connections, as they differ across the ESP32 family.