Hi, I've been trying to construct a triggering system using a LiDAR Lite-V3 and two nRF24L01+PA+LNA 2.4GHz RF Wireless Modules. LiDAR and one of the RF TX are mounted on the roof of a vehicle and controlled by an Arduino UNO, while the RF RX is stationary at around 140m away controlled by an Arduino NANO.
The issue i'm having is that when I test the system at short range with both systems connected to one computer, my timestamp values from the RX are consistently earlier than the timestamp values from the TX, which means that the NANO is receiving the information before it can even send.
I tried running a simple counter++ code with a delay(1000), and it consistently gives me a latency from anywhere between 10 to 100ms. Since I'm working with RF and LiDAR, I'm working with a margin in the 10's of milliseconds. I've included the code, as well as the negative latency issue between the two systems. If anyone knows what the hell is going on any help would be appreciated!
//UNO Code
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(9 , 10); // Creates radio named 'radio', pins(CE,CSN)
const byte address[6] = "00001"; // Byte of array representing the 1 address to transmit data to
int led_pin = 7;
int triggeredCounter = 0;
unsigned long Distance; // Measured in cm
bool triggered = LOW;
int timeDelay = 0;
LIDARLite myLidarLite;
void setup() {
Serial.begin(115200); // Initialize serial communications, baudrate;
printf_begin();
radio.begin(); // Start nRF24L01 radio
radio.setRetries(1, 15); // Wait 250 microsec between each retry, retry 15x
radio.setChannel(108); // Set RF channel, can operate from 2.4GHz to 2.524Gz, channels above 100 are usually above Wifi
radio.setPALevel(RF24_PA_MAX); // Set power amplifier level to max
radio.openWritingPipe(address); // Set transmitting addresss
radio.stopListening(); // Set module as transmitter always
radio.setCRCLength(RF24_CRC_16); // Set CRC Length to 16 bit
radio.printDetails();
myLidarLite.begin(1, true); //set config to default and I2C to 400kHz, starts I2C
myLidarLite.configure(1); //there are 6 different configs available, default is 0
pinMode(led_pin, OUTPUT);
Serial.println("Setup Complete, Ready to Transmit");
}
void loop() {
radio.write(&triggeredCounter, sizeof(triggeredCounter));
Serial.println(triggeredCounter);
triggeredCounter++;
delay(1000);
}
//NANO Code
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <RF24_config.h>
#include <printf.h>
RF24 radio(9 , 10); // CE, CSN // assign pins for radio
const byte address[6] = "00001";
int led_pin = 3;
int triggered = 0;
void setup() {
Serial.begin(115200); // Initialize serial communications, baudrate
printf_begin();
radio.begin();
radio.setChannel(108); // Set RF channel, can operate from 2.4GHz to 2.524Gz, channels above 100 are usually above Wifi
radio.setPALevel(RF24_PA_MAX); // Max Power Amplifier for max distance between TX/RX
radio.openReadingPipe(0, address); // Set receiving address
radio.startListening(); // Constantly set as receiver
radio.setCRCLength(RF24_CRC_16); // Set CRC length to 16 bit
radio.printDetails();
pinMode(led_pin, OUTPUT);
Serial.println("Setup Complete, Ready to recieve");
}
void loop() {
if (radio.available()) { // Loking for data
radio.read(&triggered, sizeof(triggered)); // Read boolean state of triggered
Serial.println(triggered);
/* if (triggered == 1 ) {
digitalWrite(led_pin, HIGH);
Serial.println("Trigger signal was received");
}
else {
digitalWrite(led_pin, LOW);
}*/
}
}

