Skip to content

Commit e7bd487

Browse files
committed
GPS.md: Add RP2 code samples.
1 parent 51103b1 commit e7bd487

File tree

1 file changed

+71
-18
lines changed

1 file changed

+71
-18
lines changed

v3/docs/GPS.md

Lines changed: 71 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ This repository offers a suite of asynchronous device drivers for GPS devices
44
which communicate with the host via a UART. GPS [NMEA-0183] sentence parsing is
55
based on this excellent library [micropyGPS].
66

7-
The code in this V3 repo has been ported to uasyncio V3. Some modules can run
8-
under CPython: doing so will require Python V3.8 or later.
7+
The code requires uasyncio V3. Some modules can run under CPython: doing so
8+
will require Python V3.8 or later.
9+
10+
The main modules have been tested on Pyboards and RP2 (Pico and Pico W).
911

1012
###### [Tutorial](./TUTORIAL.md#contents)
1113
###### [Main V3 README](../README.md)
@@ -68,18 +70,21 @@ to access data such as position, altitude, course, speed, time and date.
6870
These notes are for the Adafruit Ultimate GPS Breakout. It may be run from 3.3V
6971
or 5V. If running the Pyboard from USB, GPS Vin may be wired to Pyboard V+. If
7072
the Pyboard is run from a voltage >5V the Pyboard 3V3 pin should be used.
73+
Testing on Pico and Pico W used the 3.3V output to power the GPS module.
74+
75+
| GPS | Pyboard | RP2 | Optional |
76+
|:----|:-----------|:----|:--------:|
77+
| Vin | V+ or 3V3 | 3V3 | |
78+
| Gnd | Gnd | Gnd | |
79+
| PPS | X3 | 2 | Y |
80+
| Tx | X2 (U4 rx) | 1 | |
81+
| Rx | X1 (U4 tx) | 0 | Y |
82+
83+
Pyboard connections are based on UART 4 as used in the test programs; any UART
84+
may be used. RP2 connections assume UART 0.
7185

72-
| GPS | Pyboard | Optional |
73-
|:---:|:----------:|:--------:|
74-
| Vin | V+ or 3V3 | |
75-
| Gnd | Gnd | |
76-
| PPS | X3 | Y |
77-
| Tx | X2 (U4 rx) | |
78-
| Rx | X1 (U4 tx) | Y |
79-
80-
This is based on UART 4 as used in the test programs; any UART may be used. The
81-
UART Tx-GPS Rx connection is only necessary if using the read/write driver. The
82-
PPS connection is required only if using the timing driver `as_tGPS.py`. Any
86+
The UART Tx-GPS Rx connection is only necessary if using the read/write driver.
87+
The PPS connection is required only if using the timing driver `as_tGPS.py`. Any
8388
pin may be used.
8489

8590
On the Pyboard D the 3.3V output is switched. Enable it with the following
@@ -113,6 +118,7 @@ In the example below a UART is instantiated and an `AS_GPS` instance created.
113118
A callback is specified which will run each time a valid fix is acquired.
114119
The test runs for 60 seconds once data has been received.
115120

