can not use SoftwareSerial.h in arduino due

i can not use SoftwareSerial in arduino due

sketch_jun13a:5:28: fatal error: SoftwareSerial.h: No such file or directory

 #include <SoftwareSerial.h>

                            ^

compilation terminated.

exit status 1
SoftwareSerial.h: No such file or directory

as

this topic

Adafruit SAMD Boards doesn’t include a SoftwareSerial

so what is the solution for this code:

#define RX 11 //depends on datasheet
#define TX 10 //depends on datasheet
#define pinLED 13

#include <SoftwareSerial.h>

SoftwareSerial bluetooth(TX, RX);

void setup() {

  bluetooth.begin(9600);
  bluetooth.println("AIPT, test BLE4.");
 
  Serial.begin(9600);
  Serial.println("AIPT, test BLE4.");

  pinMode(pinLED, OUTPUT);
}

void loop() {

  byte BluetoothData;

  if (bluetooth.available() > 0) {
   
    BluetoothData=bluetooth.read();
    
    switch (BluetoothData) {
     
      case '0':    
        digitalWrite(pinLED, LOW);
        bluetooth.println("led off");
        break;
      case '1':
        digitalWrite(pinLED, HIGH);
        bluetooth.println("led on");
        break;
      case '2':
        bluetooth.println("Proccening..");
        digitalWrite(pinLED, 0);
        delay(200);
        digitalWrite(pinLED, 1);
        delay(200);
        digitalWrite(pinLED, 0);
        delay(200);
        digitalWrite(pinLED, 1);
        delay(200);
        bluetooth.println("this is our hash");
        digitalWrite(pinLED, 0);
        break;
      case 'a':
  
        bluetooth.print("launch time ");
        bluetooth.print(millis()/1000);
        bluetooth.println(" s.");
        break;
      case 'b':
     
        bluetooth.print("message: ");
        BluetoothData=bluetooth.read();
 
        while (bluetooth.available() > 0) {
          bluetooth.write(BluetoothData);
          Serial.write(BluetoothData);
     
          delay(10);
          BluetoothData=bluetooth.read();
        }
        bluetooth.println();
        break;
      case '\r';
        break;
      case '\n':
        break;
      default:
        bluetooth.println("unknow command");
    }
  }

  delay(100);
}

The Due has four unused hardware serial ports (Serial, Serial1, Serial2, Serial3), so there is really no need for a software serial library. Since hardware serial is far superior, you should always use it instead of software serial if possible. So just connect your Bluetooth module to one of the serial ports, then change your code to use that serial port instead of the software serial one.

I've deleted your other cross-post @arashsoft. I notice you've done this repeatedly.

Cross-posting is against the rules of the forum. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend 15 minutes (or more) writing a detailed answer on this topic, without knowing that someone else already did the same in the other topic.

Repeated cross-posting will result in a suspension from the forum.

In the future, please take some time to pick the forum board that best suits the topic of your question and then only post once to that forum board. This is basic forum etiquette, as explained in the sticky "How to use this forum - please read." post you will find at the top of every forum board. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

pert:
The Due has four unused hardware serial ports (Serial, Serial1, Serial2, Serial3), so there is really no need for a software serial library. Since hardware serial is far superior, you should always use it instead of software serial if possible. So just connect your Bluetooth module to one of the serial ports, then change your code to use that serial port instead of the software serial one.

oh tnx how can i change my code for that?

#include <SoftwareSerial.h>

SoftwareSerial bluetooth(TX, RX);

(deleted)

spycatcher2k:

#include <SoftwareSerial.h>

SoftwareSerial bluetooth(TX, RX);







#include define bluetooth Serial1




remove the 2nd line from above, the rest of your code should remain the same.

thanks
and which port should i use for rx tx (serial 1)

scl1 and sda1?

(deleted)

(deleted)

I seem to recall, that with a bit of a fiddle, the DUE has a fifth hardware serial port.

I seem to recall, that with a bit of a fiddle, the DUE has a fifth hardware serial port.

That’s right, I dug out this old sketch that implements Serial4 on the Arduino Due’s unused fifth serial port. Transmit (Tx) is on analog pin A11 and receive (Rx) is on digital pin D52. The test code simply echos back characters entered from the Arduino IDE’s console:

// Use the Arduino Due core to set-up the unused USART2 for Serial4 on pins A11 (Tx) and D52 (Rx) 
RingBuffer rx_buffer5;
RingBuffer tx_buffer5;
USARTClass Serial4(USART2, USART2_IRQn, ID_USART2, &rx_buffer5, &tx_buffer5);
//void serialEvent4() __attribute__((weak));
//void serialEvent4() { }

void USART2_Handler(void)   // Interrupt handler for UART2
{
  Serial4.IrqHandler();     // In turn calls on the Serial4 interrupt handler
}

void setup() {
  PIO_Configure(PIOB, PIO_PERIPH_A, PIO_PB20A_TXD2 | PIO_PB21A_RXD2, PIO_DEFAULT);    // Configure the Tx and Rx pins
  Serial4.begin(115200);                                                              // Start the serial port
}

void loop() {
  if (Serial4.available())             // Check if incoming data is available
  {
    byte byteRead = Serial4.read();    // Read the most recent byte  
    Serial4.write(byteRead);           // Echo the byte back out on the serial port
  }
}