In this video lesson we show you how you can transfer data from your Raspberry Pi Pico W GPS Project to your PC for display on Google Earth. This program transfers the Pi Pico GPS Log file to your PC, and as the transfer is done, the program converts the log.txt file into a .kml file for display on Google Earth.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# ==================================================================== # DISCLAIMER: # This code is provided as-is for educational and experimental # purposes only. The author makes no representations or warranties of # any kind concerning the safety, suitability, or accuracy of this # code. Use at your own risk. The author assumes no liability for any # damages, system failures, security breaches, or network issues # resulting from the use or implementation of this script. # ==================================================================== import serial import time serialPort = 'COM7' baudRate = 115200 ser = serial.Serial(serialPort, baudRate, timeout = .1) ts=1 time.sleep(ts) ser.write(b"f=open('log.txt','r')\r\n") line = ser.readline().decode('utf-8').strip() print("Initial Line: "+line) ts=.1 time.sleep(ts) kmlHeader = """<?xml version="1.0" encoding="UTF-8"?> <kml xmlns="http://www.opengis.net/kml/2.2"> <Document> <name>Path from Pico</name> <Style id="pointStyle"> <IconStyle> <Icon><href>http://maps.google.com/mapfiles/kml/shapes/placemark_circle.png</href></Icon> <scale>1.0</scale> </IconStyle> </Style> <Style id="lineStyle"> <LineStyle><color>ff0000ff</color><width>3</width></LineStyle> </Style> <Placemark> <styleUrl>#pointStyle</styleUrl> <MultiGeometry> """ pointStart = "<Point><coordinates>" pointEnd = "</coordinates></Point>" lineStringStart = """ </MultiGeometry> </Placemark> <Placemark> <name>Path</name> <styleUrl> #lineStyle</styleUrl> <LineString> <tessellate>1</tessellate> <altitudeMode>clampToGround</altitudeMode> <coordinates> """ lineStringEnd = """ </coordinates> </LineString> </Placemark> </Document> </kml> """ with open('path.kml','w') as kml: kml.write(kmlHeader) with open('lon-lat.txt', 'w') as lonLat: pass with open('path.kml','a') as kml: with open('lon-lat.txt','a') as lonLat: while line != "''": ser.write(b"f.readline()\r\n") line = ser.readline().decode('utf-8').strip() line = ser.readline().decode('utf-8').strip() print("LINE: "+line) if line.startswith("'") and line !="''": line = line[1:-3] myData = line.split(',') line = myData[1]+','+myData[0] print("New Line: ",line) kml.write(pointStart+'\n'+line+ '\n'+pointEnd+'\n') lonLat.write(line+ " "+'\n') with open('lon-lat.txt','r') as lonLat: coordinates = lonLat.read() print(coordinates) with open('path.kml','a') as kml: kml.write(lineStringStart+'\n'+ coordinates+lineStringEnd) ser.write(b"f.close()\r\n") ser.close() print("KML File Saved as "+ 'path.kml') |