Firstly my GPS only blinks led upto 1hour only and thereafter no connection in day. Why it is so? Also my this code is not working (with LCD display). It shows syntax error as

SerialException: could not open port /dev/ttyAMA0: [Errno 13] Permission denied: '/dev/ttyAMA0'

or syntax error. What is problem with that?


import time
import serial
import string
import pynmea2
import RPi GPIO as gpio
#to add the LCD library
import Adafruit_CharLCD as LCD


#declaring LCD pins
lcd_rs = 17
lcd_en = 18
lcd_d4 = 27
lcd_d5 = 22
lcd_d6 = 23
lcd_d7 = 10

lcd_backlight = 2

lcd_columns = 16 #Lcd column
lcd_rows = 2 #number of LCD rows

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)

port = "/dev/ttyAMA0" # the serial port to which the pi is connected.

#create a serial object
ser = serial.Serial(port, baudrate = 9600, timeout = 0.5)

while 1:
        data = ser.readline()
#wait for the serial port to churn out data

    if data[0:6] == '$GPGGA': # the long and lat data are always contained in the GPGGA string of the NMEA data

        msg = pynmea2.parse(data)

#parse the latitude and print
        latval = msg.lat
concatlat = "lat:" + str(latval)
        print concatlat

#parse the longitude and print
longval = msg.lon
concatlong = "long:"+ str(longval)
print concatlong

    time.sleep(0.5)#wait a little before picking the next data.
  • what syntax error are you talking about? – jsotola Jun 23 at 18:55
  • Ah, let me see. My GPS always stays connected, for at least 12 hours, or until I switch off power at mid night. About the "/dev/ttyAMA0" error - if you never got your program running, it might mean that the old name "AMA0" is not there, replaced by the built in UART or USB/UART you are using. – tlfong01 Jun 24 at 0:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.