LoPy UART for GPS not reading data
The pinout documentation is confusing me a lot, such that I don't understand why the UART isn't receiving data from a GPS module.
I should be using UART 1 for LoPy? Correct?
I have the GPS receiver connected:
GPS:RX <=> LoPy expansion G24
GPS:TX <=> LoPy expansion G11
My code to configure the UART:
com = UART(1, pins=("P3", "P4"), baudrate=9600)
The documentation for the pinout is very confusing.
Should I use P3 and P4, or G23 and G24, or G24 and G11 in the code?
Why is the LoPy pinout labelled G24 and G21 for these signals?
The expansion board labels these signals G24 and G11
I'm not receiving data. (otherwise I wouldn't be asking a question!)
The GPS is presumely working as it flashes LED when fix is available.
I have swapped RX/TX to check if the signals are crossed.
Is it possible to do a loopback test on the same UART? If I write data then read the same UART, I get data even if the loopback is not connected. So I guess it just reads the TX buffer.
I have completed this project and have posted on this topic:
@affoltep Many thanks for the help. I'll carry on work with it tomorrow. Made good progress tonight. Cheers.
@johnmcdnz Here are some code fragments how I use:
#initialize UART interface to the GNSS module gps_pps = Pin('P23', mode = Pin.IN) gps_enable = Pin('P8', mode=Pin.OUT) gps_enable(False) gps_uart = UART(1, 9600) gps_uart.init(9600, bits=8, parity=None, stop=1) #Create NMEA structure nmea = NmeaParser()
latitudebinary = 0 longitudebinary = 0 altitude = 0 hdop = 0 newpos = False
while not newpos: if gps_uart.any(): nmea.update(gps_uart.readline()) if nmea.fix_stat & nmea.valid_sentence: newpos = True if (time.ticks_diff(start, time.ticks_ms()) > GNSS_TRIAL): pycom.rgbled(red) print('No actual GNSS postition') time.sleep(0.2) pycom.rgbled(off) return latitudebinary = int(((nmea.latitude + 90) / 180) * 16777215) longitudebinary = int(((nmea.longitude + 180) / 360) * 16777215) altitude = int(nmea.altitude) hdop = int(nmea.hdop * 10)
Hope it is understandable ;)
Is this correct:
place = NmeaParser() place.update(data) print (place.longitude, ":", place.latitude)
@affoltep I have copied your code. Excuse my ignorance with Python, what's the correct way to pass the data string to the code and read the response.
e.g. if NMEA string is in 'data', and decode is to be in 'place'
place = NmeaParser.update(data)
I know this is incorrect, but what is right?
@livius Looks like a reasonable unit, claims 2.5m accuracy, <30s fix from cold and 1s from hot start.
thank you - yes it is really good
interesting - i didn't see it before -
is it fast and accurate? Looks really interestingly
good to here that it work for you.
Maybe there was some not linked to contacts.
Thanks for the quick reply.
My test is now working. I can't explain why!
I changed a few things, like removed the jumper pins, then replaced them.
Changed the UART0 baudrate to 9600, and then back to 115200.
None of this is relevant though, as from power up the unit is now receiving fine.
Odd. I'd like to think I 'fixed' something, but don't believe I changed anything useful.
Anyway, now I can proceed!
P3 and P4 are valid
You can test if UART1 work by changing boot.py from uart 0 to uart 1
but you must have some TTL USB to UART converter to test if it work - or computer with native COM port.
If you got repl on it than it should work for you with GPS also.
I am quite sure that i have tested UART 1 before and it worked with converter.
But it was with old firmware...
What firmware version do you have? 1.6.5?
And one more tip - did you tried connecting gps to uart0 instead of Uart1 without expansion board?
To see if you can recive something?
@johnmcdnz I wrote a small test programm I used to test the gps-module communication. You have a the UART on Pin "P3" and Pin "P4" on LoPy, so you don't need to declare it. It is standard. "Gx" is always the view of the extension board, so you never use it for declarations in code. Always reference to the "Px" declaration.
from machine import Pin from machine import UART #Interface definitons for GPS gps_pps = Pin('P23', mode = Pin.IN) gps_enable = Pin('P8', mode=Pin.OUT) gps_enable(False) gps_uart = UART(1, 9600) gps_uart.init(9600, bits=8, parity=None, stop=1) gps_enable(True) while True: if gps_uart.any(): print(gps_uart.readline())