Skip to content

Commit f5e898d

Browse files
author
Alexandre Marquet
committed
Adaptations to work with PyCom's microPython.
1 parent 7a88c30 commit f5e898d

File tree

3 files changed

+36
-81
lines changed

3 files changed

+36
-81
lines changed

README.rst

+8-39
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,26 @@
22
Introduction
33
============
44

5-
.. image:: https://readthedocs.org/projects/adafruit-circuitpython-gps/badge/?version=latest
6-
:target: https://circuitpython.readthedocs.io/projects/gps/en/latest/
7-
:alt: Documentation Status
8-
9-
.. image :: https://img.shields.io/discord/327254708534116352.svg
10-
:target: https://discord.gg/nBQh6qu
11-
:alt: Discord
12-
13-
.. image:: https://travis-ci.org/adafruit/Adafruit_CircuitPython_GPS.svg?branch=master
14-
:target: https://travis-ci.org/adafruit/Adafruit_CircuitPython_GPS
15-
:alt: Build Status
16-
175
GPS parsing module. Can parse simple NMEA data sentences from serial GPS
186
modules to read latitude, longitude, and more.
197

8+
Installation
9+
=============
10+
11+
On a LoPy, just put ``adafruit_gps.py`` into the ``lib/`` directory.
2012

2113
Dependencies
2214
=============
2315
This driver depends on:
2416

25-
* `Adafruit CircuitPython <https://github.com/adafruit/circuitpython>`_
26-
27-
Please ensure all dependencies are available on the CircuitPython filesystem.
28-
This is easily achieved by downloading
29-
`the Adafruit library and driver bundle <https://github.com/adafruit/Adafruit_CircuitPython_Bundle>`_.
17+
* `MicroPython <https://github.com/micropython/micropython>`_
3018

3119
Usage Example
3220
=============
3321

3422
See examples/simple.py for a demonstration of parsing and printing GPS location.
23+
Please note that ``datalogging.py`` has not been ported from CircuitPython to
24+
Micropython yet.
3525

3626
Contributing
3727
============
@@ -43,27 +33,6 @@ before contributing to help this project stay welcoming.
4333
Building locally
4434
================
4535

46-
To build this library locally you'll need to install the
47-
`circuitpython-build-tools <https://github.com/adafruit/circuitpython-build-tools>`_ package.
48-
49-
.. code-block:: shell
50-
51-
python3 -m venv .env
52-
source .env/bin/activate
53-
pip install circuitpython-build-tools
54-
55-
Once installed, make sure you are in the virtual environment:
56-
57-
.. code-block:: shell
58-
59-
source .env/bin/activate
60-
61-
Then run the build:
62-
63-
.. code-block:: shell
64-
65-
circuitpython-build-bundles --filename_prefix adafruit-circuitpython-gps --library_location .
66-
6736
Sphinx documentation
6837
-----------------------
6938

@@ -85,4 +54,4 @@ Now, once you have the virtual environment activated:
8554
8655
This will output the documentation to ``docs/_build/html``. Open the index.html in your browser to
8756
view them. It will also (due to -W) error out on any warning like Travis will. This is a good way to
88-
locally verify it will pass.
57+
locally verify it will pass.

adafruit_gps.py

