Guest User

Untitled

a guest
May 16th, 2019
87
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import time
  2. import serial
  3. import string
  4. import pynmea2
  5. import RPi GPIO as gpio
  6. #to add the LCD library
  7. import Adafruit_CharLCD as LCD
  8.  
  9. gpio.setmode(gpio.BCM)
  10.  
  11. #declaring LCD pins
  12. lcd_rs = 17
  13. lcd_en = 18
  14. lcd_d4 = 27
  15. lcd_d5 = 22
  16. lcd_d6 = 23
  17. lcd_d7 = 10
  18.  
  19. lcd_backlight = 2
  20.  
  21. lcd_columns = 16 #Lcd column
  22. lcd_rows = 2 #number of LCD rows
  23.  
  24. lcd = LCD.Adafruit_CharLCD(lcd = LCD.Adafruit_CharLCD(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7, lcd_columns, lcd_rows, lcd_backlight)
  25.  
  26. port = "/dev/ttyAMA0" # the serial port to which the pi is connected.
  27.  
  28. #create a serial object
  29. ser = serial.Serial(port, baudrate = 9600, timeout = 0.5)
  30.  
  31. while 1:
  32.     try:
  33.         data = ser.readline()
  34.     except:
  35. print("loading")
  36. #wait for the serial port to churn out data
  37.  
  38.     if data[0:6] == '$GPGGA': # the long and lat data are always contained in the GPGGA string of the NMEA data
  39.  
  40.         msg = pynmea2.parse(data)
  41.  
  42. #parse the latitude and print
  43.         latval = msg.lat
  44. concatlat = "lat:" + str(latval)
  45.         print concatlat
  46. lcd.set_cursor(0,0)
  47. lcd.message(concatlat)
  48.  
  49. #parse the longitude and print
  50. longval = msg.lon
  51. concatlong = "long:"+ str(longval)
  52. print concatlong
  53. lcd.set_cursor(0,1)
  54. lcd.message(concatlong)
  55.            
  56.     time.sleep(0.5)#wait a little before picking the next data.
RAW Paste Data