How use Two Ports or softwareserial in arduino ATmega328P

i try to use, two ports in arduino ATmega328p, the first port it control the DFPlayer mini, and the second port, it control Bluetooth module HC-06, but not work, in serial monitor show me this message:

My project Initializing DFPlayer ... (May take 3~5 seconds) Unable to
begin:
1.Please recheck the connection!
2.Please insert the SD card!

but when I delete the Bluetooth code fragment , the project work fine with DFPlayer mini module.

how i would connect two modules, because i try with the sample code of arduino page, but not work for me

#include "Arduino.h"
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"

bool doneFlag = false;


SoftwareSerial mySoftwareSerial(10, 11); // RX, TX
  /*BLUETOOH*/
SoftwareSerial BT(12,13); // RX, TX
  /*BLUETOOH*/

DFRobotDFPlayerMini myDFPlayer;
void printDetail(uint8_t type, int value);

# define ACTIVATED LOW


int btnpuerta = 7;
int btnwelcome = 6;
int btnreload = 8;


void setup()
{

  /*SETUP PARA CADA ACCION EN ARDUINO*/
  pinMode(btnpuerta, INPUT);
  digitalWrite(btnpuerta,HIGH);

  pinMode(btnwelcome, INPUT);
  digitalWrite(btnwelcome,HIGH);

  pinMode(btnreload, INPUT);
  digitalWrite(btnreload,HIGH);


  Serial.begin(115200);
  mySoftwareSerial.begin(9600);
  
  

    /*BLUETOOH*/
   BT.begin(9600);
  
  /*BLUETOOH*/
  


  
  Serial.println();
  Serial.println(F("Escanmotor.com"));
  Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)"));

  
  if (!myDFPlayer.begin(mySoftwareSerial)) {  //Use softwareSerial to communicate with mp3.
    Serial.println(F("Unable to begin:"));
    Serial.println(F("1.Please recheck the connection!"));
    Serial.println(F("2.Please insert the SD card!"));
    while(true);
  }
  Serial.println(F("DFPlayer Mini online."));
  
  myDFPlayer.setTimeOut(500); //Set serial communictaion time out 500ms
  
  //----Set volume----
  myDFPlayer.volume(30);  //Set volume value (0~30).
  myDFPlayer.volumeUp(); //Volume Up
  myDFPlayer.volumeDown(); //Volume Down
  
  //----Set different EQ----
  myDFPlayer.EQ(DFPLAYER_EQ_NORMAL);

  
  //----Set device we use SD as default----

  myDFPlayer.outputDevice(DFPLAYER_DEVICE_SD);

 

  //----Read imformation----
  Serial.println(myDFPlayer.readState()); //read mp3 state
  Serial.println(myDFPlayer.readVolume()); //read current volume
  Serial.println(myDFPlayer.readEQ()); //read EQ setting
  Serial.println(myDFPlayer.readFileCounts()); //read all file counts in SD card
  Serial.println(myDFPlayer.readCurrentFileNumber()); //read current play file number
  Serial.println(myDFPlayer.readFileCountsInFolder(3)); //read file counts in folder SD:/03


}

void loop(){

  /*BLUETOOH*/
    mySoftwareSerial.listen();
    delay(2);
    while (mySoftwareSerial.available() > 0) {
        char inByte = mySoftwareSerial.read();
        Serial.write(inByte);
        delay(1);
    }

    BT.listen();
    delay(2);
    while (BT.available() > 0) {
        char inByte = BT.read();
        Serial.write(inByte);
        delay(1);
    }
  /*BLUETOOH*/


  if (digitalRead(btnpuerta) == ACTIVATED) {
    myDFPlayer.play(1);
    delay(2500);
    }

  if (digitalRead(btnwelcome) == ACTIVATED) {
       if (doneFlag == false) // fragmento para repetir el comando una sola vez
      {
          myDFPlayer.play (5);
          delay (2000);
          myDFPlayer.stop ();
          doneFlag = true;
      }
     
    }

  if (digitalRead(btnreload) == ACTIVATED) {
    doneFlag == true;
    }

}


void printDetail(uint8_t type, int value){
  switch (type) {
    case TimeOut:
      Serial.println(F("Time Out!"));
      break;
    case WrongStack:
      Serial.println(F("Stack Wrong!"));
      break;
    case DFPlayerCardInserted:
      Serial.println(F("Card Inserted!"));
      break;
    case DFPlayerCardRemoved:
      Serial.println(F("Card Removed!"));
      break;
    case DFPlayerCardOnline:
      Serial.println(F("Card Online!"));
      break;
    case DFPlayerUSBInserted:
      Serial.println("USB Inserted!");
      break;
    case DFPlayerUSBRemoved:
      Serial.println("USB Removed!");
      break;
    case DFPlayerPlayFinished:
      Serial.print(F("Number:"));
      Serial.print(value);
      Serial.println(F(" Play Finished!"));
      break;
    case DFPlayerError:
      Serial.print(F("DFPlayerError:"));
      switch (value) {
        case Busy:
          Serial.println(F("Card not found"));
          break;
        case Sleeping:
          Serial.println(F("Sleeping"));
          break;
        case SerialWrongStack:
          Serial.println(F("Get Wrong Stack"));
          break;
        case CheckSumNotMatch:
          Serial.println(F("Check Sum Not Match"));
          break;
        case FileIndexOut:
          Serial.println(F("File Index Out of Bound"));
          break;
        case FileMismatch:
          Serial.println(F("Cannot Find File"));
          break;
        case Advertise:
          Serial.println(F("In Advertise"));
          break;
        default:
          break;
      }
      break;
    default:
      break;
  }
  
}

The serial monitor port is the same port that is available on the TX and RX pins on the board.

So you need two additional serial ports via software,

Or one serial port via software and not use the serial monitor.

It is possible to have multiple software serial ports with speeds up to 115200 bps

Source: https://www.arduino.cc/en/Reference/softwareSerial

do you mean:

  pinMode(btnpuerta, INPUT_PULLUP);
  pinMode(btnwelcome, INPUT_PULLUP);
  pinMode(btnreload, INPUT_PULLUP);

?

what?

is not it?

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