I tried the Tinkercad simulation with two Arduino Uno's connected RX-TX and TX-RX.
Then I get: 79, 111, 34, 100, 99, 116.
I think that Tinkercad does not support overruling the data at port 0 (RX).
Shall we go through this from the start ?
Which Arduino boards do you use ?
How did you connect them ?
If the Receiver Arduino board has the Serial Monitor open, should the Serial port split itself ? Read data from the other board but send data to the computer ?
It is easier of you allow the Serial Monitor on both (using Serial) and communicate via an other port (for example Serial1).
Can you tell why you want two Arduino boards ? It is easier if you can do your project with a single Arduino board.
horace, Koepel, thank you very much for your replies. Actually, converting integer array into byte one has solved this problem. Thank you very much for your support and attention.
Try modifying your array to include values such as 256, 512, 1024
Then try 257, 513, 1025
Then 258, 514, 1026
See if you can notice a pattern.
If you have a calculator with programmer mode (even windows calculator has this mode), try entering the number in "decimal" mode, then change the calculator to "hexadecimal" mode and see if you can relate what you see in the calculator to what you are getting in the Serial monitor.
Koepel, excuse me, that link which I sent to you has become outdated because I sent it to more than one person. I didn't know such a thing could happen as I am new to TinkerCad. Here is a new one which I updated. It should work: Login | Tinkercad
You could add a delay in the Transmitter sketch to reduce the stream of data a little.
You can remove the delay in the Receiver sketch and remove the: else No data part.
The Receiver sketch should be calling Serial.available() as much as possible. Preferably hundreds times per second. So the Receiver can come in action as soon as something is received. After something is received, the Receiver should return to calling Serial.available() as soon as possible.
Tinkercad has two options: Share a project and then others can change it or give a public link to a project that others can copy. If you see my changes, then anyone can change it with that link
The following sketch (tested on UNO) prints the elements of your int-type array.
void setup()
{
Serial.begin(9600);
}
int arr[5] = {1, 2, 3, 4, 5};
void loop()
{
for (uint8_t i = 0; i < sizeof arr/2; i++)
{
Serial.print(arr[i], DEC);
Serial.print(' ');
}
Serial.println();
delay(1000);
}
Output:
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
Notes: 1. int-type array holds 16-bit (2-byte) for every element/item/member of the array. 2.sizeof operator returns total number of bytes present in the array.
If there is anything wrong, it is on the receiving end, where each byte is being read in individually and the value printed, instead of being read back into an integer array, then the values from the array printed.
Arrived message length is almost known in this case, and it is 25. Considering a space for a null-character, 26 locations of the declared array would be occupied. I don't see any harm to keep the buffer_size argument of the readBytesUntil() method equal to the array_size. Anyway, the following code would be the safe one so that the method terminates before going to the beyond of the array_size. Would appreciate to hear your comment/opinion.
byte m = SUART.readBytesUntil('\n', myData, sizeof myData - 1);
it is for array of 10 bytes? So your code transmit 2.5 times more bytes than needs for data itself?
I think this is a bad advice to novice. The idea of OP's code was more correct than yours.
Converting the binary data to text first and than from text to int again is a very inefficient way to transmit. This is a common novice mistake and should be avoided.
You can send binary with at least 3-byte synchronization pattern, CHKSUM, and information as to the number of bytes in the message. There are various ways of exchanging data with relative merits/demerits.
All possible solutions are useful information for a user. We don't know really which one matches his interest.