Asynchronous transmission with (one) start bit and (one) stop bit (and no parity) is the way Arduino Serial works, so no problem with that.
In your KQ-130F module datasheet, you can see that the pin MODE (pin 8 ) sets the mode of operation.
If MODE is HIGH or unconnected, the mode of operation is Transparent.
If MODE is LOW, the mode of operation is Custom.
In the Transparent mode (MODE = HIGH or unconnected) the module simply echoes on TX pin (pin 7) the bytes received on RX pin (pin 6), but the datasheet warns that in this mode the noise on AC line can generate random bytes at receiving end.
For example, if you transmit the bytes
5A 5A 5A 34 56 78 12 45 67,
the receiving module can receive
FE FD EF 5A 5A 5A 34 56 78 12 45 67 85 DE EF
where the bytes
FE FD EF
at the start and
DE EF
at the end are random bytes generated by noise.
If you use this mode of operation, you need some protocol to skip random bytes.
The Custom mode of operation (MODE = LOW) uses the first byte as data length.
So, in this mode, if you want to transmit the 2 bytes
34 52
you must write the sequence
02 34 52
where the first byte (02) is the length of data bytes.
To summarize, if you use Transparent mode to send a string, very likely the receiving end will read a different string due to random bytes generated by AC line.
On the other hand, if you use Custom mode, you need to send the length of the string before sending the actual string, and in the receiving end you must read the first byte as string length, and then read the string bytes.
Here my tentative blocking routines for writing and reading strings in Custom mode
// you can change MAX_LEN to any value < 250
#define MAX_LEN 80
#define IO_FAILURE 0 // write or read operation failure
#define IO_SUCCESS 1 // write or read operation success
int writeStringCustomMode(String &txt)
{
int len = txt.length();
if (len > MAX_LEN)
return IO_FAILURE;
Serial1.write(len);
Serial1.write(txt.c_str(),len);
Serial1.flush();
return IO_SUCCESS;
}
char bufString[MAX_LEN + 1];
// read from Serial1 and save the string in the bufString buffer
int readByte()
{
while(Serial1.available() < 1)
;
return Serial1.read();
}
int readStringCustomMode()
{
int len, ch;
len = Serial1.read();
bool discardInput = len > MAX_LEN;
for(int i=0; i<len; i++)
{
ch = readByte();
if (!discardInput)
bufString[i] = ch;
}
if (!discardInput)
bufString[len] = 0;
else
bufString[0] = 0;
return discardInput ? IO_FAILURE : IO_SUCCESS;
}
before using readStringCustomMode() check if Serial1.available() > 0