Skip to main content
added 532 characters in body
Source Link

TheYour code wasis not reading the software serialSoftwareSerial. b wasb is only populated when the Pi sent data. The loop below sends what it reads from the software serialSoftwareSerial, after that is prints a new line println() (println)only because that's what your code is doing)

The listen() method of SoftwareSerial is only required if you have more than one SoftwareSerial connection.

#include <SoftwareSerial.h>

String b = "0";
SoftwareSerial portOne(2, 3); //RX= pin 2  TX= pin 3

void setup() {
  Serial.begin(9600, SERIAL_8N1); 
  portOne.begin(9600);
} 

void loop() {
  if (Serial.available() > 0) {
    b = Serial.readString();
    Serial.println("Data from RPI:");
  } 

 //not required with only one software serial connection
 //portOne.listen();

  if (portOne.available() > 0)
  {
   while(portOne.available() > 0){
      byte byteRead = portOne.read();
      Serial.write(byteRead);
    }
    Serial.println();
   }
  }

The code was not reading the software serial. b was only populated when the Pi sent data. The loop below sends what it reads from the software serial, after that is prints a new line (println) because that's what your code is doing.

#include <SoftwareSerial.h>

String b = "0";
SoftwareSerial portOne(2, 3); //RX= pin 2  TX= pin 3

void setup() {
  Serial.begin(9600, SERIAL_8N1); 
  portOne.begin(9600);
} 

void loop() {
  if (Serial.available() > 0) {
    b = Serial.readString();
    Serial.println("Data from RPI:");
  }
  portOne.listen();

  if (portOne.available() > 0)
  {
   while(portOne.available() > 0){
      byte byteRead = portOne.read();
      Serial.write(byteRead);
    }
    Serial.println();
   }
  }

Your code is not reading the SoftwareSerial. b is only populated when the Pi sent data. The loop below sends what it reads from the SoftwareSerial, after that is prints a new line println() (only because that's what your code is doing)

The listen() method of SoftwareSerial is only required if you have more than one SoftwareSerial connection.

#include <SoftwareSerial.h>

String b = "0";
SoftwareSerial portOne(2, 3); //RX= pin 2  TX= pin 3

void setup() {
  Serial.begin(9600, SERIAL_8N1); 
  portOne.begin(9600);
} 

void loop() {
  if (Serial.available() > 0) {
    b = Serial.readString();
    Serial.println("Data from RPI:");
  } 

 //not required with only one software serial connection
 //portOne.listen();

  if (portOne.available() > 0)
  {
   while(portOne.available() > 0){
      byte byteRead = portOne.read();
      Serial.write(byteRead);
    }
    Serial.println();
   }
  }
added 532 characters in body
Source Link

You just have to print toThe code was not reading the SoftwareSerial everything that you readsoftware serial. b was only populated when the Pi sent data. The loop below sends what it reads from the software serial, after that is prints a new line Serial(println) because that's what your code is doing.

#include <SoftwareSerial.h>

String whileb = "0";
SoftwareSerial portOne(2, 3); //RX= pin 2  TX= pin 3

void setup() {
  Serial.available>0begin(9600, SERIAL_8N1); 
  {portOne.begin(9600);
} 

void loop() {
  if mySoftSerial(Serial.printavailable() > 0) {
    b = Serial.readreadString();
    Serial.println("Data from RPI:");
  }

or

  whileportOne.listen(Serial);

  if (portOne.available>0available() > 0)
  {
   while(portOne.available() > uint8_t0){
 b     byte byteRead = SerialportOne.read();
     mySoftSerial Serial.printwrite(bbyteRead);
    }
    Serial.println();
   }
  }

You just have to print to the SoftwareSerial everything that you read from the Serial.

  while(Serial.available>0)
  {
     mySoftSerial.print(Serial.read());
  }

or

  while(Serial.available>0)
  {
     uint8_t b = Serial.read();
     mySoftSerial.print(b);
  }

The code was not reading the software serial. b was only populated when the Pi sent data. The loop below sends what it reads from the software serial, after that is prints a new line (println) because that's what your code is doing.

#include <SoftwareSerial.h>

String b = "0";
SoftwareSerial portOne(2, 3); //RX= pin 2  TX= pin 3

void setup() {
  Serial.begin(9600, SERIAL_8N1); 
  portOne.begin(9600);
} 

void loop() {
  if (Serial.available() > 0) {
    b = Serial.readString();
    Serial.println("Data from RPI:");
  }
  portOne.listen();

  if (portOne.available() > 0)
  {
   while(portOne.available() > 0){
      byte byteRead = portOne.read();
      Serial.write(byteRead);
    }
    Serial.println();
   }
  }
Source Link

You just have to print to the SoftwareSerial everything that you read from the Serial.

  while(Serial.available>0)
  {
     mySoftSerial.print(Serial.read());
  }

or

  while(Serial.available>0)
  {
     uint8_t b = Serial.read();
     mySoftSerial.print(b);
  }