@@ -4,8 +4,10 @@ This repository offers a suite of asynchronous device drivers for GPS devices
4
4
which communicate with the host via a UART. GPS [ NMEA-0183] sentence parsing is
5
5
based on this excellent library [ micropyGPS] .
6
6
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).
9
11
10
12
###### [ Tutorial] ( ./TUTORIAL.md#contents )
11
13
###### [ Main V3 README] ( ../README.md )
@@ -68,18 +70,21 @@ to access data such as position, altitude, course, speed, time and date.
68
70
These notes are for the Adafruit Ultimate GPS Breakout. It may be run from 3.3V
69
71
or 5V. If running the Pyboard from USB, GPS Vin may be wired to Pyboard V+. If
70
72
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.
71
85
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
83
88
pin may be used.
84
89
85
90
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.
113
118
A callback is specified which will run each time a valid fix is acquired.
114
119
The test runs for 60 seconds once data has been received.
115
120
121
+ Pyboard:
116
122
``` python
117
123
import uasyncio as asyncio
118
124
import as_drivers.as_GPS as as_GPS
@@ -124,6 +130,25 @@ uart = UART(4, 9600)
124
130
sreader = asyncio.StreamReader(uart) # Create a StreamReader
125
131
gps = as_GPS.AS_GPS(sreader, fix_cb = callback) # Instantiate GPS
126
132
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
+
127
152
async def test ():
128
153
print (' waiting for GPS data' )
129
154
await gps.data_received(position = True , altitude = True )
@@ -358,7 +383,7 @@ The following are counts since instantiation.
358
383
359
384
* ` utc ` (property) [ hrs: int, mins: int, secs: int] UTC time e.g.
360
385
[ 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
362
387
[ section 6] ( ./GPS.md#6-using-gps-for-accurate-timing ) .
363
388
* ` local_time ` (property) [ hrs: int, mins: int, secs: int] Local time.
364
389
* ` 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:
447
472
``` python
448
473
import uasyncio as asyncio
449
474
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
+ #
453
482
sreader = asyncio.StreamReader(uart) # Create a StreamReader
454
483
swriter = asyncio.StreamWriter(uart, {})
455
484
gps = GPS(sreader, swriter) # Instantiate GPS
@@ -633,6 +662,7 @@ test.usec()
633
662
634
663
## 6.2 Usage example
635
664
665
+ Pyboard:
636
666
``` python
637
667
import uasyncio as asyncio
638
668
import pyb
@@ -657,6 +687,30 @@ async def test():
657
687
t = gps_tim.get_t_split()
658
688
print (fstr.format(gps_tim.get_ms(), t[0 ], t[1 ], t[2 ], t[3 ]))
659
689
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
+
660
714
asyncio.run(test())
661
715
```
662
716
@@ -964,7 +1018,6 @@ These tests allow NMEA parsing to be verified in the absence of GPS hardware:
964
1018
* ` astests_pyb.py ` Test with synthetic data on UART. GPS hardware replaced by
965
1019
a loopback on UART 4. Requires a Pyboard.
966
1020
967
- # 11 References
968
1021
969
1022
[ MicroPython ] :https://micropython.org/
970
1023
[ frozen module ] :https://learn.adafruit.com/micropython-basics-loading-modules/frozen-modules
0 commit comments