use gps unit with arduino microcontroller

Upload: mauricio-rezende-de-oliveira

Post on 04-Apr-2018

231 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/30/2019 Use GPS unit with Arduino microcontroller

    1/46

    Use of a GPS unit & The Arduino

    Microcontroller for Surveying.

    July 2, 2012

  • 7/30/2019 Use GPS unit with Arduino microcontroller

    2/46

    Abstract

    The experiment to which this paper concentrates on aims to use the Arduino

    microcontroller, a programmable 8 bit microprocessor complete with I/Ocomponents etc, and a simple GPS unit to make a basic surveying unit. Inorder to do this various topics are touched upon. The method of communi-cation between the Arduino and GPS is explored in detail in as much as thetype of data the position data is received in, the methods the Arduino canemploy to extract this data and finally how the Arduino can use this data fordistance and area calculations. The Arduino is capable of taking GPS datathat comes in the form of NMEA sentences and strip the desired ASCII char-acters representing position coordinates from the sentence. These can thenbe converted to floating point numbers and used for arithmetic such as find-

    ing distances between two points of latitude and longitude. With a methodof finding distances established a program or sketch to find the area of anirregular sketch was written that successfully calculates the area and plotsout the shape on a colour LCD. The error associated with this method wasalso established with an understanding that the percentage error decreaseswith increasing distance.

  • 7/30/2019 Use GPS unit with Arduino microcontroller

    3/46

    Contents

    1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

    2.1 The Arduino Microcontroller . . . . . . . . . . . . . . . 22.2 EM-406A GPS module . . . . . . . . . . . . . . . . . . 42.3 Phi II Shield LCD . . . . . . . . . . . . . . . . . . . . 52.4 Sparkfuns 08600 colour LCD . . . . . . . . . . . . . . 5

    3 Method and Algorithms . . . . . . . . . . . . . . . . . . . . . 63.1 Sentence Isolation . . . . . . . . . . . . . . . . . . . . . 73.2 Determination of Distance using Latitude and

    Longitude . . . . . . . . . . . . . . . . . . . . . . . . . 83.3 The Calculation of the Area of an Irregular Shape . . . 93.4 The Integration of Sparkfuns 08600 Colour LCD . . . 10

    4 Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114.1 Time and Location Display Sketch . . . . . . . . . . . 114.2 Relative Distance Sketch . . . . . . . . . . . . . . . . . 124.3 Irregular Area Sketch . . . . . . . . . . . . . . . . . . . 134.4 Evaluation of Errors . . . . . . . . . . . . . . . . . . . 18

    5 Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205.1 Advancements and Improvements . . . . . . . . . . . . 205.2 Discussion of Errors . . . . . . . . . . . . . . . . . . . 22

    6 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

    1 Appendix A: Sentence Isolation Sketch . . . . . . . . . . . . . 262 Appendix B: Time and Location Display Sketch . . . . . . . . 263 Appendix C: Relative Distance Sketch . . . . . . . . . . . . . 284 Appendix D: Irregular Area Sketch . . . . . . . . . . . . . . . 335 Appendix E: Error Estimation . . . . . . . . . . . . . . . . . . 44

    1

  • 7/30/2019 Use GPS unit with Arduino microcontroller

    4/46

    1 Introduction

    This project puts to the test the adaptability of the Arduino to practicaltasks, using data to create an informative output and to see how portable itcan be. The task set to the Arduino in this project is to see if it can take serialdata from a GPS unit and use it to firstly to display position informationonto LCDs. This examines the Arduinos capability to take informationfrom one source and manipulate it into a form that will be accepted by anoutput device like an LCD.

    Secondly to use latitude and longitude information to find the distancetravelled by the user as the crow flies. This task requires conversion of data

    to integers that can be used for arithmetic. Also requires the Arduino to savelatitude and longitude values until such time as they are to be put to use.Thirdly this project explores if the Arduino can use this distance infor-

    mation to find areas of simple and complicated shapes. This necessitates theneed of a well written code and the memory in the Arduino in which to takethis code and put it to use in the field.

    Lastly this project questions whether all of the above components canbe expressed on a colour 132 132 pixel LCD. For this a library has to becreated or found that will allow the plotting of the irregular area being cal-culated by the Arduino. Also the toll on battery life is recorded thus makinga direct impact on the units portability.

    2 Background

    2.1 The Arduino Microcontroller

    The Arduino is a programmable 8-bit microcontroller that is capable ofmanipulating a series of periphery devices based on the program or with aprogram that uses serial data from another periphery device. For example athermistor could be connected up to the Arduino and the Arduino in turnconnected up to a small piston device. Based on the temperature valuescoming in from the thermistor the Arduino could open or close a windowin response. Other examples of periphery devices include LEDs, LCDsand GPS units which is the device featured in this report. The Arduino is amarriage of two separate projects both aimed at making a certain specializedfield more accessible to either the public or to students.

    The first of these projects is called the Wiring project aimed at making auser friendly library of commands based on C complete with a programming

    2

  • 7/30/2019 Use GPS unit with Arduino microcontroller

    5/46

    (a) EM-406A GPS Unit [Spa12a] (b) Arduino Mega 2560 [BCI+

    12f]

    framework that would compile this code and upload it to your microcon-troller [BHB12]. Traditional microcontrollers are programmed with C aloneand as such getting the microcontroller to light a single LED was a chal-lenge even for the intermediate programmer. The creation of a library forcommon microcontroller tasks was an initiative to get artists and hobbyistsmore interested in digital electronics by making it more accessible to nonprofessionals.

    The second project named Processing had the same project idea in mind

    but with software literacy in the visual arts [FR12]. The purpose of Pro-cessing initially was to be a tool for teaching computer programming in thecontext of the visual arts but it quickly became the tool of choice for profes-sional work in this field also.

    The Arduino team took the library from Wiring and adapted it for theirown line of microcontrollers. The development environment was fashionedafter Processing in order to write, compile and upload the code to the Arduinoboards [BCI+12d]. The result is the Arduino community with a series ofboards and an Arduino playground full of advice and fledgling ideas keptup to date by beginners and experts alike.

    The board used in this project is the Arduino Mega 2560, one if thelarger boards it houses 54 digital input and output pins of which 14 arecapable of pulse width modulation output, 16 analog inputs and 4 hardwareserial ports. The board can either be powered by a USB connection or by astandard battery [BCI+12f, Ard12].

    3

  • 7/30/2019 Use GPS unit with Arduino microcontroller

    6/46

    (a) Phi II Shield (b) 08600 LCD [Spa12b]

    2.2 EM-406A GPS module

    The EM406-A GPS module distributed by Sparkfun and made by USGlob-alSat is a small 30 30 mm unit that serially outputs GPS information witha quoted accuracy of 10 m 2DRMS. 2DRMS means twice the distance rootmean square which quotes the accuracy of the unit in terms of circular errorprobability. In this case it means that the position given by the GPS will be

    within a circle of 10 m radius 95% of the time [Spa12a, Cor12].It houses the SiRF StarIII chipset which is a piece of silicon capableof locking to GPS signals and passing coordinate information to the minicomputer housed within the unit. The GPS signal carries with it a record oftime of when it left the satellite. Its the StarIII job to use that informationto find the distance the satellite is from the unit. If in canyon like area thesignals could be reflected off walls thus introducing considerable error. TheStarIII has a series of tricks to correct this and is the main reason for itspopularity as a chip in GPS modules as it enhances the signal aquistion inurban or canopy environments [Owi06].

    The module also has an embedded antenna which aids in signal aquistion

    as well as a LED status indicator and 6 pin cable interface enabling it to bepinned to the Arduino Mega 2560 [Spa12a]. Using this 6 pin cable the GPScan be connected serially to the Arduino in order to transmit position datato the Arduino. The data the GPS outputs comes in the form of NMEAsentences which is a data transmission protocol inherited from the NationalMarine Electronics Association. The NME Association use this ASCII basedprotocol to transmit position data to their various vessels throughout theworld [DeP12].

    There are 4 unique sentences characterised by the first 6 ASCII characters

    4

  • 7/30/2019 Use GPS unit with Arduino microcontroller

    7/46

    in the sentence; $GPRMC, $GPGGA, $GPGSA and $GPGSV. They all carry

    specific set of information such as time, latitude, longitude, satellite statusand several more. The sentence used in this project is the $GPGGA line asit contains all the information required [DeP12].

    2.3 Phi II Shield LCD

    The Phi II Shield is a simple 20 4 LCD that fits virtually every Ar-duino model [Liu11a]. The LiquidCrystal library is used to program infor-mation onto the LCD which is a default library of the Arduino softwarepackage [BCI+12e]. This allows the user to display text anywhere on the

    LCD whether it be ASCII or serial information from a peripheral devicesuch as temperature values from a thermistor. The location of text has tobe stated explicitly as there is overflow problems with this LCD, for exampletext going off the edge of the first row will appear coming backwards on thethird row. However this LCD is still the most popular choice among Arduinousers.

    For a more comprehensive set of commands for this LCD there is also adownloadable library that allows the creation of menus onto the Shield aswell as scrolling options and button control [Liu11b]. It is this LCD that isused mostly for this project for its easily programmable and doesnt drain

    as much power as the 08600.

    2.4 Sparkfuns 08600 colour LCD

    The 08600 is a 132 132 pixel colour LCD and is a knockoff model ofthe LCDs found in Nokia 6100 mobile phones. It has 12 pinouts, 10 ofwhich have to have 3.3V input, 1 pin for the backlight that needs to drawa sufficient amount of power for the voltage booster to produce 7V requiredfor the backlight and a pin for ground [Spa12b, Owe10].

    One particular issue with this LCD is the ambiguity of the graphics con-troller it has, whether it be a Philips or an Epson [Lyn12]. The documen-

    tation contains all the information necessary to build a library to programthe LCD however the syntax is different for both Philips and Epson. Sincebuilding a library for this is a big undertaking and time was limited, a prebuilt library online had to be used.

    5

  • 7/30/2019 Use GPS unit with Arduino microcontroller

    8/46

    Figure 1: Algorithm for compiling sentences and displaying information

    3 Method and Algorithms

    For the main aim of the project only the Arduino and the GPS werenecessary and as such were the only components, along with the Phi II shield,that were used for the majority of the project duration. The Sparkfun 08600was left as an optional add-on at the end as to get it operational in anypractical sense required an external library which at the moment is still indevelopment.

    To begin the project a solid foundation of understanding had to be es-tablished in terms of getting the GPS to converse with the Arduino and toget the Arduino to extract relevant substrings of information to be put touse in various possible scenarios. The Arduino and the GPS are connected

    serially through serial port 3 which comprise of pin 15 (RX) and pin 14 (TX)[Cor12], there are two pins grounded to the same Arduino pin in addition tothe 5V power and the 1 pulse per second wired to a +5V pin and pin 16 re-spectively. With the baud rate set to 4800 bps in setup the NMEA sentencescan be displayed on a computer monitor using the USB serial connection ofthe Arduino and the computer. With this an understanding of the NMEAsentences is achieved and a sketch to extract information such as latitudeand longitude can begin to be realised.

    The 08600 LCD requires a voltage of 3.3V for the serial peripheral in-

    6

  • 7/30/2019 Use GPS unit with Arduino microcontroller

    9/46

    Figure 2: Algorithm for finding the distance travelled using Lat and Longinformation

    terface pins [Spa12b] used for communicating with peripheral devices so avoltage divider is used utilising three resistors to convert 5V from the Ar-duino pins to 3V for the 08600. These pins are connected to the J1 line ofpins on the Arduino Mega in order to avoid bus contention that would occurshould they be wired to the digital pins 0-13 line to which the Phi II shield isconnected. The 08600 also requires 7V for the backlight. There is a voltagebooster fitted into the 08600 itself so a 5V or a 3.3V Arduino pin can sup-ply the power, the current drawn from 3.3V being 324mA and from a 5V thepower drawn is 120mA [Spa12b, Owe10]. The 5V pin is used to supply powerto the backlight and a 3.3V pin for the rest (for a schematic representation,refer to the Appendices). Wiring the board to ground a default blue colourappears on the LCD indicating its ready for use.

    3.1 Sentence Isolation

    An algorithm to isolate the NMEA sentence $GPGGA and extract infor-mation is featured in figure 1. The first hurdle of this project was the NMEAsentence isolation. Since the Arduino receives one ASCII symbol at a timefrom the GPS a method of compiling had to be decided upon. In order to beable to extract relevant chunks of information, all of the information has tobe stored in a data array of some kind and kept in memory until such time

    7

  • 7/30/2019 Use GPS unit with Arduino microcontroller

    10/46

    that its needed for data extraction. For this problem, the String Object

    function in the Arduino reference library [BCI+12e] was looked into as wellas research into traditional C character arrays and the various ways in whichthey can be manipulated.

    For any data to be extracted they have to have a String or an arraywaiting for them to be placed into thereby indicating multiple array variablesare needed. Once extracted they are still ASCII characters which can bedisplayed on the Phi II to give time, latitude and longitude as well as howmany satellites the module has locked on to.

    Once completed this sketch becomes an integral external function for allfuture sketches concerning the GPS module. The first step required for any

    work to be carried out using the module is compiling the sentences, grabbingthe right sentence and finally the information, most important being thesatellite information which keeps the user informed of the relative reliabilityof the incoming information based on how many satellites are in view.

    3.2 Determination of Distance using Latitude and

    Longitude

    As mentioned before, the previous algorithm is the base for the algorithmdiscussed in this section. The flowchart is featured in figure 2. There are two

    main reasons for considering this algorithm. The first is to put the relativeaccuracy of the GPS to the test by getting the Arduino, using the data fromthe GPS, to find a fixed known distance repeatedly and use the data forstatistical analysis. The second is to be able to calculate distance for futuresketches such as the irregular area sketch.

    For this sketch to work it needs to follow the following logic. The amountof satellites that the module is locked onto has to be known in order to mon-itor the number for accuracy considerations. For distance calculations anapproximation is made with respect to the spherical coordinates that lati-tude and longitude are derived from. Since the distances under considerationhere are very small, the curvature of the Earth doesnt really impact on thecalculations thus for this project cartesian coordinates are used based on theunderstanding that the error associated with this assumption is negligiblysmall. With this assumption in place the distance can be determined usingPythagoras theorem providing the latitude and longitude are converted fromdegree minutes to meters. The conversion factors for latitude and longitudecan be determined in ones locality from an ordnance survey map. A map ofeast Galway region was used for this purpose [oI98] and were found to be,

    8

  • 7/30/2019 Use GPS unit with Arduino microcontroller

    11/46

  • 7/30/2019 Use GPS unit with Arduino microcontroller

    12/46

    rectangles and triangles from minimum longitude back around to maximum

    longitude are added together separately. The difference between these twoallocated areas should give out the area of the irregular shape.

    For the Arduino to be able to carry out this algorithm, the sketch will haveto meet a few key requirements. The algorithm requires the max and min ofboth latitude and longitude so an external function is needed to determinethem. The sketch should have a way to organise the points so as to start fromthe maximum longitude and end back at the same maximum longitude. Thesketch also needs to be a general sketch that should work for a regular triangleright up to an irregular shape like the one in figure 3. This means that thesketch has to written in a non specific fashion so as to apply to the widest

    range of shapes as possible. Thus the main body of this sketch will be anexternal function that finds the distances for the sides of the rectangles andtriangles, the amount of which depends on the amount of points taken andthe amount of points between the maximum and minimum of both latitudeand longitude. In using the amount of points to govern how the rest of thecode operates ensures that it should behave appropriately for the shape beingconsidered, the maximum and minimum also serve to characterize the shapereinforcing the logic that is followed by using the points as markers for howmany distances to calculate. Once the distances are calculated the areas haveto be determined. This can be done with the number of input points just

    like the distances.With this point logic in place the area of relatively any shape can becharacterised.

    3.4 The Integration of Sparkfuns 08600 Colour LCD

    The inclusion of the 08600 was questionable for most of the project as anArduino library or any interface library for the module is yet to be fully re-alised. There are several libraries online that are half complete and only workfor specific types of knockoff LCDs [For10]. The main problem being facedwith this as mentioned in the background section is the telling whether you

    have a Philips graphics controller or an Epson [Lyn12]. This is important toknow as the two are treated differently code wise in other words the languagebeing sent to it needs to be its native language or else it wont do anything.The 08600 according to Sparkfun has an Epson controller as they are a cloneof older Sparkfun versions however they often refer to Philips controllers invarious example codes which has left the issue somewhat confusing [Lyn12].

    The only way to include this in the project is to explore the various forumsconcerning the LCD and work through their workings and see if the sameresults appear on the LCD here. This requires an untold amount of time

    10

  • 7/30/2019 Use GPS unit with Arduino microcontroller

    13/46

    Figure 4: NMEA sentences

    which is the reason it is left as the last order of business.If a library is found then the 08600 can be used to draw the area under

    consideration to give the user an idea of the shape the Arduino is dealing withthus enabling assurance that the Arduino is considering the correct shape.

    4 Results

    This section consists of the final working sketches of the algorithms de-scribed above. The key syntax elements that help overcome problems thatwere mentioned previously are described in full and they can be viewed inthe code in the appendices where the full sketches are located. Also exploredis the evolution of the algorithms in order to move around or accommodateproblems faced in the coding process or indeed problems faced in the runningof the code that forced the algorithm to be revised.

    4.1 Time and Location Display Sketch

    The sketch for time and location display works exactly how the algorithmdisplayed in figure 1 portrays. Reading incoming data serves to recognise theinstance on a $ sign which indicates the beginning of a sentence. Oncereceived the code jumps to an external function and into a while loop wherethe incoming characters are added to a string object up until the ASCIIcharacter for carriage return is received. Upon reading carriage return thereis a filter in the form of an if loop to test if the sentence is $GPGGA, if notthe string object containing the tested sentence is emptied and built again

    until such time when the sentence is $GPGGA in which case its let throughwith the full sentence intact [DeP12].

    To show the time, latitude and longitude the appropriate sections of thesentence have to be plucked out. For time it is characters from 8-14, forlatitude its characters 19-30 and for longitude its 31-43. The latitude andlongitude will only be displayed however if the character at position 44 ofthe sentence is 1 indicating that there are satellites present. If the value is 0then there are no satellites and no latitude and longitude information thusnone shall be displayed.

    11

  • 7/30/2019 Use GPS unit with Arduino microcontroller

    14/46

  • 7/30/2019 Use GPS unit with Arduino microcontroller

    15/46

  • 7/30/2019 Use GPS unit with Arduino microcontroller

    16/46

    input array then all the points before it will be at the end after the last

    value of the input array in the organised array, thereby shifting the pointsbefore the maximum longitude and moving them to the end. The organisefunction also records the index value for the maximum and minimum valuesfor latitude and longitude that are now in the organised array. The indexvalue for maximum longitude will always be zero in the organised array.

    Distances for Area Calculation of Triangles and Rectangles

    Following the organisation function is the function to find the distancesrequired to find the area of the rectangles and triangles of the shape dictated

    by the organised points called tri() in the code. This is where using theindex values of arrays is put to its greatest use. The index locations aremanipulated in order to move around the shape point by point. This is doneto get distances required for area calculations which all takes place insideof for loops controlled by index logic. The for loop for points from maxlongitude to the max latitude for example runs until the control integer of thefor loop equals the index number of the maximum latitude. The same logicis used for the other two sections of the shape namely the points betweenand including the maximum latitude and the minimum longitude and thepoints from minimum longitude to the minimum latitude. The last quadrantis characterised by a for loop also but only to the last point of the latitude

    and longitude arrays. The distance for the triangle and rectangle for the lastarray point to the maximum longitude, which is the first point in the array,is calculated by a snippet of code directly after the last for loop that endsupon the event at which the control integer of the for loop equals array indexnumber of the last point in the array.

    Inside of the for loop is the code that finds all the distances of the sideof the rectangles and triangles of the shape. The way in which it goes aboutdoing this is featured in figures 5 and 6. Figure 5 features the path the codetakes around the shape for the segment of maximum longitude to maximumlatitude and also the segment of minimum longitude to minimum latitude.

    The pattern is slightly different for the other two sectors shown in figure 6.This difference is to account for the change in direction of the path the codehas to take, one pattern having to get the distance of the triangle base andthen the perpendicular height like in the maximum longitude to maximumlatitude segment, the other pattern then having to get the perpendicularheight first and then the base like the maximum latitude to minimum longi-tude segment. Likewise for the rectangle distance calculations the distancefrom a rectangle point to minimum latitude is calculated before the triangledistances in the first and third segment but does the opposite for the other

    14

  • 7/30/2019 Use GPS unit with Arduino microcontroller

    17/46

    Figure 5: Algorithm for finding the distance travelled using Lat and Long

    information 15

  • 7/30/2019 Use GPS unit with Arduino microcontroller

    18/46

  • 7/30/2019 Use GPS unit with Arduino microcontroller

    19/46

    (a) 08600 displaying a computed area (b) The computed area as seen on the Phi II

    two segments. This is a direct result of the direction change around theshape.

    As seen in both of these flowcharts the index of each array is used to drivethe path forward around the shape while also controlling the duration of thefor loop.

    Calculation of the Area

    Once the program completes finding all the distances around the shapesperimeter, the distances are gathered for all the triangles into a triangledistance array which will always have twice the amount of points in itsarray for example if the shape has 7 points the triangle distance array willhave 12 distance values, the same applies for the rectangles who have theirown individual array.

    The next step is calculating the individual areas of the triangles andrectangles using the distances contained in their own distance arrays. It fallsto another for loop for this task. The for loop needs to terminate when it

    reached the last distance calculated before the minimum latitude so as toadd together all the top areas. The index of this last distance is always twicethe minimum longitude index so the for loop will operate for index valuesless than twice the minimum longitude index. A second for loop is used tocalculate and add together all the bottom areas which terminates before theindex reaches twice the latitude arrays final point. A final snippet of codeis at the end of the two for loops for the area of the shapes between thearray end point and the maximum longitude. Subtracting the bottom areafrom the top area yields the area of the shape which is rounded off to the

    17

  • 7/30/2019 Use GPS unit with Arduino microcontroller

    20/46

    nearest meter since it cant be quoted with decimal points due to the 10

    meter accuracy consideration [Cor12].

    The Use of Sparkfuns 08600

    The inclusion of this componant was dependant on whether or not a suit-able library could be found to write and draw rudimentary shapes onto the08600 since there was no time in which to write one from scratch. A librarywas found on the Sparkfun site for the 08600 in a comment by usernameTCWORLD [Spa12b]. This library was written by this user to cater for bothPhilips and Epson graphics controllers. Upon trying the library with the

    test example provided the 08600 responded positively. This library enableswriting ASCII to the 08600 as well as coloured boxes with user controlledforeground and background colour. Other shapes catered for are circles andstraight lines. This library was utilised to display the shape the Arduinocalculates with a small compass in the corner to give a sense of direction tothe displayed shape. With the calculated area displayed at the bottom of thescreen the 08600 makes an effective display device using a very rudimentarylibrary. The code for this can be found in Appendix D in a function callednokia().

    4.4 Evaluation of ErrorsThe datasheet of the EM-406A gives a figure for the accuracy of the GPS

    unit to be within a circle of radius 10 m of ones true position 95% of the time[Cor12]. If the unit is connected to the European Geostationary NavigationOverlay Service (the European equivalent to WAAS) this circle can be cor-rected to a 5 m radius of ones true position 95% of the time [Cor12, Age12].Figure 7 shows a series of histograms examining the absolute accuracy of theGPS unit as you stand in one position for a period of time. The last twohistograms display the relative accuracy of the Arduino and the GPS unit ofa distance of 20 m.

    The histogram for the absolute accuracy with 3 or 4 satellites form aGaussian shape of reasonable spread in values with a standard deviation of 53 m. This standard deviation decreases the more satellites are obtainedwith the deviation in the 7/8 graph being 1.5 m. Because of this the areascalculated with the Arduino along with relative distance measurements wereonly carried out while connected to 7 or 8 satellites. It is rare to connect tomore than 8, perhaps on a sunny day up to 10 can be found.

    With the relative distance sketch, measurements a length of 20 m werecalculated by the Arduino 15 times making the histogram present in figure

    18

  • 7/30/2019 Use GPS unit with Arduino microcontroller

    21/46

    (a) Absolute position with 3/4 satellites (b) Absolute position with 6/7 satellites

    (c) Absolute position with 7/8 satellites

    (d) Position measurement of twenty meters (e) Position measurement of twenty meters with aver-aging of the Lat and Long

    Figure 7: Accuracy Histograms

    19

  • 7/30/2019 Use GPS unit with Arduino microcontroller

    22/46

  • 7/30/2019 Use GPS unit with Arduino microcontroller

    23/46

    The library that is used for the 08600 is limited to drawing squares,

    lines and circles as well as writing text and using colours [Spa12b]. Itsa strange library in the sense that when it draws a square that the userprogrammed to appear it slowly draws it across the screen. It does the samething when the 08600 refreshes, slowly colouring the screen a default colourand only drawing the programmed shapes after this has finished covering thescreen. To improve this either this library has to be modified or a new morecomprehensive one found or written from scratch. Since the library caters forboth Epson and Philips, the Philips code could be removed from the librarysince the 08600 has an Epson controller. The source code for the library itselfshould be revised to see what could be causing the slow refresh rate of the

    08600. Alternatively a new library could be written using the 08600 datamanual [Lyn12] which contains the commands and colour codes associatedwith the controller and the wealth of information contained in the Sparkfuncomments and Arduino playground forum.

    If the development of this project were to be taken further, thought couldbe put into perhaps bringing the height above sea level into play in termsof surveying. The method of finding the area of this 3 dimensional modelwould obviously have to be revised, the Monte Carlo method being a goodplace to start. The modeling of this shape couldnt be done on the 08600 butthe values can be easily saved for analysis on a more powerful machine. The

    accuracy of the height above sea level is much worse than the longitude andlatitude necessitating the need for connection to EGNOS [DeP12, Age12].Another side project would be to use the 08600 and the GPS to make a

    digital compass. The basic concept is to display a makeshift compass withNorth, South, East and West and all thats in between with a compass needlein the middle indicating which way is North and which is South. The relativedifficulty of doing this with the GPS is most likely pretty high but it wouldbe a good exercise with the 08600, even a simpler derivative of this conceptwould be worth doing for the experience in operating the 08600. It wouldrequire a revised or new version of the 08600 library as it needs to refreshthe screen much faster than it does by default.

    To make the 08600 more portable in the sense that it doesnt consumeas much power while on battery, a method of turning the backlight off aftera set amount of time would save a lot of power being consumed. The back-light which is wired to a 5V pin on the Arduino consumes 120mA of power[Spa12b]. If it could be used only when the user wants to use the LCD thiswould save battery life considerably, just like in a mobile phone.

    21

  • 7/30/2019 Use GPS unit with Arduino microcontroller

    24/46

    5.2 Discussion of Errors

    The error associated with the area from Appendix E is as follows,

    A = 2L0L

    It follows from this that the percentage error is,

    A

    A0=

    2L

    L0

    For an rectangular area of 2020 m the error in the area calculation usingthe Arduino and the GPS unit would be,

    A = 2(20)(2.4) = 96m

    The error in the length used here is the standard deviation of the relativedistance measurements, the histogram of which is featured in figure 7(d).The percentage error of this rectangular area comes out to be,

    A

    A0=

    2(2.4)

    20= 0.24 = 24%

    For an area of 100 100 m, using the same standard deviation the error

    associated with this area would be,

    A = 2(100)(2.4) = 480m

    with a percentage error of,

    A

    A0=

    2(2.4)

    100= 0.048 = 4.8%

    From this simple analysis it can be estimated that the error of the areacalculated will stay constant the bigger the area but the percentage error

    will decrease with larger areas.

    6 Conclusion

    This project has shown the adaptability the Arduino has as a microcon-troller. Not only is it a useful tool for hobbyists and artists but can be usedin practical applications with great results. Its clear that the Arduino isproficient at taking serial data and outputting it in a variety of differentmeans, whether it be LEDs or LCDs enabling the user to use the Arduino

    22

  • 7/30/2019 Use GPS unit with Arduino microcontroller

    25/46

    for portable field work as the output of the Arduinos task can be displayed

    on an LCD.Data from the GPS is taken by the Arduino, stripped of its relevant

    information and displayed as seen in the time and display sketch while alsoconverting latitude and longitude into meters and using them for relativedistance. This shows the ease at which the Arduino can take data and carryout a variety of different tasks and have them carried out in a very smallamount of time.

    The practical use of the Arduino is proven in the irregular area sketchwhich takes all the components explored before and culminating them intoone very useful and portable sketch. The code is capable of finding the area

    of areas approximately 100 100 with a percentage error of 4.8%. This sur-prisingly accurate result reflects on the capability of the Arduino and onthe workings of the simple GPS unit for finding distances and its compe-tency in using correction techniques as the college can be a somewhat urbanenvironment.

    Even through the fact that this project can be taken further especiallywith the 08600, it highlights the versatility of the Arduino and many of itsperiphery devices.

    23

  • 7/30/2019 Use GPS unit with Arduino microcontroller

    26/46

    Bibliography

    [Age12] European Space Agency. What is EGNOS. http://www.esa.int/esaNA/egnos.html, 2012.

    [Ard12] Arduino. Arduino MEGA 2560. http://docs-europe.electrocomponents.com/webdocs/0e8b/0900766b80e8ba22.

    pdf, 2012.

    [BCI+12a] Massimo Banzi, David Cuartielles, Tom Igoe, Gianluca Martino,and David Mellis. Arduino - attachinterrupt(interrupt, function,mode). http://arduino.cc/en/Reference/AttachInterrupt,2012.

    [BCI+12b] Massimo Banzi, David Cuartielles, Tom Igoe, Gianluca Mar-

    tino, and David Mellis. Arduino - string - substring(). http://arduino.cc/en/Reference/StringSubstring, 2012.

    [BCI+12c] Massimo Banzi, David Cuartielles, Tom Igoe, Gianluca Martino,and David Mellis. Arduino - string - toCharArray(). http://arduino.cc/en/Reference/StringToCharArray, 2012.

    [BCI+12d] Massimo Banzi, David Cuartielles, Tom Igoe, Gianluca Martino,and David Mellis. Arduino Homepage. http://arduino.cc/,2012.

    [BCI+

    12e] Massimo Banzi, David Cuartielles, Tom Igoe, Gianluca Martino,and David Mellis. Arduino Libraries. http://arduino.cc/en/Reference/Libraries, 2012.

    [BCI+12f] Massimo Banzi, David Cuartielles, Tom Igoe, Gianluca Martino,and David Mellis. Arduino Mega 2560. http://arduino.cc/en/Main/ArduinoBoardMega2560, 2012.

    [BHB12] Hernando Barragan, Brett Hagman, and Alexander Brevig.Wiring - about. http://wiring.org.co/about.html, 2012.

    24

    http://www.esa.int/esaNA/egnos.htmlhttp://www.esa.int/esaNA/egnos.htmlhttp://docs-europe.electrocomponents.com/webdocs/0e8b/0900766b80e8ba22.pdfhttp://docs-europe.electrocomponents.com/webdocs/0e8b/0900766b80e8ba22.pdfhttp://docs-europe.electrocomponents.com/webdocs/0e8b/0900766b80e8ba22.pdfhttp://arduino.cc/en/Reference/AttachInterrupthttp://arduino.cc/en/Reference/AttachInterrupthttp://arduino.cc/en/Reference/StringSubstringhttp://arduino.cc/en/Reference/StringSubstringhttp://arduino.cc/en/Reference/StringToCharArrayhttp://arduino.cc/en/Reference/StringToCharArrayhttp://arduino.cc/http://arduino.cc/http://arduino.cc/en/Reference/Librarieshttp://arduino.cc/en/Reference/Librarieshttp://arduino.cc/en/Main/ArduinoBoardMega2560http://arduino.cc/en/Main/ArduinoBoardMega2560http://arduino.cc/en/Main/ArduinoBoardMega2560http://wiring.org.co/about.htmlhttp://wiring.org.co/about.htmlhttp://arduino.cc/en/Main/ArduinoBoardMega2560http://arduino.cc/en/Main/ArduinoBoardMega2560http://arduino.cc/en/Reference/Librarieshttp://arduino.cc/en/Reference/Librarieshttp://arduino.cc/http://arduino.cc/en/Reference/StringToCharArrayhttp://arduino.cc/en/Reference/StringToCharArrayhttp://arduino.cc/en/Reference/StringSubstringhttp://arduino.cc/en/Reference/StringSubstringhttp://arduino.cc/en/Reference/AttachInterrupthttp://docs-europe.electrocomponents.com/webdocs/0e8b/0900766b80e8ba22.pdfhttp://docs-europe.electrocomponents.com/webdocs/0e8b/0900766b80e8ba22.pdfhttp://docs-europe.electrocomponents.com/webdocs/0e8b/0900766b80e8ba22.pdfhttp://www.esa.int/esaNA/egnos.htmlhttp://www.esa.int/esaNA/egnos.html
  • 7/30/2019 Use GPS unit with Arduino microcontroller

    27/46

    [Cor12] Globalsat Tech Corp. Product User Manual GPS Receiver Engine

    Board. http://www.sparkfun.com/datasheets/GPS/EM-406A_User_Manual.PDF, 2012.

    [DeP12] Dale DePriest. NMEA Data. http://www.gpsinformation.org/dale/nmea.htm, 2012.

    [For10] Arduino Forum. Nokia 6100 LCD Display - Arduino Play-ground. http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1237036119/all, 2010.

    [FR12] Ben Fry and Casey Reas. Processing - about. http://

    processing.org/about/, 2012.

    [Liu11a] John Liu. Phi 2 Documention. http://liudr.files.wordpress.com/2011/02/phi-2-documentation-04022011.

    pdf, 2011.

    [Liu11b] John Liu. Phi prompt Text-bsed User Interface for Arduino.http://phi-prompt-user-interface-library.googlecode.

    com/files/Phi_prompt%20documentation%2020110523.pdf,2011.

    [Lyn12] James P. Lynch. Nokia 6100 LCD Display Driver.http://www.sparkfun.com/tutorial/Nokia%206100%20LCD%

    20Display%20Driver.pdf, 2012.

    [Mar01] Michale Margolis. Arduino Cookbook. OReilly, 1005 GravensteinHighway North, Sebastopol, CA 95472, 2001.

    [oI98] Ordnance Survey of Ireland. Discovery Series 46 Sraith EolaisGaillimh, 1998.

    [Owe10] Ryan Owens. Nokia - Breakout - v13. http://www.sparkfun.com/datasheets/LCD/Nokia-Breakout-v13.pdf, 2010.

    [Owi06] Rich Owings. SiRFstarIII - Why Its a Big Deal. http://www.sparkfun.com/products/465, 2006.

    [Spa12a] Sparkfun. 20 Channel EM-406A SiRF III Receiver with Antenna.http://www.sparkfun.com/products/465, 2012.

    [Spa12b] Sparkfun. Colour LCD - Breakout Board. http://www.sparkfun.com/products/8600, 2012.

    25

    http://www.sparkfun.com/datasheets/GPS/EM-406A_User_Manual.PDFhttp://www.sparkfun.com/datasheets/GPS/EM-406A_User_Manual.PDFhttp://www.gpsinformation.org/dale/nmea.htmhttp://www.gpsinformation.org/dale/nmea.htmhttp://www.gpsinformation.org/dale/nmea.htmhttp://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1237036119/allhttp://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1237036119/allhttp://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1237036119/allhttp://processing.org/about/http://processing.org/about/http://liudr.files.wordpress.com/2011/02/phi-2-documentation-04022011.pdfhttp://liudr.files.wordpress.com/2011/02/phi-2-documentation-04022011.pdfhttp://liudr.files.wordpress.com/2011/02/phi-2-documentation-04022011.pdfhttp://phi-prompt-user-interface-library.googlecode.com/files/Phi_prompt%20documentation%2020110523.pdfhttp://phi-prompt-user-interface-library.googlecode.com/files/Phi_prompt%20documentation%2020110523.pdfhttp://phi-prompt-user-interface-library.googlecode.com/files/Phi_prompt%20documentation%2020110523.pdfhttp://www.sparkfun.com/tutorial/Nokia%206100%20LCD%20Display%20Driver.pdfhttp://www.sparkfun.com/tutorial/Nokia%206100%20LCD%20Display%20Driver.pdfhttp://www.sparkfun.com/datasheets/LCD/Nokia-Breakout-v13.pdfhttp://www.sparkfun.com/datasheets/LCD/Nokia-Breakout-v13.pdfhttp://www.sparkfun.com/products/465http://www.sparkfun.com/products/465http://www.sparkfun.com/products/465http://www.sparkfun.com/products/465http://www.sparkfun.com/products/8600http://www.sparkfun.com/products/8600http://www.sparkfun.com/products/8600http://www.sparkfun.com/products/8600http://www.sparkfun.com/products/465http://www.sparkfun.com/products/465http://www.sparkfun.com/products/465http://www.sparkfun.com/datasheets/LCD/Nokia-Breakout-v13.pdfhttp://www.sparkfun.com/datasheets/LCD/Nokia-Breakout-v13.pdfhttp://www.sparkfun.com/tutorial/Nokia%206100%20LCD%20Display%20Driver.pdfhttp://www.sparkfun.com/tutorial/Nokia%206100%20LCD%20Display%20Driver.pdfhttp://phi-prompt-user-interface-library.googlecode.com/files/Phi_prompt%20documentation%2020110523.pdfhttp://phi-prompt-user-interface-library.googlecode.com/files/Phi_prompt%20documentation%2020110523.pdfhttp://liudr.files.wordpress.com/2011/02/phi-2-documentation-04022011.pdfhttp://liudr.files.wordpress.com/2011/02/phi-2-documentation-04022011.pdfhttp://liudr.files.wordpress.com/2011/02/phi-2-documentation-04022011.pdfhttp://processing.org/about/http://processing.org/about/http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1237036119/allhttp://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1237036119/allhttp://www.gpsinformation.org/dale/nmea.htmhttp://www.gpsinformation.org/dale/nmea.htmhttp://www.sparkfun.com/datasheets/GPS/EM-406A_User_Manual.PDFhttp://www.sparkfun.com/datasheets/GPS/EM-406A_User_Manual.PDF
  • 7/30/2019 Use GPS unit with Arduino microcontroller

    28/46

    1 Appendix A: Sentence Isolation Sketch

    void setup(){

    Serial3.begin(4800);

    Serial.begin(9600);

    }

    void loop(){

    if(Serial3.available()>0){Serial.print(char(Serial3.read()));

    }

    }

    2 Appendix B: Time and Location Display

    Sketch

    #include

    #define LCD_RS 8

    #define LCD_EN 9

    #define LCD_D4 7

    #define LCD_D5 6

    #define LCD_D6 2

    #define LCD_D7 3

    int gps = 0;

    String SenIn = "";

    char conver[5];

    char conver2[5];

    char conver3[5];

    LiquidCrystal lcd(LCD_RS, LCD_EN, LCD_D4, LCD_D5, LCD_D6, LCD_D7);

    void setup(){

    26

  • 7/30/2019 Use GPS unit with Arduino microcontroller

    29/46

  • 7/30/2019 Use GPS unit with Arduino microcontroller

    30/46

    lcd.print(SenIn.substring(10,12));

    lcd.setCursor(5,0);lcd.write(:);

    lcd.setCursor(6,0);

    lcd.print(SenIn.substring(12,14));

    }

    void show_Position(){

    if(SenIn.charAt(44)==1){

    lcd.setCursor(0,1);lcd.print(SenIn.substring(19,30));

    lcd.setCursor(0,2);

    lcd.print(SenIn.substring(31,43));

    lcd.setCursor(14,0);

    lcd.print(SenIn.substring(46,48));

    }

    }

    3 Appendix C: Relative Distance Sketch

    #include

    #include

    #define LCD_RS 8

    #define LCD_EN 9

    #define LCD_D4 7

    #define LCD_D5 6

    #define LCD_D6 2

    #define LCD_D7 3

    volatile int state = LOW;

    volatile int state_2 = LOW;

    String SenIn = "";

    String Lat1 = "";

    String Lat2 = "";

    String Long1 = "";

    28

  • 7/30/2019 Use GPS unit with Arduino microcontroller

    31/46

    String Long2 = "";

    String pile = "";

    char conver1[5];

    char conver2[5];

    char conver3[5];

    char conver4[5];

    char conver5[5];

    float Lat_one = 0;

    float Lat_two = 0;

    float Long_one = 0;float Long_two = 0;

    float Lat_dif = 0;

    float Long_dif = 0;

    float fin1 = 0;

    float fin2 = 0;

    float dist = 0;

    float pile1 = 0;

    float pile2 = 0;

    float ave = 0;

    int addr = 12;

    int gps = 0;

    LiquidCrystal lcd(LCD_RS, LCD_EN, LCD_D4, LCD_D5, LCD_D6, LCD_D7);

    void setup(){

    pinMode(18, INPUT);

    pinMode(19, INPUT);

    pinMode(A0, INPUT);

    pinMode(A1, INPUT);

    digitalWrite(A0, HIGH);

    digitalWrite(A1, HIGH);

    attachInterrupt(5, flag, RISING); // port 18

    attachInterrupt(4, flag_2, RISING); // port 19

    lcd.begin(20, 4);

    29

  • 7/30/2019 Use GPS unit with Arduino microcontroller

    32/46

    Serial3.begin(4800);

    }

    void loop(){

    nmea_Decode();

    if(state==0){

    lcd.setCursor(0,1);

    lcd.print("Received");

    averageLat();Lat_one=ave;

    averageLong();

    Long_one=ave;

    lcd.setCursor(0,2);

    lcd.print("Done!");

    delay(2000);

    lcd.clear();

    state=!state;

    }

    if(state_2==0){

    lcd.setCursor(0,1);

    lcd.print("Received");

    averageLat();

    Lat_two=ave;

    averageLong();

    Long_two=ave;

    compute();

    state_2=!state_2;

    }

    SenIn="";

    }

    void nmea_Decode(){

    30

  • 7/30/2019 Use GPS unit with Arduino microcontroller

    33/46

  • 7/30/2019 Use GPS unit with Arduino microcontroller

    34/46

    for(int i=0; i

  • 7/30/2019 Use GPS unit with Arduino microcontroller

    35/46

  • 7/30/2019 Use GPS unit with Arduino microcontroller

    36/46

    float Lat1 = 0, Lat2 = 0, Long1 = 0, Long2 = 0;

    float Lat_one = 0, Lat_two = 0, Lat_three = 0;float Long_one = 0, Long_two = 0, Long_three = 0;

    float Lat_dif = 0;

    float Long_dif = 0;

    float fin1 = 0;

    float fin2 = 0;

    float dist = 0;

    float area_tri_top = 0, area_tri_bottom = 0, area_rec_top = 0,

    area_rec_bottom = 0, area_top = 0, area_bottom = 0, area = 0;

    float max_Lat = -10000, max_Long = -10000;

    float min_Lat = 10000, min_Long = 10000;float max_Long_organ = -10000;

    int lat_index = 0, long_index = 0, array_end = 0;

    int org = 0;

    int addr = 12;

    int control = 0, control2 = 0, control3 = 0, num = 0;

    int min_Lat_index = 0, min_Long_index = 0, max_Lat_index = 0,

    max_Long_index = 0;

    int max_Long_organ_index = 0;

    int gps = 0;

    gLCD graphic(RST,CS,Clk,Dat);

    LiquidCrystal lcd(LCD_RS, LCD_EN, LCD_D4, LCD_D5, LCD_D6, LCD_D7);

    void setup(){

    pinMode(18, INPUT);

    pinMode(19, INPUT);

    pinMode(A0, INPUT);

    pinMode(A1, INPUT);

    digitalWrite(A0, HIGH);

    digitalWrite(A1, HIGH);

    attachInterrupt(5, flag, RISING); // port 18

    attachInterrupt(4, flag_2, RISING); // port 19

    //graphic.Init(0,2,0);

    lcd.begin(20, 4);

    34

  • 7/30/2019 Use GPS unit with Arduino microcontroller

    37/46

    Serial3.begin(4800);

    Serial.begin(9600);

    }

    void loop(){

    nmea_Decode();

    if(state==0){

    lcd.setCursor(4,0);

    lcd.print("Received");Position();

    }

    if(state_2==0){

    //nokia();

    lcd.setCursor(0,1);

    lcd.print("Received");

    organise();

    tri();

    Area();}

    SenIn="";

    }

    void flag(){

    state = !state;

    }

    void flag_2(){

    state_2 = !state_2;

    }

    35

  • 7/30/2019 Use GPS unit with Arduino microcontroller

    38/46

  • 7/30/2019 Use GPS unit with Arduino microcontroller

    39/46

    save();

    lcd.setCursor(13,0);

    lcd.print("Done");

    delay(2000);

    lcd.clear();

    state = !state;

    }

    void save(){

    EEPROM.write(addr,Lat_num);

    addr++;

    Lat_num = Lat_num/256;

    EEPROM.write(addr,Lat_num);

    addr++;

    EEPROM.write(addr,Long_num);

    addr++;Long_num = Long_num/256;

    EEPROM.write(addr,Long_num);

    addr++;

    }

    void organise(){

    for(org=max_Long_organ_index; org

  • 7/30/2019 Use GPS unit with Arduino microcontroller

    40/46

    if(long_points[num]max_Long){

    max_Long=long_points[num];

    max_Long_index = num;

    }

    if(lat_points[num]>max_Lat){

    max_Lat=lat_points[num];max_Lat_index = num;

    }

    if(lat_points[num]

  • 7/30/2019 Use GPS unit with Arduino microcontroller

    41/46

    distance();

    dist_tri[control2]=dist;control2++;

    dist_rec[control3]=dist;

    control3++;

    Lat1=lat_points[lat_index];

    lat_index++;

    Lat2=lat_points[lat_index];

    Long1=long_points[long_index];

    Long2=long_points[long_index];

    distance();dist_tri[control2]=dist;

    control2++;

    }

    long_index = max_Lat_index;

    lat_index = max_Lat_index;

    for(int index=max_Lat_index; index

  • 7/30/2019 Use GPS unit with Arduino microcontroller

    42/46

    Lat1=lat_points[lat_index];

    Lat2=min_Lat;

    Long1=long_points[long_index];

    Long2=long_points[long_index];

    distance();

    dist_rec[control3]=dist;

    control3++;

    }

    long_index = min_Lat_index;

    lat_index = min_Lat_index;

    for(int index=min_Lat_index; index

  • 7/30/2019 Use GPS unit with Arduino microcontroller

    43/46

    Long2=long_points[long_index];

    distance();dist_tri[control2]=dist;

    control2++;

    }

    Lat1=lat_points[control-1];

    Lat2=min_Lat;

    Long1=long_points[control-1];

    Long2=long_points[control-1];

    distance();

    dist_rec[control3]=dist;control3++;

    Lat1=lat_points[control-1];

    Lat2=lat_points[control-1];

    Long1=long_points[control-1];

    Long2=long_points[max_Long_index];

    distance();

    dist_tri[control2]=dist;

    control2++;

    dist_rec[control3]=dist;control3++;

    Lat1=lat_points[control-1];

    Lat2=lat_points[max_Long_index];

    Long1=long_points[max_Long_index];

    Long2=long_points[max_Long_index];

    distance();

    dist_tri[control2]=dist;

    control2++;

    }

    void distance(){

    dist=0;

    Lat_dif = (Lat1-Lat2);

    Long_dif = (Long1-Long2);

    41

  • 7/30/2019 Use GPS unit with Arduino microcontroller

    44/46

  • 7/30/2019 Use GPS unit with Arduino microcontroller

    45/46

  • 7/30/2019 Use GPS unit with Arduino microcontroller

    46/46

    int X4=abs(round((position_long[0]-max_Long)/10));

    int Y3=abs(round((position_lat[control-1]-max_Lat)/10));int Y4=abs(round((position_lat[0]-max_Lat)/10));

    graphic.Line(X3+10,Y3+10,X4+10,Y4+10,1);

    }

    5 Appendix E: Error Estimation

    The error in length when calculated using the relative distance sketch is,

    L = L0 L

    L = L0

    1

    L

    L0

    A = L2 = L20

    1

    L

    L0

    2

    Where A is the area. Using the approximation

    1 LL0

    2

    1 2L

    L0

    the

    area equation becomes,

    A A0 2L0LThus

    A = 2L0L