-
Notifications
You must be signed in to change notification settings - Fork 5
/
gnssl76l.py
35 lines (28 loc) · 933 Bytes
/
gnssl76l.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# This file is part of MicroPython GNSSL76L driver
# Copyright (c) 2017 Mika Tuupola
#
# Licensed under the MIT license:
# http://www.opensource.org/licenses/mit-license.php
#
# Project home:
# https://github.com/tuupola/micropython-gnssl76l
"""
MicroPython Quectel GNSS L76-L (GPS) I2C driver
"""
import utime
from machine import I2C, Pin
class GNSSL76L:
def __init__(self, i2c=None, address=0x10):
if i2c is None:
self.i2c = I2C(scl=Pin(26), sda=Pin(25))
else:
self.i2c = i2c
self.address = address
def read(self, chunksize=255):
data = self.i2c.readfrom(self.address, chunksize)
while data[-2:] != b"\x0a\x0a":
utime.sleep_ms(2)
data = data + self.i2c.readfrom(self.address, chunksize)
return data.replace(b"\x0a", b"").replace(b"\x0d", b"\x0d\x0a")
def sentences(self):
return self.read().splitlines()