Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for LS20031 GPS module. #5718

Merged
merged 1 commit into from
Jan 3, 2025

Conversation

alexmarkley
Copy link
Contributor

Adds support for the LOCOSYS LS20031 66-Channel GPS Receiver Module. Confirmed working via linux-native on a Raspberry Pi.

Jan 01 18:45:57 indelible-base meshtasticd[5424]: DEBUG | 23:45:51 57 [GPS] Probe for GPS at 57600
Jan 01 18:45:57 indelible-base meshtasticd[5424]: DEBUG | 23:45:51 57 [GPS] Trying $PDTINFO (UC6580)...
Jan 01 18:45:57 indelible-base meshtasticd[5424]: DEBUG | 23:45:51 57 [GPS] Trying $PDTINFO (UM600)...
Jan 01 18:45:57 indelible-base meshtasticd[5424]: DEBUG | 23:45:52 58 [GPS] Trying $PCAS06,1*1A (ATGM336H)...
Jan 01 18:45:57 indelible-base meshtasticd[5424]: DEBUG | 23:45:52 58 [GPS] Trying $PCAS06,1*1A (ATGM332D)...
Jan 01 18:45:57 indelible-base meshtasticd[5424]: DEBUG | 23:45:53 59 [GPS] Trying $PAIR021*39 (AG3335)...
Jan 01 18:45:57 indelible-base meshtasticd[5424]: DEBUG | 23:45:53 59 [GPS] Trying $PAIR021*39 (AG3352)...
Jan 01 18:45:57 indelible-base meshtasticd[5424]: DEBUG | 23:45:54 60 [GPS] Trying $PQTMVERNO*58 (LC86)...
Jan 01 18:45:57 indelible-base meshtasticd[5424]: DEBUG | 23:45:54 60 [GPS] Trying $PCAS06,0*1B (L76K)...
Jan 01 18:45:57 indelible-base meshtasticd[5424]: DEBUG | 23:45:55 61 [GPS] Trying $PMTK605*31 (L76B)...
Jan 01 18:45:57 indelible-base meshtasticd[5424]: DEBUG | 23:45:55 61 [GPS] Trying $PMTK605*31 (PA1616S)...
Jan 01 18:45:57 indelible-base meshtasticd[5424]: DEBUG | 23:45:56 62 [GPS] Trying $PMTK314,-1*04 (LS20031)...
Jan 01 18:45:57 indelible-base meshtasticd[5424]: INFO  | 23:45:56 62 [GPS] LS20031 detected, using GNSS_MODEL_LS20031 Module
Jan 01 18:45:57 indelible-base meshtasticd[5424]: DEBUG | 23:45:56 62 [GPS] Publish pos@0:2, hasVal=0, Sats=0, GPSlock=0
Jan 01 18:45:57 indelible-base meshtasticd[5424]: DEBUG | 23:45:56 62 [GPS] No GPS lock
Jan 01 18:45:57 indelible-base meshtasticd[5424]: DEBUG | 23:45:56 62 [GPS] onGPSChanged() pos@0 time=1735775156 lat=0 lon=0 alt=0
====SNIP====
Jan 01 18:45:57 indelible-base meshtasticd[5424]: DEBUG | 23:45:56 62 [GPS] NMEA GPS time 2025-01-01 23:45:57 age 0
Jan 01 18:45:57 indelible-base meshtasticd[5424]: DEBUG | 23:45:56 62 [GPS] Upgrade time to quality GPS
Jan 01 18:45:57 indelible-base meshtasticd[5424]: DEBUG | 23:45:57 62 [GPS] Read RTC time as 1735775157
Jan 01 18:45:57 indelible-base meshtasticd[5424]: DEBUG | 23:45:57 62 [GPS] hasValidLocation RISING EDGE
Jan 01 18:45:57 indelible-base meshtasticd[5424]: DEBUG | 23:45:57 62 [GPS] Took 62s to get lock
Jan 01 18:45:57 indelible-base meshtasticd[5424]: DEBUG | 23:45:57 62 [GPS] Predict 0s to get next lock
Jan 01 18:45:57 indelible-base meshtasticd[5424]: DEBUG | 23:45:57 62 [GPS] 120s until next search
Jan 01 18:45:57 indelible-base meshtasticd[5424]: INFO  | 23:45:57 62 [GPS] GPS power state move from ACTIVE to HARDSLEEP
Jan 01 18:45:57 indelible-base meshtasticd[5424]: DEBUG | 23:45:57 62 [GPS] Publish pos@6775d3b5:2, hasVal=1, Sats=8, GPSlock=1
Jan 01 18:45:57 indelible-base meshtasticd[5424]: DEBUG | 23:45:57 62 [GPS] New GPS pos@6775d3b5:3 lat=(REDACTED) lon=(REDACTED) alt=239 pdop=1.31 track=354.21 speed=0.00 sats=8
Jan 01 18:45:57 indelible-base meshtasticd[5424]: DEBUG | 23:45:57 62 [GPS] onGPSChanged() pos@6775d3b5 time=1735775157 lat=(REDACTED) lon=(REDACTED) alt=239
Jan 01 18:46:01 indelible-base meshtasticd[5424]: INFO  | 23:45:57 62 [GPS] updatePosition LOCAL pos@6775d3b5 time=1735775157 lat=(REDACTED) lon=(REDACTED) alt=239
Jan 01 18:46:01 indelible-base meshtasticd[5424]: DEBUG | 23:45:57 62 [GPS] Set local position: lat=(REDACTED) lon=(REDACTED) time=1735775157 timestamp=1735775157

