Created
May 16, 2024 18:07
-
-
Save skittleson/b01e3e8a5f368c3116336abc84c55f08 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import utime as time | |
from machine import UART,Pin | |
gps_module = UART(1, baudrate=9600, tx=Pin(4), rx=Pin(5)) | |
time_zone = -7 | |
def read_until_char(uart, target_char='$'): | |
received_data = b'' # Initialize an empty byte string to store received data | |
while True: | |
if uart.any(): # Check if there's data available to read | |
char = uart.read(1) # Read one byte (character) from UART | |
received_data += char # Append the character to the received_data | |
if char == target_char.encode(): # Check if the character matches the target character | |
break # Stop reading if the target character is found | |
return received_data | |
def normalize_gps_data(byte_data): | |
return '$' + (byte_data[:-1] ).decode('ascii').rstrip() | |
while True: | |
time.sleep_ms(100) | |
data = normalize_gps_data(read_until_char(gps_module)) | |
#print(data) | |
if data.startswith('$GPGGA'): | |
print(data) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment