Successfully reported this slideshow.

Easy GPS Tracker using Arduino and Python

8,235 views

Published on

Barcelona Python Meetup speech (16th Jan 2013)

Published in: Technology, Business

Easy GPS Tracker using Arduino and Python

  1. 1. Introduction Arduino GPS Maps GUI Python and Arduino Easy GPS Tracker using Arduino and Python Núria Pujol Vilanova Unitat de Tecnologia Marina (CMIMA-CSIC) npujol@utm.csic.es nuriapujolvilanova@gmail.com 16. January 2014 Future
  2. 2. Introduction Arduino GPS Maps What is my spech about? 1 2 3 4 5 Arduino Xbee communications NMEA strings Georefed image GUI using PyQt GUI Future
  3. 3. Introduction Arduino GPS Maps GUI What problem we want to solve? Main objective Looking for a low cost and wide range system to locate AUV. GPRS systems coverage problems far from coast Iridium satellite communication costs Future
  4. 4. Introduction Our Solution Arduino GPS Maps GUI Future
  5. 5. Introduction Arduino GPS Maps GUI Arduino Family ARDUINO UNO CPU Speed: 16MHZ Analog IN: 6 Digital I/O: 14 UART: 1 Flash: 32Kb ARDUINO MEGA CPU Speed: 16MHZ Analog IN: 16 Digital I/O: 54 UART: 4 Flash: 128Kb Future
  6. 6. Introduction Arduino GPS Xbee Devices ZIGBEE Freq: 2.4GHz Power OUT: 63mW* Max. Range: 3.2Km RF Data rate: 250 Kbps 802.11bgn ("Wifi") Freq: 2.4GHz Power OUT: 16 dBm Max. Range: 300m RF Data rate: 65 Mbps "PROPRIETARY" Freq: 868MHz Power OUT: 350mW Max. Range: 40Km RF Data rate: 24 Kbps * 10mW limited in most EU Maps GUI Future
  7. 7. Introduction Arduino GPS Maps How can I program my Arduino? Arduino IDE Classical way to program your Arduino Using Python Libraries: Python Arduino Prototyping, Pyduino, Pyfirmata,etc. PyMite (Python-on-chip) GUI Future
  8. 8. Introduction Arduino GPS Maps How can I configure Xbee comunication? Manufacturer software (X-CTU) Moltosenso Network Manager Serial Port (pyserial) GUI Future
  9. 9. Introduction Arduino GPS Maps GUI 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 7 FF1 r ’ ’) >>> ser . read (8) ’ OK r7FF1 r ’ >>> ser . write ( ’ +++ ’) >>> ser . write ( ’ ATRE r ’) >>> ser . write ( ’ ATCN r ’) Future
  10. 10. 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); }
  11. 11. Introduction Arduino GPS Maps 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 GUI Future
  12. 12. Introduction Arduino GPS Maps Programing example with Python from arduino import Arduino import time b = Arduino ( ’/ dev / ttyUSB0 ’) pin = 9 # declare output pins as a list / tuple b . 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/ GUI Future
  13. 13. 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 = 8 5 2 3 5 3 5 3 1 3 7 3 5 1 1 1 8 1 1 2 ’) >>> ser = serial . Serial ( ’/ dev / ttyUSB0 ’ ,9600) >>> ser . inWaiting () 243 >>> ser . readline () ’ $GPGGA ,203156.000 ,4122.5905 , N ,00208.1725 , E ,...*5 r r n ’
  14. 14. Introduction Arduino GPS Maps GUI 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(41o 22.5950’ N)→41+(22.5950/60)=41.376583 N LON: 00208.1621 E(2o 08.1621’ E)→2+(0.81621/60)=2.136035 E Decimal to UTM conversion def from_latlon ( latitude , longitude ) def LLtoUTM ( ReferenceEllipsoid , Lat , Long ) Future
  15. 15. Introduction Arduino GPS Maps Georefed images formats TIFF + TFW ⇐⇒ GeoTIFF Using a .tif file and a .tfw Geotiff (embedded georeferencing information) Where to obtain this files for free? Institut Cartogràfic de Catalunya Centro Nacional de Información Geográfica GUI Future
  16. 16. Introduction Arduino GPS Georefed images formats exemple.tfw 0.93 187659192 3412 0.00 000000000 0000 0.00 000000000 0000 -0.931876591923412 41 4 6 8 5 . 6 8 3 8 9 8 5 8 0 1 4 0 0 0 0 4570442.677152497700000 Maps GUI Future
  17. 17. Introduction Arduino GPS Maps GUI Future How to plot a GeoTIFF? from osgeo import gdal import matplotlib . pyplot as plt gtif = gdal . Open ( ’ canal . tif ’) gtif . G et P r o j e c t i o n R e f () gtif_array = gtif . ReadAsArray () tfw = gtif . G et G eo Tr a ns f or m () A ,D ,B ,E ,C , F = tfw [1] , tfw [2] , tfw [4] , tfw [5] , tfw [0] , tfw [3] L = gtif . RasterXSize H = gtif . RasterYSize BLX , 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 . t i c k l a b e l _ f o r m a t ( useOffset = False , axis = ’ both ’) plt . imshow ( gtif_array [:3 ,: ,:]. transpose ((1 ,2 ,0)) , extent = extent ) plt . show ()
  18. 18. Introduction Arduino GPS Maps GUI How to plot a TIFF? import matplotlib . pyplot as plt twf_values =[] file = open ( ’ c a na l_ E TR 89 _ H3 1 . tfw ’ , " r " ) for line in file : twf_values . append ( float ( line )) A , D , B , E , C , F = twf_values file . close () file_im = plt . imread ( ’ ca na l _E T R8 9_ H 31 . 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 . t i c k l a b e l _ f o r m a t ( useOffset = False , axis = ’ both ’) plt . imshow ( file_im , extent =[ BLX , TRX , TRY , BLY ]) plt . show () Future
  19. 19. Introduction Obtained Plot Arduino GPS Maps GUI Future
  20. 20. Introduction Arduino GPS Maps Adding GUI Eric Python IDE GUI Future
  21. 21. Introduction Arduino GPS Maps Adding GUI Qt 4 Designer GUI Future
  22. 22. Introduction Final Result Arduino GPS Maps GUI Future
  23. 23. Introduction Arduino GPS Future plans Optimization Coverage range testing Field Tests Get range and bearing AUV utilities using Xbee Maps GUI Future
  24. 24. Introduction Arduino GPS Maps QUESTIONS? GUI Future

×