Live GPS lap tracking and visualization system using a Neo M8N GPS module + Python.
-
Hardware
- Neo M8N GPS Module
- Microcontroller (e.g., Arduino)
-
Python Libraries
serialpymatplotlibnumpy
- The microcontroller being used to receive and parse gps data is an STM32F446RE
- USART1 was used to receive NMEA data and USART2 was used to print the latitudes and longitudes to the serial port.

| STM Pin | GPS Pin | Function |
|---|---|---|
| PA10 | TX | RX |
| PA9 | RX | TX |
-
This code was referred to from micropeta. http://micropeta.com/video122
-
*gpsParse(char strParse) -This function parses incoming NMEA GPS sentences ($GPGGA, $GPGLL, or $GPRMC) to extract latitude and longitude data. It converts the NMEA-format coordinates into decimal degrees using nmeaToDecimal() and sends the formatted result over UART.
How it works:
Checks which NMEA sentence type is received (GGA, GLL, or RMC).
-Uses sscanf to extract latitude, longitude, and directional info. -Converts the raw NMEA latitude/longitude to standard decimal degrees. -Formats the result as a comma-separated string. -Transmits the final coordinates over UART2.
-
nmeaToDecimal(float coordinate)
- Converts a GPS coordinate from NMEA format (ddmm.mmmm) to standard decimal degrees (dd.dddddd).
-
GPS Data Acquisition
High-accuracy GPS data is received using the NeoGPS library. -
Serial Communication
Data is transmitted from the microcontroller and read viaserialpyon the host PC. -
Real-Time Data Visualization
GPS coordinates are plotted usingmatplotlib. The first lap defines the base track layout. -
Lap Detection and Timing
A lap is considered complete when the current GPS location returns within a 0.00003° threshold of the start point. -
Live Tracking (Lap 2+)
From the second lap onward, a moving location marker is shown. The base track remains constant. -
RPM Trail Visualization
RPM is simulated and shown as a color-coded trail:- 🟢 Green: < 2000 RPM
- 🟡 Yellow: 2000–4000 RPM
- 🔴 Red: > 4000 RPM
- Saves latitude/longitude of the first lap into a
.npyfile. - Returns the array for use in offset boundary drawing.

- Creates a vertical lime green start/finish line using the first GPS coordinate.
- Only drawn once at initialization.

- Called during lap 1.
- Simulates RPM and assigns a trail color.
- Plots GPS path in real-time.
- Updates blue current-location marker.
- Displays point count.

- Called from lap 2 onwards.
- Applies RPM color logic.
- Loads saved first lap and draws offset track boundaries.
- Updates GPS trail and live position.
- Refreshes lap counter and timer.

- Continuously checks proximity to the start line.
- Triggers when:
- Enough points are recorded.
- Start point is reached again.
- Actions:
Continuously:
- Reads GPS data via Arduino serial (e.g.,
COM3). - Parses GPS (lat, lon).
- Initializes start line.
- Appends valid coordinates.
- Calls:
update_lap_one()during lap 1.update_plot_lap_two_onwards()for lap 2+.
- Handles cleanup on keyboard interrupt.

** Hardware Setup**
- Connect your Neo M8N GPS module to your microcontroller (e.g., Arduino).
- Ensure the GPS module has a clear view of the sky for optimal signal.
- Upload your Arduino sketch that outputs GPS NMEA sentences via serial.


