0

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
asked May 24, 2023 at 14:04
2
  • chr(int(response, 2)) seems suspicious. Note: you have a char, not a string. But why do you get a binary string? Commented May 24, 2023 at 14:09
  • what i should do? Commented May 24, 2023 at 14:31

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.