'SoftwareSerial' does not name a type; did you mean 'HardwareSerial'?

OK. In my ongoing, (so far totally unsuccessful) attempt to get some sound from my ESP32.....

I'm wanting to connect to a DY-SV17F, to integrate into a working app, running an led strip controlled by an MIT app via bt.

SO... I have installed DYPlayerArduino.h, and am fiddleing around, while beginning, trying to use examples from the DYPlayerArduino designer. And failing at the first post.

This code, from the example:

#include "DYPlayerArduino.h"
#include <SoftwareSerial.h>

// Initialise on software serial port.
SoftwareSerial SoftSerial(10, 11);
DY::Player player(&SoftSerial);

void setup() {
  player.begin();
  // Also initiate the hardware serial port so we can use it for debug printing
  // to the console..
  Serial.begin(9600);
  player.setVolume(15); // 50% Volume
  player.setCycleMode(DY::PlayMode::Repeat); // Play all and repeat.
  player.play();
}

void loop() {

  // Print the number of the sound that is playing.
  Serial.print("Playing sound: ");
  Serial.println((int16_t)player.getPlayingSound());
  delay(500);
}


Results in:

C:\Users\cex\AppData\Local\Temp\.arduinoIDE-unsaved2024215-6600-5ig6k5.xc2bs\SoftwareSerial\SoftwareSerial.ino:7:20: note: suggested alternative: 'Serial'
 DY::Player player(&SoftSerial);
                                ^~~~~~~~~~
                                Serial

exit status 1

Compilation error: 'SoftwareSerial' does not name a type; did you mean 'HardwareSerial'?

Help? I know this shows a lack of understanding for how libraries work, but I'm fairly new to this, I can't find much information on programming for the DY series, and I'm also pretty new to Arduino/ESP32

You should not be using SoftwareSerial. You have an ESP32 which has several available hardware serial (UART) ports. SoftwareSerial should only be used when no hardware serial ports are available.

1 Like

OK. That'll be why, then.
So the problem is with this line:

SoftwareSerial SoftSerial(10, 11);

How do I set hardware serial ports to the same ones, say 10 and 11?

You don't. Their pins are fixed. You must connect your player to those pins.

ESP32 supports great flexibility in UART pin assignments:

Serial2.begin(115200, SERIAL_8N1, rxPin, txPin);
2 Likes

OK. Thank you. I'll give that a go.

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