Difference between SoftwareSerial and Serial

Hi!

I control an mp3 player (mp3-flash-16P) in a project. I tried to send message with SoftwareSerial:

#include "SoftwareSerial.h"

SoftwareSerial mySerial(19,20) ; //on pins 19 20

void setup()
{
    mySerial.begin(9600) ;
}

...

uint8_t play1[8] = { 0x7E, 0xFF, 0x06, 0x22, 0x00, 0x09, 0x05, 0xEF };

for (int i=0; i<8; i++)
    {
        mySerial.write( play1[i]);

    }

Guess what, mp3 module receive the instruction and plays the file.

Now for some reason I want to use hardware serial, so I replaced "mySerial" by "Serial", I connected module Rx on Arduino 1 Tx (and Tx on Arduino 0 Rx). Then nothing, no sound from the module. I see the Tx led blinking on send.

is the way to send hex different in SoftwareSerial and Serial? I also tried with "Serial.print".

I assume that you use Serial.begin() in the sketch

By using pins 0 and 1 you have connected the module to the hardware Serial port in parallel with the output to the PC so it is no wonder that there are problems

post a full sketch demonstrating the issue. for example does this work if you connect your DFPlayer to Serial1

const uint8_t play1[8] = { 0x7E, 0xFF, 0x06, 0x22, 0x00, 0x09, 0x05, 0xEF };

void setup()
{
  Serial1.begin(9600) ;
  Serial1.write(play1, sizeof play1);
}
void loop() {}

if you use Serial, you might have issues uploading and with the Serial monitor if it's open at the same time.

Sure, I use Serial.begin().

I thought it could be a problem, I tried with a power supply

So what happened ?

Just nothing. I see the led blinking but no sound...

I'll try ASAP

Which Arduino board are you using ?

Nano Every

Then you can use Serial1 on pins 0 and 1

Did you try it ?

!!!! edited
sorry, I missed the 1. No I didn't. I'll do that this evening...

I can't find much infos about Serial1, only that it is connected to pins 0,1. So Serial is not? That could be the reason, like my toaster works better when it's plugged...

The original Arduinos such as the Uno and Nano used a Atmega328 chip with a single hardware UART used to communicate with the PC

Some Arduinos, such as the Mega have 4 hardware UARTS named Serial1, Serial2, Serial3 on various pins as well as Serial on pins 0 and and 1

Later Arduino used different chips with built in USB functionality used for Serial and pins 0 and 1 are used for Serial1. This is the case with the Nano Every which often causes confusion because of the common name

Summary (when using the Nano Every) :

  • When you communicate using Serial the data goes to and from the board via the USB lead
  • When you communicate using Serial1 the data goes to and from the board using pins 0 and 1
1 Like

Thank you UKHeliBob for your nice and clear explanation!
serial documentation doesn't mention nano every, only nano, which as you said has a different chip. But I guessed it was the same pinout. I didn't know about Serial1 2 3...

So of course it does work with Serial1!! Thank you for your help and the code J-M-L!

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