Advertisement
Guest User

Untitled

a guest
Feb 18th, 2020
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.99 KB | None | 0 0
  1. import serial
  2. import time
  3.  
  4. ser = serial.Serial('/dev/ttyS0') #åbner port.
  5.  
  6. running = True
  7.  
  8. try:
  9.     while running:
  10.         data = ser.readline()
  11.         #print(data)
  12.         for line in data.split(b'\n'):
  13.             if line.startswith(b'$GPGGA'):    
  14.                 line = str(line.decode("UTF-8"))
  15.                 line = line.split(",")
  16.                 latitude = line[2]
  17.                 north = line[3]            
  18.                 longtitude = line[4]
  19.                 east = line[5]
  20.                 gps = latitude + north + " " + longtitude + east
  21.                 lat_b = float(latitude[2:8]) / 60
  22.                 lat_a = float(latitude[0:2])
  23.                 print(lat_a + lat_b)
  24.                 long_b = float(longtitude[3:9]) / 60
  25.                 long_a = float(longtitude[0:3])
  26.                 print(long_b + long_a)
  27.                 print(gps)
  28.                
  29.          
  30. except KeyboardInterrupt:
  31.     print("program lukker")
  32.     running = False
  33.     ser.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement