GPS Python sample

Dear Toradex,

Happy New Year!

I have an Imx8mini SOM and I want to use the Toradex python sample code for working on GPS .
I have modified the GPIO 3 and GPIO4 DT to covert them to UART2 and I connected them to GPS,

In the VS code, on the devices and appargs parts, I added [/dev/ttymxc2].
and on the buildcommands added [RUN usermod -a -G dialout torizon] also in the requirements,txt just added [pyserial pynmea2]
but I have 2 problems and nothing on the output Terminal and it would be really helpful if you could help me
image

Best regards,
Mehrdad

Hi @Mehrdad ,

What exactly is the problem? Is there an error when trying to run the code, or you can run it but it’s not working as intended?

Just to be sure, how are you adding the Python packages in requirements.txt? You should put one package per line, as shown in torizon-samples/requirements.txt at bullseye · toradex/torizon-samples · GitHub :

pyserial
pynmea2

With this I was able to deploy and debug the GPS code, though I didn’t connect an actual GPS module on the SoM, so naturally I didn’t get any output.

During my tests the two import warnings appeared even when the code executed successfully.

Let me know if this helps you.

Best regards,
Lucas Akira

Hi @lucas_a.tx

The output terminal does not show anything, and there is only one library per line for each library , as shown below

image

I think it didn’t import the libraries since they have a line below them in main.py but you have this warning as well!

image

it is strange because if I write serial. and there is nothing shown for the serial module

image

for example, if I added time module and if I write time dot, I can see the other methods of the time that I can use

image

Best regards,
Mehrdad

Hi @Mehrdad ,

The output terminal does not show anything, and there is only one library per line for each library , as shown below

Right, your requirements.txt looks correct to me. So apparently you can run the code, but you get no output i.e. the GPS coordinates, is this correct?

I think it didn’t import the libraries since they have a line below them in main.py but you have this warning as well!

I believe the libraries were imported, as otherwise you would get an import error and the code would not run at all. You can verify this by running this test code adapted from here: https://openbase.com/python/pynmea2

#!/usr/bin/python3
import sys
import pynmea2
import serial

serial_port = "/dev/apalis-uart2"
if len(sys.argv) > 1:
    serial_port = sys.argv[1]

ser = serial.Serial(serial_port,9600, 8, 'N', 1, timeout=1)
msg = pynmea2.parse("$GPGGA,184353.07,1929.045,S,02410.506,E,1,04,2.6,100.00,M,-33.9,M,,0000*6D")
print("Time = " + msg.timestamp.strftime("%H:%M:%S"))
print("Latitude = " + msg.lat + ", " + msg.lat_dir)
print("Longitude = " + msg.lon + ", " + msg.lon_dir)
print("\n")

If serial and pynmea2 are not imported you would get an error at execution time. On my side the code above worked without problems:

I recommend debugging your code and checking the serial data i.e. the value of variable data after

data = data.decode("utf-8","ignore").rstrip()

Also, check how your GPS module sends serial data, like the supported baud rate, number of data bits, parity, etc. and change the serial initialization accordingly.

Best regards,
Lucas Akira

Hi @Mehrdad !

Do you have any news about this topic?

Best regards,

Hi @henrique.tx
It is unfortunately not possible for me, I use C. I appreciate your help.
Best regards,
Mehrdad

Hello @Mehrdad ,

What does this mean? Were you able to try what @lucas_a.tx suggested on the Python project that you referred to in your previous messages?

Does that mean that you have eventually switched your project from Python to C? If that’s the case, you can open a new topic if you have any issues with your C project.

Best regards,
Josep