Edit: We're so close! Update at bottom! I'm not sure if this is the right place to ask, but since you helped my so much in the past, I thought it's worth a try.
So as I stated in my last question, I'm using my Arduino Leonardo to simulate a GPS Receiver.
The Arduino is now connected to a Velodyne VLP-16 LiDAR
And wrote the following code:
#include <SoftwareSerial.h>
SoftwareSerial mySerial(7, 6); //232_TX,232_
int triggerFreq = 1;
unsigned long timestamp;
unsigned long triggerStartTime;
const unsigned long dt = 1000000/triggerFreq; //micros
unsigned long i;
float gprmc = 181721.000;
void setup() {
pinMode(11, OUTPUT); // PPS
pinMode(12, OUTPUT); // Indicator of msg_sent
Serial.begin(9600);
mySerial.begin(9600);
triggerStartTime = micros();
}
void loop() {
timestamp = micros()-triggerStartTime;
if (timestamp>= dt*i+200000)
{
digitalWrite(12,HIGH);
i +=1;
gprmc += 1;
mySerial.print("$GPRMC,");
if (gprmc < 100000) mySerial.print(F("0"));
mySerial.print(gprmc,3);
mySerial.println(F(",A,4042.695,N,07400.796,W,,,080120,000.0,W*63"));
Serial.print("$GPRMC,");
if (gprmc < 100000) Serial.print(F("0"));
Serial.print(gprmc,3);
Serial.println(F(",A,4042.695,N,07400.796,W,,,080120,000.0,W*63"));
digitalWrite(12,LOW);
}
else if (timestamp>=dt*i+100000)
{
digitalWrite(11,LOW);
}
else if (timestamp>=dt*i)
{
digitalWrite(11,HIGH);
}
}
Here's the situation now:
- I'm seeing on the board that the messages are being sent (TX LED flashing)
- I'm also seeing that the pulse is sent correctly (flashing LED)
- I don't measure any voltage on the TX output pin (RS232 pin3) (I'm just using my multimeter, but normally it reacts to such short voltage pulses by blinking an LED)
- I do measure such a pulse on RS232 pin4
- The LiDAR doesn't react to my sent messages
Now my question: Do you see an error in my implementation? Is the message sent correctly?
Thank you sooo much for your help! I'm really appreciating it!
Edit: The LiDAR manual says:
The supported NMEA sentence and syntax are exactly the same as on the wired (serial) GPS interface. Supported sentence delimiter sequences include (HEX 0D0A, the standard), by itself, and by itself.
To be honest I'm not very familiar with these kind of problems so I'm not sure if these delimiters are already being sent?
Edit Nr2: Ok the following situation:
- I'm actually not sure what changed. The code is still the same as above
- The LiDAR now recognizes SOME of the messages (I can only see the position, so I edited the code to change the position a bit every second, and the Lidar updates its position irregularly but approx. all 10 seconds)
- If anyone knows an explanation, I would be very happy to know. Otherwise, I just keep on trying an will keep you updated!
So the following code partially works. That means: the LiDAR recognizes certain messages... it seems like those are always the same messages (i incremented the position every second, these are the positions):
- 3015.2746
- 3015.2766
- 3015.2971
- 3015.3107
- 3015.3117
I displayed all the times when something was sent, and i could not find any differences between the messages that worked and those that didn't work.
One more followup:
If I try to increment pos+=0.0001
, it does not work... it seems like i can only change up to 3 decimals. I don't understand why, since the float uses 4 bytes, so this should be no problem to store?! helpppp
Ok so here is the code for now:
#include <SoftwareSerial.h>
SoftwareSerial mySerial(7, 6); //232_TX,232_
int triggerFreq = 1;
unsigned long timestamp;
unsigned long triggerStartTime;
const unsigned long dt = 1000000/triggerFreq; //micros
unsigned long ts_pps_high;
unsigned long ts_pps_low;
unsigned long ts_msg_high;
unsigned long ts_msg_low;
unsigned long i;
int hh = 04;
int mm = 51;
int ss = 00;
float pos = 3015.2307;
bool msg;
void setup() {
// put your setup code here, to run once:
pinMode(11, OUTPUT); // PPS
pinMode(12, OUTPUT); // Indicator of msg_sent
Serial.begin(9600);
mySerial.begin(9600);
triggerStartTime = micros();
}
void loop() {
timestamp = micros()-triggerStartTime;
if (timestamp>= dt*i+350000)
{
pos +=0.001;
digitalWrite(12,HIGH);
i +=1;
if (ss == 59)
{
ss=0;
if (mm==59)
{
mm=0;
hh+=1;
}
else mm+=1;
}
else ss+=1;
ts_msg_high = micros();
mySerial.print("$GPRMC,");
if (hh<10) mySerial.print(F("0"));
mySerial.print(hh);
if (mm<10) mySerial.print(F("0"));
mySerial.print(mm);
if (ss<10) mySerial.print(F("0"));
mySerial.print(ss);
mySerial.print(".000,A,");
mySerial.print(pos,4);
mySerial.println(",N,09749.2872,W,0.67,161.46,030913,,,A*7C");
// Print Debug Messages
digitalWrite(12,LOW);
ts_msg_low=micros();
Serial.print("PPS at: ");
Serial.print(ts_pps_high);
Serial.print("\t PPS low after: ");
Serial.print(ts_pps_low-ts_pps_high);
Serial.print("\t MSG high after: ");
Serial.print(ts_msg_high-ts_pps_high);
Serial.print("\t MSG low after: ");
Serial.print(ts_msg_low-ts_pps_high);
Serial.print("$GPRMC,");
if (hh<10) Serial.print(F("0"));
Serial.print(hh);
if (mm<10) Serial.print(F("0"));
Serial.print(mm);
if (ss<10) Serial.print(F("0"));
Serial.print(ss);
Serial.print(".000,A,");
Serial.print(pos,4);
Serial.println(",N,09749.2872,W,0.67,161.46,030913,,,A*7C");
}
else if (timestamp>=dt*i+100000)
{
digitalWrite(11,LOW);
if (msg==true)
{
msg = false;
ts_pps_low = micros();
}
}
else if (timestamp>=dt*i)
{
digitalWrite(11,HIGH);
if (msg==false)
{
msg = true;
ts_pps_high = micros();
}
}
}
You can see my output as well:
PPS at: 2001060 PPS low after: 100000 MSG high after: 350016 MSG low after: 427132$GPRMC,045103.000,A,3015.2336,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 3001060 PPS low after: 100004 MSG high after: 350004 MSG low after: 427112$GPRMC,045104.000,A,3015.2346,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 4001056 PPS low after: 100000 MSG high after: 350004 MSG low after: 427116$GPRMC,045105.000,A,3015.2355,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 5001060 PPS low after: 100004 MSG high after: 350004 MSG low after: 427112$GPRMC,045106.000,A,3015.2365,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 6001056 PPS low after: 100004 MSG high after: 350004 MSG low after: 427116$GPRMC,045107.000,A,3015.2375,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 7001060 PPS low after: 100004 MSG high after: 350004 MSG low after: 427120$GPRMC,045108.000,A,3015.2385,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 8001056 PPS low after: 100004 MSG high after: 350020 MSG low after: 427132$GPRMC,045109.000,A,3015.2395,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 9001060 PPS low after: 100000 MSG high after: 350016 MSG low after: 427160$GPRMC,045110.000,A,3015.2404,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 10001052 PPS low after: 100008 MSG high after: 350020 MSG low after: 427164$GPRMC,045111.000,A,3015.2414,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 11001064 PPS low after: 100000 MSG high after: 350020 MSG low after: 427164$GPRMC,045112.000,A,3015.2424,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 12001056 PPS low after: 100008 MSG high after: 350004 MSG low after: 427152$GPRMC,045113.000,A,3015.2434,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 13001056 PPS low after: 99996 MSG high after: 350020 MSG low after: 427164$GPRMC,045114.000,A,3015.2443,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 14001056 PPS low after: 100008 MSG high after: 350008 MSG low after: 427156$GPRMC,045115.000,A,3015.2453,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 15001052 PPS low after: 100004 MSG high after: 350020 MSG low after: 427164$GPRMC,045116.000,A,3015.2463,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 16001052 PPS low after: 100000 MSG high after: 350016 MSG low after: 427164$GPRMC,045117.000,A,3015.2473,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 17001056 PPS low after: 100004 MSG high after: 350020 MSG low after: 427164$GPRMC,045118.000,A,3015.2482,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 18001052 PPS low after: 100000 MSG high after: 350016 MSG low after: 427164$GPRMC,045119.000,A,3015.2492,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 19001056 PPS low after: 100004 MSG high after: 350020 MSG low after: 427160$GPRMC,045120.000,A,3015.2502,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 20001060 PPS low after: 100000 MSG high after: 350004 MSG low after: 427148$GPRMC,045121.000,A,3015.2512,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 21001052 PPS low after: 100004 MSG high after: 350020 MSG low after: 427168$GPRMC,045122.000,A,3015.2521,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 22001064 PPS low after: 100004 MSG high after: 350004 MSG low after: 427148$GPRMC,045123.000,A,3015.2531,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 23001052 PPS low after: 100008 MSG high after: 350020 MSG low after: 427172$GPRMC,045124.000,A,3015.2541,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 24001052 PPS low after: 100008 MSG high after: 350024 MSG low after: 427168$GPRMC,045125.000,A,3015.2551,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 25001056 PPS low after: 100000 MSG high after: 350016 MSG low after: 427168$GPRMC,045126.000,A,3015.2561,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 26001052 PPS low after: 100008 MSG high after: 350024 MSG low after: 427160$GPRMC,045127.000,A,3015.2570,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 27001056 PPS low after: 100000 MSG high after: 350020 MSG low after: 427156$GPRMC,045128.000,A,3015.2580,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 28001060 PPS low after: 100008 MSG high after: 350004 MSG low after: 427144$GPRMC,045129.000,A,3015.2590,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 29001056 PPS low after: 100000 MSG high after: 350020 MSG low after: 427156$GPRMC,045130.000,A,3015.2600,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 30001056 PPS low after: 100004 MSG high after: 350020 MSG low after: 427164$GPRMC,045131.000,A,3015.2609,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 31001056 PPS low after: 100008 MSG high after: 350004 MSG low after: 427148$GPRMC,045132.000,A,3015.2619,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 32001056 PPS low after: 99996 MSG high after: 350012 MSG low after: 427164$GPRMC,045133.000,A,3015.2629,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 33001056 PPS low after: 100008 MSG high after: 350020 MSG low after: 427164$GPRMC,045134.000,A,3015.2639,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 34001056 PPS low after: 100000 MSG high after: 350016 MSG low after: 427164$GPRMC,045135.000,A,3015.2648,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 35001060 PPS low after: 100004 MSG high after: 350000 MSG low after: 427144$GPRMC,045136.000,A,3015.2658,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 36001060 PPS low after: 100000 MSG high after: 350004 MSG low after: 427148$GPRMC,045137.000,A,3015.2668,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 37001060 PPS low after: 100004 MSG high after: 350004 MSG low after: 427144$GPRMC,045138.000,A,3015.2678,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 38001064 PPS low after: 100004 MSG high after: 350004 MSG low after: 427144$GPRMC,045139.000,A,3015.2687,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 39001060 PPS low after: 100008 MSG high after: 350004 MSG low after: 427152$GPRMC,045140.000,A,3015.2697,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 40001052 PPS low after: 100008 MSG high after: 350024 MSG low after: 427160$GPRMC,045141.000,A,3015.2707,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 41001052 PPS low after: 100000 MSG high after: 350016 MSG low after: 427168$GPRMC,045142.000,A,3015.2717,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 42001060 PPS low after: 100004 MSG high after: 350004 MSG low after: 427148$GPRMC,045143.000,A,3015.2727,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 43001056 PPS low after: 100000 MSG high after: 350020 MSG low after: 427164$GPRMC,045144.000,A,3015.2736,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 44001052 PPS low after: 100004 MSG high after: 350020 MSG low after: 427164$GPRMC,045145.000,A,3015.2746,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 45001064 PPS low after: 100004 MSG high after: 350004 MSG low after: 427144$GPRMC,045146.000,A,3015.2756,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 46001052 PPS low after: 100004 MSG high after: 350020 MSG low after: 427172$GPRMC,045147.000,A,3015.2766,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 47001056 PPS low after: 100004 MSG high after: 350020 MSG low after: 427164$GPRMC,045148.000,A,3015.2775,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 48001056 PPS low after: 100000 MSG high after: 350016 MSG low after: 427164$GPRMC,045149.000,A,3015.2785,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 49001060 PPS low after: 100004 MSG high after: 350004 MSG low after: 427144$GPRMC,045150.000,A,3015.2795,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 50001052 PPS low after: 100000 MSG high after: 350016 MSG low after: 427160$GPRMC,045151.000,A,3015.2805,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 51001060 PPS low after: 100004 MSG high after: 350004 MSG low after: 427148$GPRMC,045152.000,A,3015.2814,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 52001056 PPS low after: 100000 MSG high after: 350020 MSG low after: 427164$GPRMC,045153.000,A,3015.2824,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 53001064 PPS low after: 100004 MSG high after: 350000 MSG low after: 427144$GPRMC,045154.000,A,3015.2834,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 54001056 PPS low after: 100004 MSG high after: 350020 MSG low after: 427164$GPRMC,045155.000,A,3015.2844,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 55001060 PPS low after: 100004 MSG high after: 350020 MSG low after: 427172$GPRMC,045156.000,A,3015.2854,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 56001068 PPS low after: 100004 MSG high after: 350000 MSG low after: 427144$GPRMC,045157.000,A,3015.2863,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 57001060 PPS low after: 99996 MSG high after: 350012 MSG low after: 427160$GPRMC,045158.000,A,3015.2873,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 58001064 PPS low after: 100004 MSG high after: 350004 MSG low after: 427148$GPRMC,045159.000,A,3015.2883,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 59001056 PPS low after: 100000 MSG high after: 350024 MSG low after: 427132$GPRMC,045200.000,A,3015.2893,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 60001060 PPS low after: 100004 MSG high after: 350020 MSG low after: 427124$GPRMC,045201.000,A,3015.2902,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 61001064 PPS low after: 100008 MSG high after: 350004 MSG low after: 427116$GPRMC,045202.000,A,3015.2912,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 62001060 PPS low after: 100008 MSG high after: 350008 MSG low after: 427124$GPRMC,045203.000,A,3015.2922,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 63001060 PPS low after: 100012 MSG high after: 350008 MSG low after: 427120$GPRMC,045204.000,A,3015.2932,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 64001052 PPS low after: 100000 MSG high after: 350020 MSG low after: 427136$GPRMC,045205.000,A,3015.2941,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 65001060 PPS low after: 100008 MSG high after: 350004 MSG low after: 427120$GPRMC,045206.000,A,3015.2951,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 66001064 PPS low after: 100000 MSG high after: 349996 MSG low after: 427116$GPRMC,045207.000,A,3015.2961,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 67001060 PPS low after: 100004 MSG high after: 350004 MSG low after: 427120$GPRMC,045208.000,A,3015.2971,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 68001060 PPS low after: 100000 MSG high after: 350004 MSG low after: 427112$GPRMC,045209.000,A,3015.2980,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 69001052 PPS low after: 100004 MSG high after: 350020 MSG low after: 427164$GPRMC,045210.000,A,3015.2990,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 70001064 PPS low after: 100004 MSG high after: 350004 MSG low after: 427136$GPRMC,045211.000,A,3015.3000,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 71001060 PPS low after: 100004 MSG high after: 350004 MSG low after: 427148$GPRMC,045212.000,A,3015.3010,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 72001064 PPS low after: 100004 MSG high after: 350004 MSG low after: 427144$GPRMC,045213.000,A,3015.3020,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 73001056 PPS low after: 100000 MSG high after: 350016 MSG low after: 427164$GPRMC,045214.000,A,3015.3029,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 74001064 PPS low after: 99988 MSG high after: 350004 MSG low after: 427148$GPRMC,045215.000,A,3015.3039,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 75001052 PPS low after: 100000 MSG high after: 350020 MSG low after: 427164$GPRMC,045216.000,A,3015.3049,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 76001060 PPS low after: 100004 MSG high after: 350000 MSG low after: 427144$GPRMC,045217.000,A,3015.3059,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 77001056 PPS low after: 100008 MSG high after: 350004 MSG low after: 427148$GPRMC,045218.000,A,3015.3068,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 78001060 PPS low after: 100008 MSG high after: 350004 MSG low after: 427152$GPRMC,045219.000,A,3015.3078,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 79001052 PPS low after: 100008 MSG high after: 350020 MSG low after: 427164$GPRMC,045220.000,A,3015.3088,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 80001052 PPS low after: 100000 MSG high after: 350016 MSG low after: 427164$GPRMC,045221.000,A,3015.3098,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 81001056 PPS low after: 100008 MSG high after: 350020 MSG low after: 427164$GPRMC,045222.000,A,3015.3107,N,09749.2872,W,0.67,161.46,030913,,,A*7C
PPS at: 82001060 PPS low after: 100000 MSG high after: 350016 MSG low after: 427172$GPRMC,045223.000,A,3015.3117,N,09749.2872,W,0.67,161.46,030913,,,A*7C