Help regarding Two Arduino Rx Tx Serial communication!

Need help regarding Tx Arduino with integer "25" and "32" to Rx Arduino.

/* Tx Arduino sending integer "25", "32" to Rx Arduino

Sketch modified from YouTube
https://www.youtube.com/watch?v=sSJ_GcaNrVU&t=4s
*/

#include <SoftwareSerial.h>
SoftwareSerial softSerial(10,11);

int data1, data2, data3, data4;

void setup() {
  Serial.begin(9600);
  Serial.println();
  Serial.println("Tx Arduino");

  softSerial.begin(9600); // enable Tx
}

void loop() {    
    data1 = 25;
    data2 = 32;
    
 softSerial.print(data1);      softSerial.print("A");
 softSerial.print(data2);      softSerial.print("B");
 softSerial.println("\n");
    
    Serial.print("    ");
    Serial.print(data1);
  	softSerial.write("\n");
    softSerial.write(data1);
    
	delay (1500);
    Serial.println(); 
}

// Rx Arduino receiving integer "25", "32" from Tx Arduino

#include <SoftwareSerial.h>
SoftwareSerial softSerial(2,3);

char c;
String dataIn;
int8_t indexOfA, indexOfB, indexOfC, indexOfD;

String data1, data2, data3, data4;

void setup(){  
  Serial.begin(9600);
  softSerial.begin(9600);
  Serial.println("Rx Arduino");
}

void loop(){
  while(softSerial.available()>0)   {
    c = softSerial.read();

      if(c=='\n') {break;}
      else        {dataIn+=c;}
    }
    
  if(c=='\n')    {
      Serial.println("Serial Available");
      Parse_the_Data();

      Serial.println("Data1 = " + data1);
      Serial.println("Data2 = " + data2);
      Serial.println("===============================================");
      
    // Reset Values
      c=0;
      dataIn="";
    }
}

void Parse_the_Data()	{
  indexOfA = dataIn.indexOf("A");
  indexOfB = dataIn.indexOf("B");

  data1  = dataIn.substring(0, indexOfA);
  data2  = dataIn.substring(indexOfA+1, indexOfB);
}

// Using Tinkercad for doing so.

Sketch modified from YouTube

  • Please expand on your situation.

  • Always show us a good schematic of your proposed circuit.
    Show us good images of your ‘actual’ wiring.

  • In the Arduino IDE, use Ctrl T or CMD T to format your code then copy the complete sketch.
    Use the < CODE / > icon from the ‘posting menu’ to attach the copied sketch.

1 Like

Example 5 seems to be what you're after
https://forum.arduino.cc/t/serial-input-basics-updated/382007/3

That's the wiring.

Hi. Thanx for responding.

I edited the OP to depict the Sketch.

BTW

  • An integer is two bytes.

  • Where did you find this syntax ?
    Okay, you are using String
    Serial.println("Data1 = " + data1);

  • Pin 2 and 3 are already the hardware serial pins
    SoftwareSerial softSerial(2,3);

Yes. As per the YouTube video of having numbers from Tx Arduino to Rx Arduino.

I am duplicating the YouTube with just 4 of 12 data input.

The Serial Monitor is not matching the YouTube, sadly!

I think you should write this to YouTube comment section. Am I wrong?

Keeping the same set, I went for a string "Hello World"

/* Tx Arduino sending integer "25", "32" to Rx Arduino

NOT the Sketch modified from YouTube
https://www.youtube.com/watch?v=sSJ_GcaNrVU&t=4s
*/

#include <SoftwareSerial.h>
SoftwareSerial softSerial(10,11);

int data1, data2, data3, data4;

void setup() {
  Serial.begin(9600);
  Serial.println();
  Serial.println("Tx Arduino");

  softSerial.begin(9600); // enable Tx
}

void loop() {    
    data1 = 25;
    data2 = 32;
    
// Instead of sending "25" and "32" instead sending string  
// softSerial.print(data1);      softSerial.print("A");
// softSerial.print(data2);      softSerial.print("B");
// softSerial.println("\n");
  
softSerial.println("Hello from Tx Arduino!");
  
    Serial.print("    ");
    Serial.print(data1);
    
	delay (5000);
    Serial.println(); 
}

/* Rx Arduino receiving string from Tx Arduino

Project sketch based upon
https://www.makeuseof.com/arduino-mastering-serial-communication/
*/

#include <SoftwareSerial.h>
SoftwareSerial softSerial(2,3);

void setup(){  
  Serial.begin(9600);
  softSerial.begin(9600);
  Serial.println("Rx Arduino");
}

void loop() {
  if (softSerial.available() > 0) {
    String incomingData = softSerial.readString();
    
    Serial.println(incomingData);
    Serial.println("------------------");  
    }
  delay(5000);    
}

The outcome
Tx Arduino
25
25
25 ... (etc)

Rx Arduino
Hello ærom ª¼
ɑե¹½…
¤²‹ë2ÉýÕAª¡º°º´··†…

Hållo fr·[¢áÁrduino!


So is that sketch all right or Tinkercad is not doing it right?

It can be connection issue. Try changing the cables. Also check this out:

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