Skip to content

Instantly share code, notes, and snippets.

@robomike
Created May 17, 2017 16:11
Show Gist options
  • Save robomike/236bd07c810e7e87d6226daa3a093f2c to your computer and use it in GitHub Desktop.
Save robomike/236bd07c810e7e87d6226daa3a093f2c to your computer and use it in GitHub Desktop.
uart code cpy
#NMEA Reader for Circuit Python
#Written by Mike Letsky
import busio
import board
def getPosition():
global gpsUart
global byte
global sync
global msgId
global byteArray
gpsUart = busio.UART(board.TX, board.RX,baudrate=9600)
#read each byte until we find a start byte
sync = [0x24]
msgId = 'GNS'
byteArray = bytearray(100)
print('debug 1')
## while msgId in byteArray is False:
## find sync
newbyteArray = bytearray(100)
byteArray= gpsUart.readline()
gpsMessage=str(byteArray).split(',')
while (msgId in byteArray) is False:
byteArray= gpsUart.readline()
## newbyteArray= gpsUart.read(1)
## print(newbyteArray)
print(byteArray)
gpsMessage=str(byteArray).split(',')
## print(byteArray)
startPos=0
## startPos = gpsMessage.index(msgId)
## print(startPos)
## msgId=gpsMessage[startPos]
## print('msgId ' + msgId)
## time=gpsMessage[startPos+1]
## lat=gpsMessage[startPos+2]
## NS=gpsMessage[startPos+3]
## lon=gpsMessage[startPos+4]
## EW=gpsMessage[startPos+5]
## posMode=gpsMessage[startPos+6]
## print('lat '+lat)
## print('lon '+lon)
## print('time '+time)
## print('posMode '+ posMode)
return lat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment