[Digi-Key Follow me Issue 1] -4- Realizing the positioning function
[Copy link]
This post was last edited by Murong Xuehua on 2023-6-6 11:28
1. Basic introduction of Air530 positioning module
This GPS module is the main reason why I participated in this FOLLOW-ME event. The GPS module used this time is Air530 launched by Seeed, which not only supports GPS, but also China's Beidou, including: GPS / Beidou / Glonass / Galileo / QZSS / SBAS.
The relevant parameters are as follows:
- Supply voltage 3.3V/5V
- Working current up to 60mA
- Interface UART
- Time of warm start 4s
- Time of cold boot 30s
The module has 4 pins, namely:
GND |
Grounding |
TX |
Serial port sending |
RX |
Serial port receiving |
VCC |
power supply |
Hardware connection diagram:
2. GPS Data Analysis
The following is the core of this article, which is mainly about how to parse the positioning information from the received data.
In fact, by reading UART data, you can find that there are many formats of satellite data that can be obtained.
$GNGGA: GPS/Beidou positioning information
$GNGSA: Current satellite information
$GPGSV: Visible GPS satellite information
$BDGSV: Visible Beidou satellite information
$GNRMC: Recommended positioning information
$GNVTG: Ground speed information
$GNGLL: Geodetic coordinate information
$GNZDA: Current time UTC (1) information
This article selects one of them: GNGLL.
$GNGLL,<1>,<2>,<3>,<4>,<5>,<6>,<7>*<8><CR><LF>
<1>Latitude ddmm.mmmm, degree-minute format (if the leading digit is insufficient, fill in 0)
<2>Latitude N (North Latitude) or S (South Latitude)
<3>Longitude dddmm.mmmm, degree-minute format (if the leading digit is insufficient, fill in 0)
<4>Longitude E (East Longitude) or W (West Longitude)
<5>UTC time, hhmmss.sss format
<6>Status, A=positioning, V=unpositioned
<7>Mode indication, A-automatic mode; D-differential mode; E-estimate (dead reckoning) mode; M-manual
input mode; S-simulator mode
< 8>Checksum
The main code is as follows:
def getGPS(gpsModule):
global FIX_STATUS, TIMEOUT, latitude, longitude, satellites, GPStime
timeout = time.time() + 8
while True:
gpsModule.readline()
buff = str(gpsModule.readline())
parts = buff.split(',')
print(buff)
if (parts[0] == "b'$GNGLL" and len(parts) == 8):
if(parts[1] and parts[2] and parts[3] and parts[4] and parts[5] and parts[6] and parts[7]):
print(buff)
latitude = convertToDegree(parts[1])
if (parts[2] == 'S'):
latitude = -latitude
longitude = convertToDegree(parts[3])
if (parts[4] == 'W'):
longitude = -longitude
#satellites = parts[7]
GPStime = str((int(parts[5][0:2])+8)%24) + ":" + parts[5][2:4] + ":" + parts[5][4:6]
FIX_STATUS = True
break
if (time.time() > timeout):
TIMEOUT = True
break
utime.sleep_ms(500)
def convertToDegree(RawDegrees):
RawAsFloat = float(RawDegrees)
firstdigits = int(RawAsFloat/100)
nexttwodigits = RawAsFloat - float(firstdigits*100)
Converted = float(firstdigits + nexttwodigits/60.0)
Converted = '{0:.6f}'.format(Converted)
return str(Converted)
The console output is as follows. It can be seen that after obtaining valid GNGLL data, the program correctly parses the precision and latitude.
----------------------
mytime is: 2023-06-06 Tues 09:09:44
mytime is: 2023-06-06 Tues 09:09:45
mytime is: 2023-06-06 Tues 09:09:46
mytime is: 2023-06-06 Tues 09:09:47
mytime is: 2023-06-06 Tues 09:09:48
b'$GNGSA,A,3,06,08,09,16,24,39,,,,,,,3.7,2.1,3.0,4*3C\r\n'
b'$GNGLL,3168.46110,N,12176.26956,E,010943.000,A,A*49\r\n'
b'$GNGLL,3418.46110,N,12156.26956,E,010943.000,A,A*49\r\n'
Printing GPS data...
Latitude: 33.307686
Longitude: 123.437828
Satellites:
Time: 9:09:43
----------------------
|