[SOLVED] UART for GPS

RP2040 based microcontroller boards running MicroPython.
Target audience: MicroPython users with an RP2040 boards.
This does not include conventional Linux-based Raspberry Pi boards.
User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: UART for GPS

Post by pythoncoder » Sun Feb 27, 2022 9:27 am

ghilliesuit wrote:
Sun Feb 27, 2022 12:51 am
...
So I would say it works well! Time to look through the tech docs and start parsing these strings into meaningful information.
...
I do suggest you look at the two libraries I linked above, both of which solve that problem. At the least they should be helpful in developing your own solution.
Peter Hinch
Index to my micropython libraries.

ghilliesuit
Posts: 15
Joined: Fri Feb 25, 2022 2:55 am

Re: UART for GPS

Post by ghilliesuit » Sun Feb 27, 2022 1:32 pm

@pythoncoder

I would love to use these libraries, however I got hung up pretty quickly. I am admittedly a novice user - so please forgive me :lol: . I have been using the Raspberry Pi 4B since it came out to do different projects (stepper motors, IO, 3 axis accelerometer, etc..) but have only used Python3 and CircuitPython to this point. I figured now is as good a time as any to take the training wheels off. I am hoping to build a small quad-copter with associated telemetry - so I want to work my way up to that one subsystem at a time. I appreciate the help!

I ran 'pip3 install primitives' that went well.

Then I ran 'pip3 install as_drivers/as_GPS' and that got me the a does not exist error. This telling me I have to physically download it and place it somewhere - or run another script to make it happen. But I'm not really sure how to proceed.

For reference, I am using a Raspberry Pi400 (64bit Raspberry Pi OS) + Thonny 3.3.14 to connect to Pi Pico (MicroPython V1.18). This may not be important - but just in case.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: UART for GPS

Post by pythoncoder » Sun Feb 27, 2022 1:41 pm

ghilliesuit wrote:
Sun Feb 27, 2022 1:32 pm
...I ran 'pip3 install primitives' that went well.
...
I have my doubts about that as none of my libraries are installed on PyPi. I'm not sure what you installed here...

You need to copy the files to your device using a tool such as rshell or official mpremote. Learning to use one of these tools is a good starting point, and my libraries have documentation to help here.
Peter Hinch
Index to my micropython libraries.

ghilliesuit
Posts: 15
Joined: Fri Feb 25, 2022 2:55 am

Re: UART for GPS

Post by ghilliesuit » Sun Feb 27, 2022 1:51 pm

I look into rshell and mpremote. Thanks again.

Just for reference - not sure what I installed either

Code: Select all

 
 pi@raspberrypi:~ $ pip3 install primitives
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Requirement already satisfied: primitives in ./.local/lib/python3.9/site-packages (1.7.0)
 

ghilliesuit
Posts: 15
Joined: Fri Feb 25, 2022 2:55 am

Re: UART for GPS

Post by ghilliesuit » Sun Feb 27, 2022 4:47 pm

pythoncoder wrote:
Sun Feb 27, 2022 1:41 pm
ghilliesuit wrote:
Sun Feb 27, 2022 1:32 pm
...I ran 'pip3 install primitives' that went well.
...
I have my doubts about that as none of my libraries are installed on PyPi. I'm not sure what you installed here...

You need to copy the files to your device using a tool such as rshell or official mpremote. Learning to use one of these tools is a good starting point, and my libraries have documentation to help here.
Thank you for the help! I was able to get the example provided going. Not going to show the output... because it points right to my back porch. I may reach out if I have questions on this. Thanks to the you and the other maintainers of those libraries (if there are others).

Code: Select all

import sys
sys.path.append('/as_GPS')

import uasyncio as asyncio
import as_GPS as as_GPS
from machine import UART, Pin

def callback(gps, *_):  # Runs for each valid fix
    print(gps.latitude(), gps.longitude(), gps.altitude)

uart = UART(1, baudrate=9600, bits=8, parity=None, stop=1, tx=Pin(4), rx=Pin(5), timeout=300)
sreader = asyncio.StreamReader(uart)  # Create a StreamReader
gps = as_GPS.AS_GPS(sreader, fix_cb=callback)  # Instantiate GPS

async def test():
    print('waiting for GPS data')
    await gps.data_received(position=True, altitude=True)
    await asyncio.sleep(60)  # Run for one minute

asyncio.run(test())

"""
#establish serial comms
gps = UART(1, baudrate=9600, bits=8, parity=None, stop=1, tx=Pin(4), rx=Pin(5), timeout=300)
imu = I2C(0, sda = Pin(12), scl = Pin(13), freq=400_000)

print(uasyncio.__version__)
"""

Post Reply