0

This question already has an answer here:

The image shows the error when running the following code.

import serial               #import serial pacakge
from time import sleep
import webbrowser           
import sys 

def GPS_Info():
    global NMEA_buff
    global lat_in_degrees
    global long_in_degrees
    nmea_time = []
    nmea_latitude = []
    nmea_longitude = []
    nmea_time = NMEA_buff[0]  
    nmea_latitude = NMEA_buff[1]
    nmea_longitude = NMEA_buff[3]
    print("NMEA Time: ", nmea_time,'\n')
    print ("NMEA Latitude:", nmea_latitude,"NMEA Longitude:", nmea_longitude,'\n')
    lat = float(nmea_latitude)             
    longi = float(nmea_longitude)        
    lat_in_degrees = convert_to_degrees(lat)  
    long_in_degrees = convert_to_degrees(longi)
def convert_to_degrees(raw_value):
    decimal_value = raw_value/100.00
    degrees = int(decimal_value)
    mm_mmmm = (decimal_value - int(decimal_value))/0.6
    position = degrees + mm_mmmm
    position = "%.4f" %(position)
    return position

gpgga_info = "$GPGGA,"
ser = serial.Serial ("/dev/ttyS0")    #Open port with baud rate
GPGGA_buffer = 0
NMEA_buff = 0
lat_in_degrees = 0
long_in_degrees = 0

try:
    while True:
        received_data = (str)(ser.readline()) 
        GPGGA_data_available = received_data.find(gpgga_info)  
        if (GPGGA_data_available>0):
            GPGGA_buffer = received_data.split("$GPGGA,",1)[1]
            NMEA_buff = (GPGGA_buffer.split(','))            
            GPS_Info()                                       
            print("lat in degrees:", lat_in_degrees," long in degree: ", long_in_degrees, '\n')
            map_link = 'http://maps.google.com/?q=' + lat_in_degrees + ',' + long_in_degrees  
            print("<<<<<<<<press ctrl+c to plot location on google maps>>>>>>\n")             
            print("------------------------------------------------------------\n")

except KeyboardInterrupt:
    webbrowser.open(map_link)                              
    sys.exit(0)

I ran the code in raspberry pi 3 with NOOBS OS. I tried this link.

The error says.. OSError: [Errorno 16] Device or resource busy: '/dev/ttyS0' and that 'During handling the above expression another error occured' Kindly someone help me..I'm working on the project IoT based Heart rate monitoring system using Raspberry Pi3 and having only 2 days to complete the project..

marked as duplicate by goldilocks Dec 22 '17 at 13:50

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • What error? Put it in your question. People are reluctant to have to view an image to find the error message. – joan Dec 22 '17 at 8:33
  • The error is providing you with a clue: "device or resource busy" means that something else is already using the serial port. It is very likely that your OS is using the serial port as a console. This article discusses the necessary steps to disable the system console and free up the port for other uses. – larsks Dec 22 '17 at 13:41

Browse other questions tagged or ask your own question.