Bird
0
0
Raspberry Piprogramming~20 mins

GPS module data reading in Raspberry Pi - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
GPS Data Reading Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of GPS NMEA sentence parsing
What is the output of this Python code that parses a GPS NMEA sentence to extract latitude and longitude?
Raspberry Pi
nmea_sentence = "$GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47"

parts = nmea_sentence.split(",")
lat_raw = parts[2]
lat_dir = parts[3]
lon_raw = parts[4]
lon_dir = parts[5]

lat_deg = int(lat_raw[:2])
lat_min = float(lat_raw[2:])
lon_deg = int(lon_raw[:3])
lon_min = float(lon_raw[3:])

latitude = lat_deg + lat_min / 60
longitude = lon_deg + lon_min / 60

if lat_dir == "S":
    latitude = -latitude
if lon_dir == "W":
    longitude = -longitude

print(f"Latitude: {latitude:.6f}, Longitude: {longitude:.6f}")
ALatitude: 48.117300, Longitude: 11.516667
BLatitude: 48.703800, Longitude: 113.100000
CLatitude: 4.807038, Longitude: 11.310000
DLatitude: 48.117300, Longitude: -11.516667
Attempts:
2 left
💡 Hint
Remember that latitude degrees are first two digits, longitude degrees are first three digits.
🧠 Conceptual
intermediate
1:00remaining
Understanding GPS data update frequency
A GPS module connected to a Raspberry Pi outputs NMEA sentences every second. What is the typical update frequency of GPS position data in Hertz (Hz)?
A1 Hz
B60 Hz
C0.1 Hz
D10 Hz
Attempts:
2 left
💡 Hint
One update per second means how many updates per second?
🔧 Debug
advanced
2:00remaining
Identify the error in GPS serial reading code
What error will this Python code raise when reading GPS data from serial port on Raspberry Pi?
Raspberry Pi
import serial

ser = serial.Serial('/dev/ttyS0', 9600, timeout=1)
line = ser.readline()
print(line.decode('utf-8'))
ser.close()
AAttributeError
Bserial.SerialException
CNo error, prints GPS data line
DUnicodeDecodeError
Attempts:
2 left
💡 Hint
Is the serial port and baud rate correct? Is decoding done properly?
Predict Output
advanced
2:00remaining
Output of GPS coordinate conversion function
What is the output of this function converting NMEA latitude format to decimal degrees?
Raspberry Pi
def nmea_to_decimal(coord, direction):
    degrees = int(coord[:2])
    minutes = float(coord[2:])
    decimal = degrees + minutes / 60
    if direction in ['S', 'W']:
        decimal = -decimal
    return round(decimal, 6)

print(nmea_to_decimal('4807.038', 'N'))
A4807.038
B48.1173
C4.807038
DError: ValueError
Attempts:
2 left
💡 Hint
NMEA latitude format is DDMM.mmmm, so slice first 2 characters for degrees.
🧠 Conceptual
expert
1:30remaining
Choosing correct serial port for GPS on Raspberry Pi
Which serial port is typically used to connect a GPS module on a Raspberry Pi running Raspberry Pi OS with default settings?
A/dev/ttyAMA0
B/dev/ttyUSB0
C/dev/ttyS0
D/dev/serial0
Attempts:
2 left
💡 Hint
Raspberry Pi uses a symbolic link for the primary UART serial port.