+18-25
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
GPS parsing module. Can parse simple NMEA data sentences from serial GPS
2727
modules to read latitude, longitude, and more.
2828
29-
* Author(s): Tony DiCola
29+
* Author(s): Tony DiCola, Alexandre Marquet.
3030
3131
Implementation Notes
3232
--------------------
@@ -38,14 +38,12 @@
3838
3939
**Software and Dependencies:**
4040
41-
* Adafruit CircuitPython firmware for the ESP8622 and M0-based boards:
42-
https://github.com/adafruit/circuitpython/releases
41+
* MicroPython:
42+
https://github.com/micropython/micropython
4343
4444
"""
45-
import time
46-
4745
__version__ = "0.0.0-auto.0"
48-
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_GPS.git"
46+
__repo__ = "https://github.com/alexmrqt/Adafruit_CircuitPython_GPS.git"
4947

5048
# Internal helper parsing functions.
5149
# These handle input that might be none or null and return none instead of
@@ -169,12 +167,11 @@ def _parse_gpgga(self, args):
169167
secs = time_utc % 100
170168
# Set or update time to a friendly python time struct.
171169
if self.timestamp_utc is not None:
172-
self.timestamp_utc = time.struct_time((
173-
self.timestamp_utc.tm_year, self.timestamp_utc.tm_mon,
174-
self.timestamp_utc.tm_mday, hours, mins, secs, 0, 0, -1))
170+
self.timestamp_utc = (
171+
self.timestamp_utc[0], self.timestamp_utc[1],
172+
self.timestamp_utc[2], hours, mins, secs, 0, 0)
175173
else:
176-
self.timestamp_utc = time.struct_time((0, 0, 0, hours, mins,
177-
secs, 0, 0, -1))
174+
self.timestamp_utc = (0, 0, 0, hours, mins, secs, 0, 0)
178175
# Parse latitude and longitude.
179176
self.latitude = _parse_degrees(data[1])
180177
if self.latitude is not None and \
@@ -205,12 +202,11 @@ def _parse_gprmc(self, args):
205202
secs = time_utc % 100
206203
# Set or update time to a friendly python time struct.
207204
if self.timestamp_utc is not None:
208-
self.timestamp_utc = time.struct_time((
209-
self.timestamp_utc.tm_year, self.timestamp_utc.tm_mon,
210-
self.timestamp_utc.tm_mday, hours, mins, secs, 0, 0, -1))
205+
self.timestamp_utc = (
206+
self.timestamp_utc[0], self.timestamp_utc[1],
207+
self.timestamp_utc[2], hours, mins, secs, 0, 0)
211208
else:
212-
self.timestamp_utc = time.struct_time((0, 0, 0, hours, mins,
213-
secs, 0, 0, -1))
209+
self.timestamp_utc = (0, 0, 0, hours, mins, secs, 0, 0)
214210
# Parse status (active/fixed or void).
215211
status = data[1]
216212
self.fix_quality = 0
@@ -237,15 +233,12 @@ def _parse_gprmc(self, args):
237233
# spec and not this code.
238234
if self.timestamp_utc is not None:
239235
# Replace the timestamp with an updated one.
240-
# (struct_time is immutable and can't be changed in place)
241-
self.timestamp_utc = time.struct_time((year, month, day,
242-
self.timestamp_utc.tm_hour,
243-
self.timestamp_utc.tm_min,
244-
self.timestamp_utc.tm_sec,
245-
0,
236+
self.timestamp_utc = (year, month, day,
237+
self.timestamp_utc[3],
238+
self.timestamp_utc[4],
239+
self.timestamp_utc[5],
246240
0,
247-
-1))
241+
0)
248242
else:
249243
# Time hasn't been set so create it.
250-
self.timestamp_utc = time.struct_time((year, month, day, 0, 0,
251-
0, 0, 0, -1))
244+
self.timestamp_utc = (year, month, day, 0, 0, 0, 0, 0)

examples/gps_simpletest.py

+10-17
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,13 @@
11
# Simple GPS module demonstration.
22
# Will wait for a fix and print a message every second with the current location
33
# and other details.
4-
import time
5-
import board
6-
import busio
4+
from machine import UART
5+
import utime as time
76

87
import adafruit_gps
98

10-
11-
# Define RX and TX pins for the board's serial port connected to the GPS.
12-
# These are the defaults you should use for the GPS FeatherWing.
13-
# For other boards set RX = GPS module TX, and TX = GPS module RX pins.
14-
RX = board.RX
15-
TX = board.TX
16-
17-
# Create a serial connection for the GPS connection using default speed and
18-
# a slightly higher timeout (GPS modules typically update once a second).
19-
uart = busio.UART(TX, RX, baudrate=9600, timeout=3000)
9+
# Create a GPS module instance.
10+
uart = UART(1, baudrate=9600, timeout_chars=28800000, pins=('P8','P2'))
2011

2112
# Create a GPS module instance.
2213
gps = adafruit_gps.GPS(uart)
@@ -46,17 +37,19 @@
4637
#gps.send_command('PMTK220,500')
4738

4839
# Main loop runs forever printing the location, etc. every second.
49-
last_print = time.monotonic()
40+
last_print = time.ticks_ms()
5041
while True:
5142
# Make sure to call gps.update() every loop iteration and at least twice
5243
# as fast as data comes from the GPS unit (usually every second).
5344
# This returns a bool that's true if it parsed new data (you can ignore it
5445
# though if you don't care and instead look at the has_fix property).
55-
gps.update()
46+
gps.update()
5647
# Every second print out current location details if there's a fix.
57-
current = time.monotonic()
58-
if current - last_print >= 1.0:
48+
current = time.ticks_ms()
49+
if time.ticks_diff(last_print, current) >= 1000:
5950
last_print = current
51+
52+
gps.update()
6053
if not gps.has_fix:
6154
# Try again if we don't have a fix yet.
6255
print('Waiting for fix...')

0 commit comments

Comments
 (0)