Reputation: 1
The problem is that the Gps module has to use the UART pins that are already connected to the Xbee. What i can do? (I use raspberry pi zero)
I tried this code. from gpiozero import DigitalOutputDevice, DigitalInputDevice import time
gps_tx_pin = 17 # GPIO pin connected to the TX pin of the GPS module gps_rx_pin = 26 # GPIO pin connected to the RX pin of the GPS module
gps_tx = DigitalOutputDevice(gps_tx_pin) gps_rx = DigitalInputDevice(gps_rx_pin)
def gps_write(data): for char in data: binary = bin(ord(char))[2:].zfill(8) # Convert character to binary string for bit in binary: gps_tx.value = int(bit) time.sleep(0.01) # Adjust the delay as per the requirements
def gps_read(): data = "" while True: if gps_rx.value: data += "1" else: data += "0" time.sleep(0.01) # Adjust the delay as per the requirements if len(data) >= 8: # Adjust the number of bits received per character break return data while True: gps_write("AT\r\n") # Send command to GPS module response = gps_read() # Read response from GPS module
response_char = chr(int(response, 2)) # Convert binary string to ASCII character
if response_char.startswith("$GPGGA"):
data_parts = response_char.split(",")
if len(data_parts) >= 10:
latitude = data_parts[2]
longitude = data_parts[4]
print("Latitude: {}".format(latitude))
print("Longitude: {}".format(longitude))
time.sleep(1) # Adjust the delay as per the requirements
Upvotes: 0
Views: 77