Datasheet: https://cdn.sparkfun.com/datasheets/GPS/LS20030~3_datasheet_v1.3.pdf

@fifieldt
Copy link
Contributor

fifieldt commented Jan 2, 2025

Thanks for this!

We'll merge this first, but there's a follow-up step to add code to the setup function - turn off unneeded NMEA messages etc.

@fifieldt
Copy link
Contributor

fifieldt commented Jan 2, 2025

Actually, PMTK314 is PMTK_API_SET_NMEA_OUTPUT?

If so, is that the most appropriate as a detection command?

@fifieldt fifieldt self-requested a review January 2, 2025 00:32
src/gps/GPS.cpp Outdated Show resolved Hide resolved
@fifieldt
Copy link
Contributor

fifieldt commented Jan 2, 2025

Probable source of all relevant commands: http://www.adafruit.com/datasheets/PMTK%20command%20packet-Complete-C39-A01.pdf

@alexmarkley
Copy link
Contributor Author

Actually, PMTK314 is PMTK_API_SET_NMEA_OUTPUT?

If so, is that the most appropriate as a detection command?

The reason I picked it is because it is the command to reset the NEMA output to factory defaults. In the datasheet I linked, it specifies the response we should get, $PMTK001,314,3*36<CR><LF>, which matches my testing.

$PMTK605*31

Might be more appropriate here. Does it work?

Seems to! Updated commit incoming...

@fifieldt
Copy link
Contributor

fifieldt commented Jan 3, 2025

Thanks @alexmarkley

I apologise the gps.cpp file is so long; here's why I asked for that change:

In the probe function ( GnssModel_t GPS::probe(int serialSpeed) ) we're just concerned with determining which specific chip we have. If you read up from line 1193, you'll see we're issuing all sorts of software/hardware version commands to try and get a response the tells us which specific chip we're talking to.

Then, in the setup function (bool GPS::setup()), you'll see a whole bunch of lines where we branch on the detected model (eg GNSS_MODEL_MTK). Inside those branches we issue commands to configure the GPS.

Since you're working on a Raspberry Pi, you have a lot of resources to play with so switching on everything works. On many other devices there isn't enough capacity to handle the full stream of all NMEA messages. So, in the setup function we disable all but RMC and GGA, as well as performing configuration like enabling constellations.

So, where to from here?

1. Explicit Detect String
If possible, it would be good to make the detect string for the LS20031 more explicit, to avoid accidentally matching other chips that support that command. We search the entire response string, so it might be as simple as just putting in the Product Model :)

Looking at the docs for the PM705 response, it looks like after the ReleaseStr and Build_ID is the Product Model (QUECTEL-76 in this case):

$PMTK705,AXN_3.10_3333_12102201,0000,QUECTEL-L76,*18

NB: Just in case you haven't tried already , #define GPS_DEBUG 1 in your variant.h will print out all of the messages going between the Pi and the GPS.

2. Add Setup Commands
I suggest taking a look at the setup for GNSS_MODEL_MTK_L76B and trying that on your GPS.

It has a slightly different PMTK314 command to the one you used before as well as some other useful commands that will improve the performance of your chip if it works :)

If, comparing the documentation and the responses obtained from the GPS running the setup code, everything looks like it works same as GNSS_MODEL_MTK_L76B, then maybe we can just treat the LS20031 as a GNSS_MODEL_MTK_L76B. If it's different, then we add the relevant commands in the setup function for the LS20031.

If, of course, you're busy or not really interested in this work, let us know and we'll run with your already excellent start :)

@alexmarkley
Copy link
Contributor Author

alexmarkley commented Jan 3, 2025

  1. Explicit Detect String

I can confirm the full response I get back from $PMTK605*31 is $PMTK705,AXN_2.30_3339_13080900,45B1,MC-1513,*79.. (the last bytes are presumably <CR><LF>).

I'd like to avoid matching on the firmware version details, which is why I put the first part of the string in there. But as you expected the device reports a product model at the end.

So to confirm @fifieldt you'd prefer to look for MC-1513 as the match response?

  1. Add Setup Commands

Based on your explanation, I understand why there is so much hardware-specific code in here! Unfortunately I'm starting a new job on Monday (and trying to get some things done around the house before that) so my time to work on this is pretty limited right now.

I'm happy to help with testing patches if that would be beneficial. I'm also happy to test the setup code block for GNSS_MODEL_MTK_L76B on this device, but I would need guidance on how to validate if the commands issued in the setup block had the desired effect.

@alexmarkley
Copy link
Contributor Author

Confirmed the GPS module works if we probe for MC-1513 as the match response.

@fifieldt
Copy link
Contributor

fifieldt commented Jan 3, 2025

Excellent, thanks @alexmarkley . Let's merge this and I'll try something for the setup code and send to you for testing :)

Congratulations on your first patch!

@fifieldt fifieldt merged commit 9afadde into meshtastic:master Jan 3, 2025
49 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants