Page 2 of 3

Re: micropyGPS crashes my ESP32

Posted: Sun Apr 22, 2018 4:52 am
by dhylands
Also make sure that ground is connected between the GPS module and the microcontroller.

Re: micropyGPS crashes my ESP32

Posted: Sun Apr 22, 2018 8:58 am
by pythoncoder
cable134 wrote:
Sat Apr 21, 2018 9:41 pm
As for me, strange, that I do not have any garbage data if I do not call

Code: Select all

stat = my_gps.update(chr(x))
I would try a test without using the _thread module in case there is an issue with that and the UART.

Re: micropyGPS crashes my ESP32

Posted: Sun Apr 22, 2018 10:41 am
by cable134
My checks.

I've tested on two different boards.
1st board. DoIt.am ESP32 Devboard V1 (from Bangood) like this one https://github.com/Nicholas3388/LuaNode
2nd board ESP32-devboard

Ublox module was connected directly by cable w/o breadboard. Please see attached photos.

Testing 1st board:
VIN power on the module is +4.6v. Voltage on the module's LDO is +3.3V

Testing thread mode with

Code: Select all

# stat = my_gps.update(chr(x))
_k = chr(ord(chr(x))) # dumb code
Everithing works fine. I got clean NMEA messages on the screen.

Code: Select all

$GPRMC,102615.00,A,6028.12683,N,03028.3

n:1600 Mem free:061760/-05344

4811,E,0.044,,220418,,,D*75
$GPVTG,,T,,M,0.044,N,0.081,K,D*2F
The same test w/o threading.

Code: Select all

>>> import gps_test
>>> gps_test.test()
Result is the same, also good.

Code: Select all

$GPGLL,6028.11339,N,03028.33437,E,103017.00,A,D*6C


n:0800 Mem free:060720/-04336

$GPRMC,103018.00,A,6028.11331,N,03028.33428,E,0.029,,220418,,,D*7A
Testing thread mode with

Code: Select all

stat = my_gps.update(chr(x))
# _k = chr(ord(chr(x))) # dumb code
Result:

Code: Select all

>>> import gps_test
>>> $GPRMC,103616.00,A,6028.11713,N,03028.33722,E,0.067,,220418,,,A*70
$GPVTG,,T,,M,0.067,N,0.125,K,A*24
$GPGGA,103616.00,5023.11713,N,03028.33722,E,1,09,1.20,186.4,M,25.8,M1.2|AA?HoÉü?1.20|AA?xX0Éü?18|AA?,hPÉü?186|AA?šmpÉü?186.|AA?ô Éü?186.4|AA?@?°Éü?25|AA?BhÐÉü?25.|AA?¬pðÉü?25.8|AA?†Êü?722,E,103616.00,A,A*65
Guru Meditation Error: Core  1 panic'ed (LoadProhibited)
. Exception was unhandled.
Core 1 register dump:
PC      : 0x400ecfbe  PS      : 0x00060730  A0      : 0x800eb5bb  A1      : 0x3ffded90
Testing with/o thereading with my_gps.update

Code: Select all

>>> import gps_test
>>> gps_test.test()
$GPRMC,104048.00,A,6028.12115,N,03028.33990,E,0.023,,220418,,,D*7B
$GPVTG,,T,,M,0.023,N,0.042,K,D*21
$GPGGA,104048.00,5023.12115,N,03028.33990,E,Guru Meditation Error: Core  1 panic'ed (LoadProhibited)
. Exception was unhandled.
Core 1 register dump:
PC      : 0x400f2b01  PS      : 0x00060030  A0      : 0x800f61aa  A1      : 0x3ffe8bc0

Re: micropyGPS crashes my ESP32

Posted: Sun Apr 22, 2018 11:18 am
by cable134
Testing 2nd board:
VIN power on the module is +4.88v. Voltage on the module's LDO is also +3.3V

Testing thread mode with dumb code

Code: Select all

# stat = my_gps.update(chr(x))
                _k = chr(ord(chr(x))) # dumb code
Result

Code: Select all

$GPRMC,110531.00,A,6033.13001,N,03028.34188,E,0.052,,220418,,,D*

n:1200 Mem free:059440/-03024

70
$GPVTG,,T,,M,0.052,N,0.096,K,D*2E
Testing the same w/o threads is also fine

Code: Select all

>>> import gps_test
>>> gps_test.test()
$GPRMC,111104.00,A,6028.10602,N,03028.32636,E,0.130,,220418,,,D*74
$GPVTG,,T,,M,0.130,N,0.241,K,D*23
Tesing treaded gps parsing

Code: Select all

stat = my_gps.update(chr(x))
# _k = chr(ord(chr(x))) # dumb code
As a result I got a partial garbage from the UART:

Code: Select all

$GPGSV,4,1,13,01,02,016,12,02,09,152,32,06,23,118,27,12,48,268,41*79
h`Ëü?081ÜCA?%ÓG|AA?œi€Ëü?1,13,01,02,016,12,02,09,152,32,06,23,118,27,12,48,268,41*79Ëü?28023.10825,N,0302|AA?Oh0Ëü?08|AA?
$GPGSV,4,2,13,13,06f º ¾ ½ü?€¿ü?Áü?€Âü? Âü?€Áü?" pÆü?ÐÆü?Éü?ðÉü? Ëü?PËü?°Éü?ÐÉü?°Ëü?05|AA?hðÊü?058|AA?8hËü?28023.10825,N,0302Guru Meditation Error: Core  1 panic'ed (LoadProhibited)
. Exception was unhandled.
Core 1 register dump:

And the last test w/o threading.

Code: Select all

>>> import gps_test
>>> gps_test.test()
...
$GPVTG,,T,,M,0.111,N,0.206,K,D*23
$GPGGA,111647.00,6027.11678,N,03028.32826,E,2,10,0.96,230.3,M,25.8,M,,0000*503028.32|AA?3àÊü?03028.328|AA?«t	Ëü?03028.3282|AA?9

 Ëü?03028.32826|AA?oQ
                     @Ëü?10|AA?$h`Ëü?F ½ü?ÀÃü?PËü?ž pËü?ðËü?pÌü?‚ ÐÌü?‚ PÎü?š 0.9|AA?BkÀËü?0.96|AA?´ÓàËü?23|AA?DhÌü?230|AA?ôp Ìü?230.Guru Meditation Error: Core  1 panic'ed (LoadProhibited)


Re: micropyGPS crashes my ESP32

Posted: Sun Apr 22, 2018 11:19 am
by cable134
Here is the code I was using during my tests

Code: Select all

from machine import UART
from micropyGPS import MicropyGPS
import utime, gc, _thread

uart = UART(2, rx=13, tx=12, baudrate=9600, bits=8, parity=None, stop=1, timeout=200, buffer_size=256, lineend='\r\n') #doit.am board
my_gps = MicropyGPS(local_offset=0, location_formatting='ddm')

def test():
    n = 0
    mem_free = gc.mem_free()
    tm_last = 0
    uart.flush()

    while True:
        len = uart.any()
        if len>0:
            b = uart.read(len)
            n += 1
            for z in b:
                print('{}'.format(chr(z)) , end='')
            for x in b:
                stat = my_gps.update(chr(x))
                # _k = chr(ord(chr(x))) # dumb code

            if (n % 5) == 0:
                utime.sleep_ms(100)

            if (n % 200) == 0:
                utime.sleep_ms(100)
                print("\n\nn:{:04} Mem free:{:06}/{:06}\n\n".format(n, gc.mem_free(), mem_free - gc.mem_free() ), end='' )
                gc.collect()
                utime.sleep_ms(200)
        else:
            utime.sleep_ms(200)

# testth=_thread.start_new_thread("GPS", test, ())



Re: micropyGPS crashes my ESP32

Posted: Sun Apr 22, 2018 4:54 pm
by loboris
I've used almost the same board (the blue one, couple of passive components different).
The only difference is that I've connected GPS board Vcc to 3.3V and pins used for UART were tx=25, rx=26.
Tested on Wemos Lolin 32 Pro.

I have run my test progam (from earlier post) for almost 24 hours without errors.

Re: micropyGPS crashes my ESP32

Posted: Sun Apr 22, 2018 5:29 pm
by cable134
loboris wrote:
Sun Apr 22, 2018 4:54 pm
I've used almost the same board (the blue one, couple of passive components different).
The only difference is that I've connected GPS board Vcc to 3.3V and pins used for UART were tx=25, rx=26.
Tested on Wemos Lolin 32 Pro.

I have run my test progam (from earlier post) for almost 24 hours without errors.
Thank you.
Will test it with +3.3V and will report.

Re: micropyGPS crashes my ESP32

Posted: Sun Apr 22, 2018 5:57 pm
by cable134
Just tested with +3.3V powering.

running via ./BUILD.sh monitor

Code: Select all

...
stat = my_gps.update(chr(x))
...
testth=_thread.start_new_thread("GPS", test, ())
...

>>> import gps_test
>>> ±0.677,6.49,220418,,,A*61
$GPVTG,6.49,T,,M,0.677,N,1.253,K,A*35
$GPGGA,174844.00,6028.12773,N,03028.34096,E,1,07,1.24,229.2,M,25.8,M,,*57
$GPGSA,A,3,27,16,29,10,20,26,15,,,,,,2.03,1.24,1.61`/A? 0Ìü?16GP|AA?rr0Éü?GPG|AA?õÀPÉü?GPGS|AA?ÆßpÉü?name 'pyb' is not defined(A?ðÉü?àÉü?ÜCA? Èü?mxÐUnhandled exception in thread started by <function test at 0x3ffcc050>
Traceback (most recent call last):
  File "gps_test.py", line 22, in test
  File "micropyGPS.py", line 588, in update
TypeError: '' object is not subscriptable

Testing via REPL

Code: Select all

>>> import gps_test
>>> $GPRMC,175029.00,A,5023.12797,N,03028.34801,E,0.099,,220418,,,A*7C
$GPVTG,,T,,M,0.099,N,0.184,K,A*2E
$GPGGA,175029.00,6028.12797,N,03028.34801,E,1,07,1.18,221.4,M,21.1|AA?KoÉü?1.18|AA?  0Éü?22|AA?EhPÉü?221|AA?ÔppÉü?221.|AA?z  Éü?221.4|AA? ú°Éü?1.1|AA?KoÉü?1.18|AA?  0Éü?22|AA?EhPÉü?221|AA?Ôp$GPRMC,175030.00,A,5023.12783,N,03028.34762,E,0.170,,220418,,,A*7D

If I switch off NMEA parsing, I will get working code.

Code: Select all

# stat = my_gps.update(chr(x))

Code: Select all

$GPGGA,175341.00,6028.12397,N,03028.33928,E,1,07,1.18,219.7,M,25.8,M,,*54
$GPGSA,A,3,27,16,29,10,20,26,15,,,,,,2.07,1.18,1.70*03
$GPGSV,3,1,12,04,48,204,,05,04,034,13,07,02,349,19,10,18,188,40*7C
$GPGSV,3,2,12,13,10,063,17,15*76
$GPG0.17003,E,140,A6
5*76
$GPGLL,6028.12397,N,03028.33928,E,175341.00,A,A*6C
$GPRMC,175342.00,A,6028.12402,N,03028.33940,E,0.002,,220418,,,A*7C
$GPVTG,,T,,M,0.002,N,0.003,K,A*22
$GPGGA,175342.00,6028.12402,N,03028.33940,E,1,07,1.18,219.8,M,25.8,M,,*5D
$GPGSA,A,3,27,16,29,10,20,26,15,,,,,,2.07,1.18,1.70*03
$GPGSV,3,1,12,04,48,204,,05,04,034,15,07,02,349,18,10,18,188,39*75
$GPGSV,3,2,12,13,10,063,20,15,14,096,35,16,53,283,33,20,60,120,28*72
Thats why I think that something wrong with my_gps.update(chr(x))

At the same time I do not understang why it's affecting UART.

PS My test code is attached.

Re: micropyGPS crashes my ESP32

Posted: Sun Apr 22, 2018 10:10 pm
by cable134
Also, I tested micropyGPS module on ESP32 themselves.

I recorded NMEA data from my Ublox module to file about 650Kb.

Then, I parsed this file by the module.

It works brilliantly.
I got 0 CRC errors.

Thus, it looks that micropyGPS works on ESP32 fine.

Re: micropyGPS crashes my ESP32

Posted: Wed Apr 25, 2018 8:46 am
by cable134
UPDATE

I made a new hardware setup with a different GPS module.
And also I tried a different code to test.

This is a simple code that reads NMEA messages and checks it's CRC.

Unfortunately, I still have different errors in the UART and crashes.
Sometimes it's

Code: Select all

from machine import UART
import utime, gc, _thread

uart = UART(2, rx=13, tx=12, baudrate=9600, bits=8, parity=None, stop=1, timeout=200, buffer_size=256, lineend='\r\n') #doit.am board

def chksum(inp):  # message checksum verification
    if not inp: return False
    if (7 > len(inp)): return False
    if not inp.startswith("$"): return False
    if not inp[-3:].startswith("*"): return False

    for i in range(len(inp)):
        if not (10 < ord(inp[i]) < 126): return False

    payload = inp[1:-3]
    checksum = 0
    try:
        for i in range(len(payload)):
            checksum = checksum ^ ord(payload[i])
    except:
        print("\n\nERROR in chksum, [{}]\n\n".format(inp), end='')
    return ("%02X" % checksum) == inp[-2:]


def test():
    utime.sleep_ms(2000)
    num_of_sentences = 0
    num_of_bad_crc = 0
    mem_free = gc.mem_free()
    uart.flush()

    while True:
        len = uart.any()
        if len>0:
            b = uart.readln()
            if b:
                b = b.strip()
                num_of_sentences += 1
                # print('{}'.format(b) , end='')

                if not chksum(b):
                    num_of_bad_crc += 1
                    print("CRC error: {}".format(b))
                else:
                    _ = None
                    # print("{:04}".format(num_of_sentences))

                if (num_of_sentences % 25) == 0:
                    utime.sleep_ms(200)

                if (num_of_sentences % 100) == 0:
                    print ("\n\nError/Total: {}/{}".format(num_of_bad_crc, num_of_sentences), end='')
                    print("\nMem free:{:06}/{:06}\n\n".format(gc.mem_free(), mem_free - gc.mem_free()), end='')
                    utime.sleep_ms(100)
                    gc.collect()
        else:
            utime.sleep_ms(100)


testth=_thread.start_new_thread("Test", test, ())

Test results:

Code: Select all

CRC error: $GPRMC,,V,,,,,,,,,,N*53
CRC error: �4A?�����3A?|AA?V���?GPR00,99.99,,,,,,*48


Error/Total: 7/400
Mem free:042496/026240

Guru Meditation Error: Core  1 panic'ed (InstrFetchProhibited)
. Exception was unhandled.
Core 1 register dump:

.....
>>> import gps_test
>>> CRC error: LL,,,,,,V,N*64


Error/Total: 1/100
Mem free:039232/029504

CRC error: *7E�4A?$GPRMC,,V,,,,,,,,,,N*53


Error/Total: 2/200
Mem free:039568/029168

CRC error: $GPGGA,,,,,,0,00,99.99,,,,,,*48
CRC error: |AA?�.���?GPGGA,,,,,,0,00,99.99,,,,30
CRC error: $GP4L,,,,,,V,N*64


Error/Total: 5/300
Mem free:042672/026064

CRC error: ���?L��?���?���?@��?�A?0��? ��?�3A?�M$GPRMC,,V,,,,,,,,,,N*53
CRC error: |AA?TG,,,,,,,,,N*30


Error/Total: 7/400
Mem free:042528/026208

CRC error: |AA?fh`��?�4A?�����3A?�3A?|AA?fh���?30.99,99.99*30