0

I can't read data using SoftwareSerial library, because SoftwareSerial.available() is always 0, no matter what I do.

I'm trying to communicate 2 Arduinos Uno, the 1 Serial (name of the first Arduino Uno) and 2 Serial (name of the second Arduino Uno). The 2 Serial will send data to 1 Serial, and 1 Serial will receive this data through a Software Serial port, and then re-write the data received to Hardware Serial Port, but I can't read this, and when I try to print what is available is software serial port, always shows 0. I know that I can do the otherwise, but I'm testing this, because in my future project I will need to use this software serial port to read input data, so this is just a test.

The pic of my simulation with the circuit is this: Example of the simulation in my circuit.

My code is: For 1 Serial (the data receiver):

#include <SoftwareSerial.h>

SoftwareSerial portOne (7,8);

String str1;

void setup()
{
  // Start the hardware serial port
  Serial.begin(9600);
  portOne.begin(9600);

}

void loop()
{
  while (portOne.available() == 0)
  {
   
  }
  str1 = portOne.readString();
  Serial.println(str1);
}

For 2 Serial (the data sender):

String str;

void setup() 
{   
  Serial.begin(9600);   // put your setup code here, to run once:

}

void loop() 
{   
  Serial.println("Testing from serial port2");   
  delay(2000); 
}

I have already read in another topics of this forums and in the internet, but any of them worked for me.

Thanks in advance.

EDIT 1: I'm only simulating both of Arduinos on Proteus, I don't have the hardware with me right now. The image wasn't clear enough, so I hope this one is better to see the wiring diagram. I'm using Virtual Terminal at the Serial Ports so I'm able to see what is being written at the Serial Ports. New image of the wiring between the 2 Arduino Unos.

  • How should they ever communicate? In your wiring image I don't see any connections between the Arduinos. If that is not thr real wiring diagram, then please show it. Have you connected RX to TX and vice versa? And it seems, that you are currently only using a simulator? Which one are you using? Or do you really use the real hardware? (Thats a big difference) – chrisl Jul 6 at 9:13
  • I'm using Proteus to simulate, because I will only get the hardware in 2 weeks, so I'm trying to finish code before they arrive. Sorry if it isn't clear enough, but in Proteus you can link them with the labels to facilitate the view. I will edit my post with a more clear image with the wiring diagram. – AndBraz Jul 6 at 9:27
  • Don’t the simulated Arduinos need their grounds connected, as they would in reality? – StarCat Jul 6 at 11:01
  • @StarCat Doesn't look like that's even possible in proteus... no GND or power pins. – Majenko Jul 6 at 11:03
  • 1
    I wonder... is SoftwareSerial even possible in simulation...? It barely works on real hardware. – Majenko Jul 6 at 11:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.