easy gps tracker using arduino and python
Post on 14-Jun-2015
5.150 Views
Preview:
DESCRIPTION
TRANSCRIPT
Introduction Arduino GPS Maps GUI Future
Python and ArduinoEasy GPS Tracker using Arduino and Python
Núria Pujol VilanovaUnitat de Tecnologia Marina (CMIMA-CSIC)
npujol@utm.csic.esnuriapujolvilanova@gmail.com
16. January 2014
Introduction Arduino GPS Maps GUI Future
What is my spech about?
1 Arduino2 Xbee communications3 NMEA strings4 Georefed image5 GUI using PyQt
Introduction Arduino GPS Maps GUI Future
What problem we want to solve?
Main objectiveLooking for a low cost and wide range system to locate AUV.
GPRS systems coverage problems far from coastIridium satellite communication costs
Introduction Arduino GPS Maps GUI Future
Our Solution
Introduction Arduino GPS Maps GUI Future
Arduino Family
ARDUINO UNOCPU Speed: 16MHZ
Analog IN: 6Digital I/O: 14
UART: 1Flash: 32Kb
ARDUINO MEGACPU Speed: 16MHZ
Analog IN: 16Digital I/O: 54
UART: 4Flash: 128Kb
Introduction Arduino GPS Maps GUI Future
Xbee Devices
ZIGBEEFreq: 2.4GHzPower OUT: 63mW*Max. Range: 3.2KmRF Data rate: 250 Kbps
802.11bgn ("Wifi")Freq: 2.4GHzPower OUT: 16 dBmMax. Range: 300mRF Data rate: 65 Mbps
"PROPRIETARY"Freq: 868MHzPower OUT: 350mWMax. Range: 40KmRF Data rate: 24 Kbps
* 10mW limited in most EU
Introduction Arduino GPS Maps GUI Future
How can I program my Arduino?
Arduino IDEClassical way to program your Arduino
Using Python Libraries:Python Arduino Prototyping, Pyduino, Pyfirmata,etc.PyMite (Python-on-chip)
Introduction Arduino GPS Maps GUI Future
How can I configure Xbee comunication?
Manufacturer software (X-CTU)Moltosenso Network ManagerSerial Port (pyserial)
Introduction Arduino GPS Maps GUI Future
Pyserial example using AT commands
>>>import serial>>>ser=serial.Serial(’/dev/ttyUSB0 ’,baudrate =9600)
>>> ser.write(’+++’)>>> ser.write(’ATID\r’)>>> ser.read (8)’OK\r7FFF\r’
>>> ser.write(’+++’)>>>ser.write(’ATID 7FF1\r’’)>>> ser.read (8)’OK\r7FF1\r’
>>> ser.write(’+++’)>>>ser.write(’ATRE\r’)>>>ser.write(’ATCN\r’)
Introduction Arduino GPS Maps GUI Future
Programing example with Arduino IDE
#include <SoftwareSerial.h>#define rxPin 9#define txPin 8
SoftwareSerial gps = SoftwareSerial(rxPin , txPin);
*VARIABLES*
void setup (){pinMode(rxPin , INPUT);pinMode(txPin , OUTPUT );gps.begin (4800);Serial.begin (9600);delay (1000);
}
Introduction Arduino GPS Maps GUI Future
Programing example with Arduino IDE
void loop (){byteGPS = 0;byteGPS = gps.read ();while(byteGPS != ’$’){
byteGPS = gps.read ();}(*)byteGPS = gps.read ();if(byteGPS == ’G’){ (*)
while(byteGPS != ’*’){
byteGPS = gps.read ();GPS[i] = byteGPS;i++;
}(*)while(j<i){
Serial.write(char(GPS[j]));j++;
}Serial.println ();
}}
(*) Missing lines of code
Introduction Arduino GPS Maps GUI Future
Programing example with Python
from arduino import Arduinoimport time
b = Arduino(’/dev/ttyUSB0 ’)pin = 9
#declare output pins as a list/tupleb.output ([pin])
for xrange (10):b.setHigh(pin)time.sleep (1)print b.getState(pin)b.setLow(pin)print b.getState(pin)time.sleep (1)
b.close()
https://github.com/vascop/Python-Arduino-Proto-API-v2/
Introduction Arduino GPS Maps GUI Future
After programing what we get?
>>>import serial>>>from serial.tools import list_ports>>> for port in list_ports.comports ():... print port...(’/dev/ttyUSB0 ’ ,...,’VID:PID =0403:6001 SNR=A9014UV2 ’)(’/dev/ttyACM0 ’ ,...,’VID:PID =2341:0043 SNR =85235353137351118112 ’)
>>> ser=serial.Serial(’/dev/ttyUSB0 ’ ,9600)>>> ser.inWaiting ()243>>> ser.readline ()’$GPGGA ,203156.000 ,4122.5905 ,N ,00208.1725 ,E ,...*5\r\r\n’
Introduction Arduino GPS Maps GUI Future
NMEA Strings
GPGGA,203156.000,4122.5950,N,00208.1621,E,1,05,1.7,-21.8,M,51.0
NMEA to Decimal conversion
LAT: 4122.5950 N(41o22.5950’ N)→41+(22.5950/60)=41.376583 NLON: 00208.1621 E(2o08.1621’ E)→2+(0.81621/60)=2.136035 E
Decimal to UTM conversion
def from_latlon(latitude , longitude)def LLtoUTM(ReferenceEllipsoid , Lat , Long)
Introduction Arduino GPS Maps GUI Future
Georefed images formats
TIFF + TFW ⇐⇒ GeoTIFF
Using a .tif file and a .tfwGeotiff (embedded georeferencing information)
Where to obtain this files for free?Institut Cartogràfic de CatalunyaCentro Nacional de Información Geográfica
Introduction Arduino GPS Maps GUI Future
Georefed images formats
exemple.tfw
0.9318765919234120.0000000000000000.000000000000000-0.931876591923412414685.6838985801400004570442.677152497700000
Introduction Arduino GPS Maps GUI Future
How to plot a GeoTIFF?
from osgeo import gdalimport matplotlib.pyplot as plt
gtif=gdal.Open(’canal.tif’)gtif.GetProjectionRef ()gtif_array=gtif.ReadAsArray ()tfw=gtif.GetGeoTransform ()A,D,B,E,C,F=tfw[1],tfw[2],tfw[4],tfw[5],tfw[0],tfw [3]L=gtif.RasterXSizeH=gtif.RasterYSizeBLX , BLY , TRX , TRY=C, F, C+(L*A), F+(H*(E))extent =[BLX , TRX , TRY , BLY]fig = plt.figure ()axes = fig.add_subplot (111)axes.ticklabel_format(useOffset=False ,axis=’both’)
plt.imshow(gtif_array [:3,:,:]. transpose ((1,2,0)), extent=extent)plt.show()
Introduction Arduino GPS Maps GUI Future
How to plot a TIFF?
import matplotlib.pyplot as plt
twf_values =[]file=open(’canal_ETR89_H31.tfw’, "r" )
for line in file:twf_values.append(float(line))
A, D, B, E, C, F=twf_valuesfile.close()
file_im=plt.imread(’canal_ETR89_H31.tif’, "r" )L=len(file_im[1, :])H=len(file_im[:, 1])BLX , BLY , TRX , TRY=C, F, C+(L*A), F+(H*(E))
fig = plt.figure ()axes = fig.add_subplot (111)axes.ticklabel_format(useOffset=False , axis=’both’)
plt.imshow(file_im , extent =[BLX , TRX , TRY , BLY])plt.show()
Introduction Arduino GPS Maps GUI Future
Obtained Plot
Introduction Arduino GPS Maps GUI Future
Adding GUI
Eric Python IDE
Introduction Arduino GPS Maps GUI Future
Adding GUI
Qt 4 Designer
Introduction Arduino GPS Maps GUI Future
Final Result
Introduction Arduino GPS Maps GUI Future
Future plans
OptimizationCoverage range testingField Tests
Get range and bearingAUV utilities using Xbee
Introduction Arduino GPS Maps GUI Future
QUESTIONS?
top related