[SOLVED] Use only TX with ESP32 Hardware Serial

Hello there, I Am currently building a project with an ESP32 CAM and a Few Modules. I want to connect a DFPlayer Mini MP3 Player Module (Which uses Serial communication) to the ESP32 CAM.
However, due to lack of pins, I only want to send data to the DFPlayer but don't need to receive data from it, hence I only need a TX pin on the ESP32 CAM and I want to leave the RX pin free for use as a GPIO. Could someone guide me as to how this can be done With either Hardware Serial or Software Serial?
This is the code I am trying to use (not working) and I want to initialize only the TX pin. what changes should I make to get this to work? (i have not used the DFRobotDFPlayer Library in this sketch).

#include <Arduino.h>
#define Start_Byte 0x7E
#define Version_Byte 0xFF
#define Command_Length 0x06
#define End_Byte 0xEF
#define Acknowledge 0x00 //Returns info with command 0x41 [0x01: info, 0x00: no info]
#define ACTIVATED LOW

// There is no RX Pin Here.
int TXD = 14; 

boolean isPlaying = false;

void execute_CMD(byte CMD, byte Par1, byte Par2)
// Excecute the command and parameters
{
  // Calculate the checksum (2 bytes)
  word checksum = -(Version_Byte + Command_Length + CMD + Acknowledge + Par1 + Par2);
  // Build the command line
  byte Command_line[10] = {Start_Byte, Version_Byte, Command_Length, CMD, Acknowledge,
                           Par1, Par2, highByte(checksum), lowByte(checksum), End_Byte};
  //Send the command line to the module
  for (byte k = 0; k < 10; k++)
  {
    Serial2.write(Command_line[k]);
    //Serial.write(Command_line[k]);
  }
}

void setVolume(int volume)
{
  execute_CMD(0x06, 0, volume); // Set the volume (0x00~0x30)
}

void playFirst()
{
  execute_CMD(0x3F, 0, 0);
  setVolume(25);
  execute_CMD(0x03, 0, 1);

}

void pauseDF()
{
  execute_CMD(0x0E, 0, 0);
  delay(500);
}

void play()
{
  execute_CMD(0x0D, 0, 1);
  delay(500);
}

void playNext()
{
  execute_CMD(0x01, 0, 1);
}

void playPrevious()
{
  execute_CMD(0x02, 0, 1);
  delay(500);
}

void setup()
{
  Serial.begin(115200);
  Serial2.begin(9600, SERIAL_8N1, TXD); //Will this Work?
  //Serial.begin(9600);
  Serial.println("initialized");
  playFirst();
}
void loop()
{
  while (Serial.available() == 0)
  {
  }
  String msg = Serial.readString();
  if(msg == "prev"){
    playPrevious();
  }
  if (msg == "next")
  {
    playNext();
  }
  if(msg == "pause"){
    pauseDF();
  }
  if (msg == "resume")
  {
    play();
  }
}

This topic is very similar Using only TX of SoftwareSerial, leaving RX pin free - Project Guidance - Arduino Forum but does not work for the ESP32.
Thank you for your Help! :slight_smile:

P.S i have tried digging into the HardwareSerial.cpp and esp32-hal-uart.c files and it seems like send-only hardware serial communication is supported? Nevertheless, my (tested to be functional DFPlayer) is not working with my ESP32 CAMs TX.

Solved by inserting -1 into the RX pin parameter instead of leaving it blank.

Went From This (Non-Functional)

Serial2.begin(9600, SERIAL_8N1, TXD); //This doesnt Work! :(

To This (Functional)

Serial2.begin(9600, SERIAL_8N1, -1, TXD); //This Works! :)

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.