GNSS module do not working with python UBX parser, but working with u-center #137
Replies: 3 comments 2 replies
-
Ok a few observations:
from time import sleep
from serial import Serial
from pyubx2 import FIXTYPE, GET, UBXMessage, UBXReader
PORT = "/dev/ttyUSB0" # amend as required
BAUD = 115200 # check this is correct for your receiver port - the default is 38400
TIMEOUT = 5
# check these command sequences are correct
# you might find it helpful to use the `UBXMessage.config_set()`
# command to create the necessary CFG-VALSET messages
MON_VER = bytes.fromhex("B5 62 0A 04 00 00 0E 34")
CLD_RT = bytes.fromhex("B5 62 06 04 04 00 FF FF 13 7A")
ENA_NAV_PVT = bytes.fromhex(
"B5 62 06 01 08 00 01 07 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 13 51"
)
ENA_NAV_SAT = bytes.fromhex(
"B5 62 06 01 08 00 01 35 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 2B 87"
)
CFG_VALGET = bytes.fromhex("B5 62 06 8B 08 00 00 00 00 00 1F 00 31 10 F9 7F")
def print_telemetry(tmy, data):
print("Telemetry Data:")
print(f"Altitude: {tmy.get('altitude')}")
print(f"Latitude: {tmy.get('latitude')}")
print(f"Longitude: {tmy.get('longitude')}")
print(f"Fix Quality: {tmy.get('fix')}")
print(f"Horizontal Dilution of Precision: {tmy.get('hdop')}")
print(f"Time: {tmy.get('time')}")
print(f"Date: {tmy.get('time_date')}")
print(f"HDOP: {tmy.get('hdop')}")
print(f"VDOP: {tmy.get('vdop')}")
print(f"Speed: {tmy.get('speed')}")
print(f"Satellite Number: {tmy.get('satnum')}")
print(f"Course Over Ground: {tmy.get('cog')}")
print(f"Message: {data}")
def send_binary_command(serial_port, message):
serial_port.write(message)
print("Binary message sent")
sleep(1)
try:
with open("parsed.log", "w", encoding="UTF-8") as outfile:
with Serial(PORT, BAUD, timeout=TIMEOUT) as ser:
# send_binary_command(ser, CLD_RT)
# send_binary_command(ser, MON_VER)
# send_binary_command(ser, ENA_NAV_PVT)
# send_binary_command(ser, ENA_NAV_SAT)
count = 0
telemetry = {}
ubr = UBXReader(ser, GET)
print("UBXReader created")
for raw_data, parsed_data in ubr:
if isinstance(parsed_data, UBXMessage):
count += 1
# print(f"UBX Message: {parsed_data}")
if parsed_data.identity == "NAV-PVT":
telemetry["altitude"] = parsed_data.height
telemetry["longitude"] = parsed_data.lon
telemetry["latitude"] = parsed_data.lat
telemetry["time"] = (
f"{parsed_data.hour:02d}:{parsed_data.min:02d}:{parsed_data.second:02d}"
)
telemetry["time_date"] = (
f"{parsed_data.year}-{parsed_data.month:02d}-{parsed_data.day:02d}"
)
telemetry["fix"] = FIXTYPE[parsed_data.fixType]
telemetry["speed"] = parsed_data.gSpeed
telemetry["cog"] = parsed_data.headMot # strictly heading rather than course
elif parsed_data.identity == "NAV-SAT":
telemetry["satnum"] = parsed_data.numSvs
elif parsed_data.identity == "NAV-DOP":
telemetry["hdop"] = parsed_data.hDOP
telemetry["vdop"] = parsed_data.vDOP
print_telemetry(telemetry, parsed_data)
# use str() if you want to save parsed_data to a text file
# if you want to save the raw_data, open the file as "wb"
outfile.write(str(parsed_data))
except KeyboardInterrupt:
print(f"\nTerminated by user - {count} UBX messages read") |
Beta Was this translation helpful? Give feedback.
-
Hi @KerteszDomokos , I'm not sure I can account for why the data isn't changing for you - the cope snippet above works fine on a Raspberry Pi 4 (I don't currently have a RPI 5 to test on). I can only guess that this is some kind of local TTL-USB or serial config issue, or possibly an incorrect flashed UBX configuration. Out of interest, what operating system are you running on the RPi 5? I can only suggest one or more of the following diagnostic checks:
|
Beta Was this translation helpful? Give feedback.
-
Thanks for your help @semuadmin! The solution could be cheaper, but it's working fine and very fast. Thanks for the help! |
Beta Was this translation helpful? Give feedback.
-
Hello,
I have an error with my GNSS module. I use it with an usb-uart driver, and when I connect it to my computer, and read datas with u-center I get continously updated position information, but when I try to read the same data with python (on a raspberry pi 5 device), I get the same datas for long minutes.
The UBX messages are coming perfectly in python, but the datas are absolutely the same for too long times (I tested it more than half an hour). When I switch to the u-center I get new position informations (in a few minute), but when I reconnect trough python I do not get updated data.
I had more errors (and less usable information) using NMEA, so thats why I use UBX
Hardware:
Configuration (writed to the FLASH):
These seem to be OK, because I get this types of messages in u-center and in python too.
Software:
There is a simple code:
Sending configuration is not working as I experienced, but this is not my main error
There is some readed data from parsed.log file:
(I deleted my position data)
I would be greatful, if you could help me.
Thanks!
EDIT:
I tested the device and the same program on a windows device, and here it is working perfectly. The error may could be a linux specified problem?
Beta Was this translation helpful? Give feedback.
All reactions