I would have a more descriptive title if I wasn't so confused.
The scene: Uno with a JSN-SR04T ultrasonic sensor and a
REYAX RYLR998 LoRa module. Sensor is 4ft above the water looking down to measure wave height, then send to receiver 400ft away. 10 samples/sec.
Nano Every with identical LoRa module + 128x64 OLED to show waves graphically and numerically. This is the receive side.
I've had all pieces of this thing working individually and when putting all the code together in one place things were going fine. Until they weren't. I suddenly started getting alternate readings from the transmit side, one good then one bad. I have reduced the code to a minimum to try to focus on the problem. First the transmitter.
void loop() { // Transmit code.
// First thing we do is sync up to the next 100mS. OK to be accurate here.
while (micros() - ET < 100000) {
}
ET = micros();
digitalWrite(trigPin, LOW);
delayMicroseconds(5);
long duration, feet, inches, distance;
digitalWrite(trigPin, HIGH);
delayMicroseconds(30);
digitalWrite(trigPin, LOW);
digitalWrite(LED_BUILTIN, HIGH);
duration = pulseIn(echoPin, HIGH);
digitalWrite(LED_BUILTIN, LOW);
//Serial.print(duration + " "); //When this line UNcommented, monitor shows random garbage.
duration = duration / 2;
if (duration < 1000) duration = 1000; // Only range data of interest is 2000-6000.
if (duration > 9999) duration = 9999;
lora.println("AT+SEND=" + house_address + ",4," + duration); // Send it (19mS)
Serial.println("AT+SEND=" + house_address + ",4," + duration); // Show what we sent to Lora.
}
And this is the data sent to the LoRa module (duplicated and sent to the monitor):

As you can see, the distance (in uS) alternates with every transmission, from around 1960 to 4360. The 4360 is the correct value (from bouncing off a wall about 4 ft away). I can't blame the sensor since the scope trace clearly shows a steady and accurate pulse width and repetition rate. Shown here:
This is what is received by the receiving LoRa (the isolated number on the left is execution time for the main loop):
And this is the receiving code:
void loop() { // Receive code.
ET = millis(); //For timing the 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, "1000") == 0) {
digitalWrite(piezo, HIGH);
delay(10);
digitalWrite(piezo, LOW);
// //}
//ET = millis() - ET;
Serial.print((millis() - ET)); // Elapsed time for loop, mS.
Serial.print(" ");
Serial.println(incomingString);
}
}
The 1960 distance value is wrong. Should be around 4300. And why isn't the 4300 distance not printing at the monitor at all? (assuming it was received). And why the blank line where the 4300 line should be?
The only #include is SoftwareSerial; both the transmitter and receiver.
I hope I have described the problem clearly. If anyone has any idea of what's going on I would appreciate some suggestions.

