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
Hi. Thanx for responding.
I edited the OP to depict the Sketch.
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!
kmin
May 15, 2024, 9:55pm
9
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:
system
Closed
February 9, 2025, 5:47pm
12
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.