Composants
- Une carte Arduino Nano
- Un module GPS Ublox neo-6m
- Un adaptateur microSD
- Une plaque à insertion rapide
- Des fils
- Un ordinateur avec l’environnement de développement Arduino
Schéma de câblage
Code
#include « SoftwareSerial.h »
#include <SD.h>
#include <SPI.h>
#include <TinyGPS++.h>
int CS_PIN = 10;
File file;
char data;
double latitude;
double longitude;
double latitudedec;
double longitudedec;
TinyGPSPlus gps;
SoftwareSerial mySerial(4, 5); // RX, TX
void setup()
{
Serial.begin(9600);
Serial.println(« uBlox Neo 6M »);
mySerial.begin(9600);
initializeSD();
}
void loop() // run over and over
{
if (mySerial.available())
{
data = mySerial.read();
// Serial.print(data);
gps.encode(data);
if (gps.location.isUpdated())
{
latitudedec = gps.location.rawLat().billionths;
longitudedec = gps.location.rawLng().billionths;
latitude = gps.location.rawLat().deg;
longitude = gps.location.rawLng().deg;
Serial.println(« ——– FIX GPS ————« );
Serial.print(« LATITUDE= »); Serial.println(latitude);
Serial.print(« LONGITUDE= »); Serial.println(longitude);
File dataFile = SD.open(« datalog.txt », FILE_WRITE);
dataFile.println(String(gps.date.value())+ »; »+String(gps.time.value())+ »; »+String(latitude)+ »; »+String(latitudedec)+ »; »+String(longitude)+ »; »+String(longitudedec));
dataFile.close();
}
}
}
void initializeSD()
{
Serial.println(« Initializing SD card… »);
pinMode(CS_PIN, OUTPUT);
if (SD.begin())
{
Serial.println(« SD card is ready to use. »);
} else
{
Serial.println(« SD card initialization failed »);
return;
}
}
Ci dessous un code en Python pour générer un fichier pour Google-earth
#!/usr/bin/python
import math
import os,sys,glob
import os,commands,sys
import datetime,time
class KML_File:
« For creating KML files used for Google Earth »
def __init__(self, filepath):
self.filepath = filepath
« adds the kml header to a file (includes a default style) »
file = open(filepath, »w »)
file.write(
« <?xml version=\ »1.0\ » encoding=\ »UTF-8\ »?>\n »\
« <kml xmlns=\ »http://www.opengis.net/kml/2.2\ »>\n » \
« <Folder>\n »\
« <name></name>\n »)
file.close()
def close(self):
file = open(self.filepath, »a »)
file.write(« </Folder>\n »)
file.write(« </kml> »)
file.close()
def open_folder(self, name):
file = open(self.filepath, »a »)
file.write(
« <Folder>\n »\
» <name> » + name + « </name>\n »)
file.close()
def close_folder(self):
file = open(self.filepath, »a »)
file.write(
« </Folder>\n »)
file.close()
def add_placemarker(self, allLonAndLat, altitude = 0.0, description = » « , name = » « , range = 6000, tilt = 45, heading = 0):
« adds the point to a kml file »
file = open(self.filepath, »a »)
file.write(
« <Placemark>\n »\
» <description> » + description + « </description>\n »\
» <name> » + name + « </name>\n »\
» <Point>\n »\
» <coordinates> »+allLonAndLat+ »</coordinates>\n »\
» </Point>\n »\
» </Placemark>\n »)
file.close()
def add_coord(self, allLonAndLat, altitude = 0.0, description = » « , name = » « , range = 6000, tilt = 45, heading = 0):
« adds the point to a kml file »
file = open(self.filepath, »a »)
file.write(
« <Placemark>\n »\
» <visibility>1</visibility>\n »\
» <LineString>\n »\
» <extrude>1</extrude>\n »\
» <tessellate>1</tessellate>\n »\
» <altitudeMode>absolute</altitudeMode>\n »\
» <coordinates> » + allLonAndLat + « </coordinates>\n »\
» </LineString>\n »\
» </Placemark>\n »)
file.close()
def convert(val):
eval = int(val/100.)
return eval + (float(val) – eval*100.0)/60.0
if __name__ == « __main__ »:
a=KML_File(« test.kml »)
f=open(‘DATALOG.TXT’,’r’)
lines=f.readlines()
f.close()
prevlat=0
prevlon=0
n=0
for l in lines:
print l
tmp=l.split(‘;’)
londeg=tmp[4].strip()
latdeg=tmp[2].strip()
londec=tmp[5].strip()
latdec=tmp[3].strip()
lat=float(latdeg)+float(latdec)/1000000000.0
lon=float(londeg)+float(londec)/1000000000.0
if float(lon) < 5 or float(lat)< 30:
continue
if lon == prevlon and lat == prevlat:
continue
prevlat=lat
prevlon=lon
desc=tmp[0]+’ ‘+tmp[1]
tname=tmp[0]+’ ‘+tmp[1]
t=str(lon)+ », »+str(lat)
a.add_placemarker(t, altitude = 0.0, description = desc, name=str(n), range = 6000, tilt = 45, heading = 0)
n=n+1
a.close()