Challenge - 5 Problems
GPS Data Reading Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2: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}")
Attempts:
2 left
💡 Hint
Remember that latitude degrees are first two digits, longitude degrees are first three digits.
✗ Incorrect
The code extracts degrees and minutes from the NMEA sentence and converts minutes to decimal degrees. Latitude is 48 degrees and 7.038 minutes, which is 48 + 7.038/60 = 48.1173. Longitude is 11 degrees and 31.000 minutes, which is 11 + 31/60 = 11.516667. Directions N and E keep values positive.
🧠 Conceptual
intermediate1: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)?
Attempts:
2 left
💡 Hint
One update per second means how many updates per second?
✗ Incorrect
GPS modules commonly output data once per second, which equals 1 Hertz (1 update per second).
🔧 Debug
advanced2: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()
Attempts:
2 left
💡 Hint
Is the serial port and baud rate correct? Is decoding done properly?
✗ Incorrect
The code opens the serial port, reads a line, decodes bytes to string, and prints it. If the GPS module is connected and sending data, this works without error.
❓ Predict Output
advanced2: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'))
Attempts:
2 left
💡 Hint
NMEA latitude format is DDMM.mmmm, so slice first 2 characters for degrees.
✗ Incorrect
The function slices first 2 characters for degrees ('48') and the rest for minutes ('07.038'). Then computes 48 + 7.038/60 = 48.1173, rounds to 6 decimal places, and since direction is 'N', keeps positive. Python prints it as 48.1173.
🧠 Conceptual
expert1: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?
Attempts:
2 left
💡 Hint
Raspberry Pi uses a symbolic link for the primary UART serial port.
✗ Incorrect
On Raspberry Pi OS, /dev/serial0 is a symbolic link to the primary UART port, which can be /dev/ttyAMA0 or /dev/ttyS0 depending on model and configuration. This is the recommended port for GPS modules connected via UART.
