Bird
0
0
Raspberry Piprogramming~10 mins

GPS module data reading in Raspberry Pi - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the module needed to read serial data from the GPS module.

Raspberry Pi
import [1]
Drag options to blanks, or click blank then click option'
Aserial
Bgps
Ctime
Dos
Attempts:
3 left
💡 Hint
Common Mistakes
Importing 'gps' which is not a standard Python module for serial communication.
Importing 'time' or 'os' which are unrelated to serial data reading.
2fill in blank
medium

Complete the code to open the serial port to read GPS data at 9600 baud rate.

Raspberry Pi
ser = serial.Serial('/dev/ttyS0', [1])
Drag options to blanks, or click blank then click option'
A9600
B115200
C4800
D19200
Attempts:
3 left
💡 Hint
Common Mistakes
Using a baud rate that does not match the GPS module's setting, causing no data to be read.
Using 4800 which is an older standard but not common for modern GPS modules.
3fill in blank
hard

Fix the error in reading a line from the GPS serial port.

Raspberry Pi
line = ser.[1]()
Drag options to blanks, or click blank then click option'
Areadlinee
Breadline
Creadlines
Dread
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'readlines' which reads all lines and returns a list, not suitable here.
Typo in method name like 'readlinee' causing AttributeError.
4fill in blank
hard

Fill both blanks to decode the GPS data line and check if it starts with the correct prefix.

Raspberry Pi
data = line.[1]('utf-8')
if data.[2]('$GPGGA'):
Drag options to blanks, or click blank then click option'
Adecode
Bstartswith
Csplit
Dstrip
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to use 'split' or 'strip' instead of 'startswith' to check the prefix.
Not decoding bytes before checking the string.
5fill in blank
hard

Fill all three blanks to create a dictionary with latitude, longitude, and fix quality from the GPS data fields.

Raspberry Pi
fields = data.split(',')
gps_info = { [1]: fields[int([2])], [3]: fields[4], 'fix_quality': fields[6] }
Drag options to blanks, or click blank then click option'
A'latitude'
B2
C'longitude'
D4
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up field indexes for latitude and longitude.
Using wrong keys or forgetting to quote dictionary keys.