inmcm / micropyGPS

A Full Featured GPS NMEA-0183 sentence parser for use with Micropython and the PyBoard embedded platform
MIT License
346 stars 119 forks source link

Unable to read data from GPS #11

Closed nikhil1983 closed 2 years ago

nikhil1983 commented 6 years ago

Hello, I am currently using micro python on STM32Fdisc board, attempting to interface with GPS module. I have tried your code and also tested my code but i am unable to read data from GPS. Do you have any idea about this problem, why it happen ?

Here is the code:

import pyb import pyb,micropython from pyb import LED, Pin, UART

rx = bytearray(250) i = None uart = UART(2,115200)

data = bytearray(255) j = 0

Capture Data in the Rx buffer

for i in range(255): uart.readinto(rx) print(rx)

x = uart.readchar()

print(x)

if i == 255: break

I printed the buffer and the value is 0. So do you have any idea what can be the reason ? I have checked the GPS module its working using C/C++ and also the UART is working fine.

tcinbis commented 6 years ago

@nikhil1983 unfortunately I do not have a STM32 board. But I run my GPS module with the following code on an ESP32, maybe it helps.

from machine import UART
from micropyGPS import MicropyGPS
from utime import ticks_ms

my_gps = MicropyGPS()
uart = UART(2,9600)

def read_GPS():
    startTime = ticks_ms()
    while ticks_ms() - startTime <= 1000:
        if uart.any():
            data = uart.read()
            for s in data:
                my_gps.update(chr(s))

NOTE: This code will only read the gps data for one second. You may need to adjust this time or call it more often.

Of course you may have to adjust the imports, because the micropython ports seem to be a little bit different in structure.

Jollyjohn commented 5 years ago

Hello, I am currently using micro python on STM32Fdisc board, attempting to interface with GPS module. I have tried your code and also tested my code but i am unable to read data from GPS. Do you have any idea about this problem, why it happen ?

Here is the code:

import pyb import pyb,micropython from pyb import LED, Pin, UART rx = bytearray(250) i = None uart = UART(2,115200) data = bytearray(255) j = 0

Capture Data in the Rx buffer

for i in range(255): uart.readinto(rx) print(rx)

x = uart.readchar()

print(x)

if i == 255: break

I printed the buffer and the value is 0. So do you have any idea what can be the reason ? I have checked the GPS module its working using C/C++ and also the UART is working fine.

Hi @nikhil1983 - Did you manage to get this working? If not, let me know as I just did a deep dive into the code and may be able to help. If you figured it out can you either refine the problem or close the ticket?

Ta