How to view software serial data on a serial monitor

I would like to see the data output from the software serial on the serial monitor. I have tried several different ways and it does not work. What is wrong?

I tried it with Arduino UNO and Thinkercad simulator but it failed in both cases.

PS: Thanks for pointing this out. I have removed the screenshot.

#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 3); //RX TX 

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

void loop() {
 
 Serial.println("Goodnight moon!");
 mySerial.println("imSoftware");

}
#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 3); //RX TX 

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

void loop() {
  
 mySerial.print("imSoftware");
 Serial.println(mySerial.read());
 

}

How’s your hardware set up, what interface are you using?

How’s your hardware set up, what interface are you using?

Based on his screen, it looks like that he is using Tinkercad to simulate an Arduino project.

Try:

if(mySerial.available())
{
   Serial.print(char(mySerial.read());
}

What is sending the serial data? Post a wiring diagram, please.

Please do not post screenshots of code. Read the forum guidelines to see how to properly post code and some good information on making a good post.

Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.

Please go back and fix your original post.

Connect two UNOs or UNO/NANO as per Fig-1 and then perform your experiments.


Figure-1:

Notes:
1. When you type say A in the InputBox of SM2 and click on the Send Button, the character automatically arrives into the Serial Buffer of UNO-1.

2. Now you check by including the following codes in your UNO-1's sketch that the character A has really arrived into the BUFFer and then read it and then show it on SM1.

byte n = SUART.available();  //checking if character has arrived or not
if(n != 0)   //n is non-zero means that at least one character has arrived.
{
     char y = SUART.read();  //bring the character from BUFFer into variable y
     Serial.println(y);    //SM1 will show A
}

3. You need to upload the following sketch in UNO-2.

#include<SoftwareSerial.h>
SoftwareSerial SUART(2, 3); //SRX, STX

void setup()
{
     Serial.begin(9600);
     SUART.begin(9600);
}

void loop()
{
     SUART.println('A');
     delay(1000);
}

I only have one Arduino and I would like to try using ThinkerCad.
What is InputBox? I don't know how to input... :smiling_face_with_tear:

I tried using Arduino UNO and ThinkerCAD simulator :grinning:

Only talking about hardware and the Arduino IDE (I have no knowledge of TinkerCAD).

To be able to see the output of a software serial directly in the IDE's serial monitor (or other terminal program) you have to connect the pins used for the software serial to the PC. You can do this with a (often called) FTDI cable / adapter that converts the (software) serial output to USB; when you connect that adapter to the PC, you get a new serial device that you can view with e.g. serial monitor.

There are other solutions (RS232 etc) but you need that additional connection.

Thanks for pointing that out! I have corrected the post.
I tried the following code, but it gave me an error :smiling_face_with_tear:

#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 3); //RX TX 

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

void loop() {
  
 mySerial.print("imSoftware");

if(mySerial.available())
{
   Serial.print(char(mySerial.read());
}
 

}

See below in Fig-1:


Figure-1:

My bad, i omitted a closing parenthesis in the Serial print.
Make it:
Serial.print(char(mySerial.read()));

In the future, please include the entire error message. It is easy to do. There is a button (lower right of the IDE window) called "copy error message". Copy the error and paste into a post in code tags. Paraphrasing the error message leaves out important information.

Only in 1.8.19 and older. IDE 2.0 does not have that button but you can right click in the output windows and click on 'copy all'.

1 Like

Thanks, I did not know, having never used the version 2 IDE.

Traditionally, the cast is enclosed by "pair of parentheses".

Serial.print((char)mySerial.read());

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