121+
Pyboard:
116122
```python
117123
import uasyncio as asyncio
118124
import as_drivers.as_GPS as as_GPS
@@ -124,6 +130,25 @@ uart = UART(4, 9600)
124130
sreader = asyncio.StreamReader(uart) # Create a StreamReader
125131
gps = as_GPS.AS_GPS(sreader, fix_cb=callback) # Instantiate GPS
126132

133+
async def test():
134+
print('waiting for GPS data')
135+
await gps.data_received(position=True, altitude=True)
136+
await asyncio.sleep(60) # Run for one minute
137+
138+
asyncio.run(test())
139+
```
140+
RP2:
141+
```python
142+
import uasyncio as asyncio
143+
import as_drivers.as_GPS as as_GPS
144+
from machine import UART, Pin
145+
def callback(gps, *_): # Runs for each valid fix
146+
print(gps.latitude(), gps.longitude(), gps.altitude)
147+
148+
uart = UART(0, 9600, tx=Pin(0), rx=Pin(1), timeout=5000, timeout_char=5000)
149+
sreader = asyncio.StreamReader(uart) # Create a StreamReader
150+
gps = as_GPS.AS_GPS(sreader, fix_cb=callback) # Instantiate GPS
151+
127152
async def test():
128153
print('waiting for GPS data')
129154
await gps.data_received(position=True, altitude=True)
@@ -358,7 +383,7 @@ The following are counts since instantiation.
358383

359384
* `utc` (property) [hrs: int, mins: int, secs: int] UTC time e.g.
360385
[23, 3, 58]. Note the integer seconds value. The MTK3339 chip provides a float
361-
buts its value is always an integer. To achieve accurate subsecond timing see
386+
but its value is always an integer. To achieve accurate subsecond timing see
362387
[section 6](./GPS.md#6-using-gps-for-accurate-timing).
363388
* `local_time` (property) [hrs: int, mins: int, secs: int] Local time.
364389
* `date` (property) [day: int, month: int, year: int] e.g. [23, 3, 18]
@@ -447,9 +472,13 @@ This reduces to 2s the interval at which the GPS sends messages:
447472
```python
448473
import uasyncio as asyncio
449474
from as_drivers.as_GPS.as_rwGPS import GPS
450-
from machine import UART
451-
452-
uart = UART(4, 9600)
475+
# Pyboard
476+
#from machine import UART
477+
#uart = UART(4, 9600)
478+
# RP2
479+
from machine import UART, Pin
480+
uart = UART(0, 9600, tx=Pin(0), rx=Pin(1), timeout=5000, timeout_char=5000)
481+
#
453482
sreader = asyncio.StreamReader(uart) # Create a StreamReader
454483
swriter = asyncio.StreamWriter(uart, {})
455484
gps = GPS(sreader, swriter) # Instantiate GPS
@@ -633,6 +662,7 @@ test.usec()
633662

634663
## 6.2 Usage example
635664

665+
Pyboard:
636666
```python
637667
import uasyncio as asyncio
638668
import pyb
@@ -657,6 +687,30 @@ async def test():
657687
t = gps_tim.get_t_split()
658688
print(fstr.format(gps_tim.get_ms(), t[0], t[1], t[2], t[3]))
659689

690+
asyncio.run(test())
691+
```
692+
RP2 (note set_rtc function is Pyboard specific)
693+
```python
694+
import uasyncio as asyncio
695+
from machine import UART, Pin
696+
import as_drivers.as_GPS.as_tGPS as as_tGPS
697+
698+
async def test():
699+
fstr = '{}ms Time: {:02d}:{:02d}:{:02d}:{:06d}'
700+
uart = UART(0, 9600, tx=Pin(0), rx=Pin(1), rxbuf=200, timeout=5000, timeout_char=5000)
701+
sreader = asyncio.StreamReader(uart)
702+
pps_pin = Pin(2, Pin.IN)
703+
gps_tim = as_tGPS.GPS_Timer(sreader, pps_pin, local_offset=1,
704+
fix_cb=lambda *_: print("fix"),
705+
pps_cb=lambda *_: print("pps"))
706+
print('Waiting for signal.')
707+
await gps_tim.ready() # Wait for GPS to get a signal
708+
while True:
709+
await asyncio.sleep(1)
710+
# In a precision app, get the time list without allocation:
711+
t = gps_tim.get_t_split()
712+
print(fstr.format(gps_tim.get_ms(), t[0], t[1], t[2], t[3]))
713+
660714
asyncio.run(test())
661715
```
662716

@@ -964,7 +1018,6 @@ These tests allow NMEA parsing to be verified in the absence of GPS hardware:
9641018
* `astests_pyb.py` Test with synthetic data on UART. GPS hardware replaced by
9651019
a loopback on UART 4. Requires a Pyboard.
9661020

967-
# 11 References
9681021

9691022
[MicroPython]:https://micropython.org/
9701023
[frozen module]:https://learn.adafruit.com/micropython-basics-loading-modules/frozen-modules

0 commit comments

Comments
 (0)