IDE 2.2.1, Arduino Uno 3
I'm trying to send some data from 1 Uno to another via a REYAX RYLR998 LORA module. I want this data to be sent 10 times per second. I can receive ok at lower speeds, like 5 per sec but that's it. (FYI the objective is to measure wave height out on a pier with an ultrasonic transducer and display that info several hundred feet away.)
I have condensed my code to a bare minimum to show the problem I'm facing. Here is a picture of a scope trace that demonstrates the problem:
Blue: Transmit data on Rx pin of LORA transmitting module.
Yellow: Receive data on Tx pin of LORA receiving module.
Pink: Pulse sent to piezo device when msg received (receiving Uno).
The first thing that makes no sense is the transmit data. It appears to be broken into 2 sections, one about 12ms in duration and the other around 8ms. Taken together this seems to encompass the full transmit string. Crazy thing is that the receive data (yellow) starts coincident with the start of the 2nd transmit section (the narrow pulse). Coincidence maybe.
Anyway, why am I not seeing the same transmit pulse length on every transmission?
Why are the transmit pulses not 100ms apart?
(I'm going to guess all this has something to do with lora.setTimeout. I have yet to find a detailed explanation of what this does.)
Now I'm going to try and post the code...
// TRANSMITTER CODE, BOATHOUSE
#include <SoftwareSerial.h>
SoftwareSerial lora(2, 3);
// We are unit #1 (boat dock), sending to unit #2 (house).
String boatdock_address = "1"; //Define Lora transmit address (this unit, boat dock).
String house_address = "2"; //Define Lora receiver address (remote unit, house).
void setup()
{
pinMode(LED_BUILTIN, OUTPUT); //Transmit blinker
Serial.begin(115200); //set baud rate to serial monitor.
lora.begin(9600); //Set baud rate for LORA comm.
lora.setTimeout(400); //What is this???
}
void loop()
{
lora.println("AT+SEND=" + house_address + ",5,PIEZO"); // Send "AT+SEND=2,5,PIEZO" +CRLF (19mS)
delay(81); // Trying to get total loop time ~100mS.
}
// RECEIVER CODE, HOUSE
#include <SoftwareSerial.h>
#define piezo 10 //Piezo beeper on pin #10.
String incomingString;
SoftwareSerial lora(2, 3);
// We are unit #2 (house), receiving from unit #1 (boat dock).
// (We never use boatdock_address since we never xmit to boathouse. )
String house_address = "2"; //Define Lora address (this unit, house).
String boatdock_address = "1"; //Define Lora address (remote unit, boat dock).
void setup()
{
pinMode(piezo, OUTPUT);
Serial.begin(115200);
lora.begin(9600);
lora.setTimeout(125);
}
void loop()
{
if (lora.available()) {
incomingString = lora.readString();
char dataArray[30];
incomingString.toCharArray(dataArray,30);
char* data = strtok(dataArray, ",");
data = strtok(NULL, ",");
data = strtok(NULL, ",");
if (strcmp(data,"PIEZO") == 0) {
digitalWrite(piezo, HIGH);
delay(10);
digitalWrite(piezo, LOW);
}
}
}