Newbie Cannot run SoftwareSerial Example in Arduino

Hi,

My objective is to run 2 serial ports concurrently on the BW16. For this purpose I have used a TTL to UART adapter for uploading sketch. Simultaneously I want to use the onboard CH341 based USB port for my second serial port.

For the above, I am using the following slightly modified SoftSerial example for BW16. I am using PUTTY for serial monitor while the Arduino Serial Monitor is being used for sketch upload.

#include <SoftwareSerial.h>

#if defined(BOARD_RTL8722DM)
    SoftwareSerial mySerial(0, 1); // RX, TX
#elif defined(BOARD_RTL8722DM_MINI)
    SoftwareSerial mySerial(2, 1); // RX, TX
#elif defined(BOARD_RTL8720DN_BW16)
    SoftwareSerial mySerial(PB2, PB1); // RX, TX
#elif defined(BOARD_RTL8721DM)
    SoftwareSerial mySerial(3, 4); // RX, TX
#elif defined(BOARD_RTL8720DF)
    SoftwareSerial mySerial(17, 16); // RX, TX
#else
    SoftwareSerial mySerial(0, 1); // RX, TX
#endif


void setup() {
    // Open serial communications and wait for port to open:
    Serial.begin(115200);
    while (!Serial) {
        ; // wait for serial port to connect. Needed for native USB port only
    }

    Serial.println("Goodnight moon!");

    // set the data rate for the SoftwareSerial port
    
    mySerial.begin(4800);
    mySerial.println("Hello, world?");
}

void loop() { // run over and over

        mySerial.write("Hello, world?");
    
    delay(1000);
 Serial.println("Goodnight moon!");
     delay(2000);
}

The sketch output works upto the point <Serial.println(“Goodnight moon!”);> in setup().

However I do not receive any output from <mySerial.println(“Hello, world?”);> ( also in setup() )on the CH341 USB port line on PUTTY.

The environment is Windows 10 on a laptop.

Please help.
Thanks and Regards

Sorry I forgot to mention that I am using the SoftwareSerial.h library that comes with Arduino IDE.

Regards
azhaque

Hi @azhaque,

Can you check on two things?

  1. Check that your wiring connection is correct.

  2. Check that in your Putty setting, the baud rate has been set to 4800.

You should not need to install additional library from the library manager. The SoftwareSerial.h library is part of the SDK.

Thank you.

Thanks Kelvin.


#include <SoftwareSerial.h>

SoftwareSerial mySerial(PB2, PB1); // RX, TX

void setup() {
    // Open serial communications and wait for port to open:
    
    mySerial.begin(4800);
    delay(1000);
    
    Serial.begin(115200);
    while (!Serial) {
    }

    Serial.println("Goodnight moon!");
    mySerial.println("Hello, world?");
}


void loop() { // run over and over
    if (mySerial.available()) {
        mySerial.write(mySerial.read());
    }
}

The modified code given above worked.
Thanks again Kelvin.

azhaque