PyRaspBeta

← All practice problems

Raspberry Pi practice problem · I²C, SPI, UART & 1-Wire

GPS odometer

HardBudget $20Python · gpiozero

A GPS gives positions, not distance. An odometer adds up the distance between each fix and the next.

Build: a GPS module on the UART (TX → RXD/GPIO15, RX → TXD, 3V3).

Program: for every $GPRMC sentence with a fix (status A), add the distance from the previous fix to a running total and print it in whole metres:

Odometer: 7 m

Use the haversine formula with an Earth radius of 6 371 000 m:

a = sin²(Δφ/2) + cos φ1 · cos φ2 · sin²(Δλ/2)
d = 2R · asin(√a)

(φ latitude, λ longitude, in radians.) The test walker has an instant fix and walks a circle at 5 km/h (about 1.4 m every second). Print Odometer: 0 m for the first fix.

More in I²C, SPI, UART & 1-Wire