Hi there i try to send an recive data by tx an rx.
On the first board i send data by Serial.print (CODE: Serial.print(123, DEC)), at the other board i want to read this data by Serial.read();. so far it works i recive data, but it is not the value i aspekted. At the Serial Monitor at the first screen arduino printed "123", but at the Monitor of the second board i get a totaly diffrent value.
Also if i try to send an read a binary, but value there are no similar values in the string.
Serial.print(123, DEC) sends three bytes of serial data: the characters '1', '2', '3' (e.g. 49, 50, 51). To receive the value on the other board, you'll need to collect these bytes and reassemble them into a value. E.g. each time you get a byte, you want to do something like:
int c = Serial.read();
int digit = c - '0'; // '0' == 48: the ASCII value of the digit 0
value = value * 10 + d;
You'll need to send some sort of terminating character (like a newline) and check for that on the receiving end.
Alternatively, you can just send binary bytes (remember a byte only goes from 0-255) or multiple bytes, but then you won't be able to read the data in the serial monitor.
Ok, i undersand, thanks so far. And i could encode the data. But at least i have one error. If i start to send just one byte nothing happend. To start the communication i had to send 2 or 3 bytes in one Serial.print();. When ist is runnig i can refresh my sending script to one byte only. :-?
Is there any reason why i had to do this, it is a not so good if i had to change the input to start the conversation. Any meanings?
So if i start this two Codes on diffrent boards nothing will happend. i have to chang my value (9215) in 215. When this script is started, the other board begins to read data.
But it is a little bit strange, because if the transmitter-board send or not, the receiver board must print something, for example -1. If i cut the connetion the receiver-boards print -1, but just after i give him a little kick.