GPS / UART / Passing NMEA strings to RX3 / TX3

Status
Not open for further replies.

Paraglider

Well-known member
There is a GPS wired to RX1 / TX1 (UART) on my Teensy 3.1. And a HM-10 BLE module is wired to RX3 / TX3. Now I would like to read the NMEA strings from RX1/TX1 and pass them directly over to RX3 / TX3 to the BLE module. The idea is to pass the information from the GPS directly to the GPS module, but I also need to extract some data from the GPS using TinyGPS+, do some computation, and then send this result also to the BLE module using RX3 / TX3. That's why the GPS is not directly connected to the BLE module. How can I achieve what I want, and also having the smallest latency possible? Any help to solve that problem is welcome.
 
I think I understand what you're trying to do, please correct me if I'm wrong. What you need, pseudo-code-ish, is the following:

Code:
get a byte from Rx1 (GPS)
write that byte to Tx3 (BT)
also feed TinyGPS with that byte
repeat

and in C++:

Code:
void setup()
{
  Serial1.begin(9600);
  Serial3.begin(9600);
}

void loop()
{
  static TinyGPSPlus gps;
  if(Serial1.available())
  {
    char c = Serial1.read();
    Serial3.write(c);
    gps.encode(c);
    // check GPS state here to get updated data
  }
}
Is that what you're looking for?
 
I think he is trying to read the entire nmea string and do some calculations on the data before sending it to Serial3. I have a library for DMA Hardware Serial that might help with this, do you have any code I can try it out with?
 
Christoph, thanks for your help. Looks like this might work. That's exactly what I try to do. But as duff mentioned I also want to do some calculations with data from the nmea string, that's why it's important to feed also TingyGPSPlus with the NMEA strings. I will try the code over tomorrow or Friday and post the result.
 
Indeed, as I re-read your question, it seems that you want all NMEA sentences to appear on your bluetooth module, but you also want to add your own messages in between. Is that it?
 
I'm making two assumtptions here:

  • You want to insert messages between NMEA sentences
  • TinyGPS parses an NMEA sentnce and updates its internal state after it has validated the checksum

In that case, insert your message like this:
Code:
void setup()
{
  Serial1.begin(9600);
  Serial3.begin(9600);
}

void loop()
{
  static TinyGPSPlus gps;
  if(Serial1.available())
  {
    char c = Serial1.read();
    Serial3.write(c);
    gps.encode(c);
    // if GPS state changed, analyze data
    // send extra string through Serial3
  }
}
 
Tested the code today during a long flight. The code works perfect. The next step will then be do create special NMEA string, or replace information in the NMEA strings with the computed values from the code.
 
Status
Not open for further replies.
Back
Top