MicroView GPS – displaying data

 

 kr

Introduction

This builds on Project 006a, in which we simply connected a GPS unit to our Microview and checked we were getting some data.  Now to make some sense of that data and display it!

This is a bit of a step-up in terms of code, which is why I have left an intermediate Project 006b available in case I need to retrace.  I’m sure people will let me know..

Parts
(Please see below for breadboard arrangement and pin allocations)

Breadboard Setup

There are just four pins from the Ublox GPS to be connected:

  • GPS red – 5V rail
  • GPS black – 0V rail
  • GPS yellow – Breadboard J8 (MV pin 9, the serial receive for Arduino code)
  • GPS green – Breadboard J9 (MV pin 10, the serial transmit for Arduino code)

WP_001331 WP_001332 WP_001333

When the connections are made, don’t forget:

  • Plug the Microview back in!
  • Pull out the red (5V) wire of the GPSto turn it off  when sending code to the Microview.

MicroView Arduino Code

I apologise for the indentation – I seem to be losing the fight with WordPress on this front.

// Author:              Mike Isted
// Date:                03 July 2014
// Acknowlwdgements:    John Boxall (Arduino Workshop)
// The team at Geek Ammo
// Mikal Hart and the Arduiniana library: http://arduiniana.org/libraries/tinygps/

// Preparation:
// – Connect an NMEA compliant GPS to the Microview serial port.  See Project 006a.#
// – Locate and import the TinyGPS Arduino library into the IDE (as per Arduino Workshop)

#include           // Include the Microview library.
#include             // Include the TinyGPS library

TinyGPS gps;                               // Create an instance of the TinyGPS object called gps.

void getgps (TinyGPS &gps)    // Define the getgps function
// We pass in a pointer to the gps data and for extraction of the longitude and latitude etc.
// Don’t worry if you don’t understand pointers for now… just accept the ‘&’ needs to be there!
{
//  Now to define all the variables we will need in the function.

float flat, flon;                        //  We are going to use decimal places (floating point variables).  To save memory you can work
//  just in whole numbers, but this makes for results you can understand more easily.  See TinyGPS
//  on-line for more information.

int year;                                 //  Of course the year will be a whole number (integer)
byte month, day, hour, minute, second, hundredths;  //  Byte variables simply save memory when the result is 0-255.

unsigned long fix_age;      //  This tells you how old the data is from the gps unit, to see if it is ‘stale’.

// Now let’s go get some data!  TinyGPS does all the hard work for you with a great selection of library functions.
// We’ll use a variety to retrieve data, but in practice you are unlikely to want all these.
// Delete lines not wanted to save memory.

gps.f_get_position(&flat, &flon);   // returns +/- latitude/longitude in degrees.  I have no idea why the long and lat values are returned as pointers…
//Just roll with it for now!
float falt = gps.f_altitude();               // +/- altitude in meters into falt
float fc = gps.f_course();                   // course in degrees into fc
float fk = gps.f_speed_knots();       // speed in knots into fk
float fmph = gps.f_speed_mph();     // speed in miles/hr into fmph
float fmps = gps.f_speed_mps();     // speed in m/sec into fmps – this will be the one we use.
float fkmph = gps.f_speed_kmph();   // speed in km/hr into fkmph – unless we are in France of course!

//  And finally the date/time data.  The function returns pointers to all these.  Again, just refer to them without the ‘&’ prefix in code.

gps.crack_datetime(&year, &month, &day, &hour, &minute, &second, &hundredths, &fix_age);

// Print out on MicroView screen:
uView.clear(PAGE);          // Clear the screen.

// One line of data on each ‘line’, as defined by the cursor positions below.
// Microview leaves the cursor where it left off unless told otherwise.  So the print commands below for date and time
// simply print each element in turn across the page.

uView.setCursor(0,0);          // set cursor at 0,0 at print the day (so it will be a number between 1 and 31)
uView.print(day);                  // Print the day at position 0,0
uView.print(“/”);                   // followed by a traditional / date delimiter
uView.print(month);            // then the month…
uView.print(“/”);
uView.print(year);

uView.setCursor(0,10);        // set cursor at 0,10 – so we are startin a new line 10 pixels down.
uView.print(hour);
uView.print(“:”);
uView.print(minute);
uView.print(“:”);
uView.print(second);

// Now for the latitude, longitude and altitude data.
// The position of the data along each line is being explicitely set so they all start at the same place.

uView.setCursor(0,20);        // set cursor at 0,20
uView.print(“Lat:”);              // Print the label..
uView.setCursor(25,20);       // Set the cursor to the right of the label
uView.print(flat);                  // and print the latitude value

uView.setCursor(0,30);
uView.print(“Lng:”);
uView.setCursor(25,30);
uView.print(flon);

uView.setCursor(0,40);
uView.print(“Alt:”);
uView.setCursor(25,40);
uView.print(falt);

// So now everything has been nicely laid out, we can display our lovely screen!

uView.display();
}
void setup()
{
uView.begin();                     // start MicroView
uView.clear(PAGE);          // and clear the screen.
Serial.begin (9600);          // Open the serial port.  The Ublox GPS is preset to 9600 baud.
// The serial port must be opened after the Microview has been started
}
void loop()
{
byte a;
if ( Serial.available() > 0 )      // Check if data is available at the serial port
{

if (Serial.available() > 0 )  // If data is available at the serial port
{
a = Serial.read();            // and if so read it into variable ‘a’

if (gps.encode(a))            //If the data is valid NMEA data
{
getgps(gps);
}
}
}
}
What should happen

1. Let the GPS unit get a fix once the code is running.  This may take a few moments.  Success is indicated by a green flashing light on the underside of the U-blox GPS unit.  Below, the green LED is labelled FIX and is to the right of the power LED (blue, illuminated).

kr

2. The Microview screen will display the data in the positions we set in the code.

kr

Of course the clock should be counting the seconds…

Project Notes

  •  Note the readout of seconds – it has no leading ‘0’, which is not what we would normally do.  This is because we have not really controlled the format of the output.
  • The clock readout is in standard time and so is an hour out right now for me in sunny UK.  That’s something we need to fix, and automatically if possible.
  • The readout of the lat and long are in decimal degrees.  That is not the same as degrees, minutes and seconds, which is more often used in applications such as Google Earth.  They are also lacking in precision, again because we have not formatted the output.
  • And finally, you will find the altitude reading wanders about over time quite a lot.  Why is this? (We’ll deal with it in a later blog, but it’s to do with triangulation of GPS satellites and small errors in angles causing big errors in distances….

Breadboard Arrangement and MicroView vs Arduino Pin Allocations

MicroView_pins
Courtesy 0f Geek Ammo

Positioning of MicroView on Breadboard (for my projects at least!)

  • Pin 1 of the MicroView is in breadboard socket C1.
  • MV pin 8 (GND) is used to ground the breadboard 0V rails.
  • MV pin 15 (5V) is used to power the breadboard supply rails.

kr kr

Acknowledgments
All code inspired by (and possibly modified from) the MicroView tutorials from the great team at Geek Ammo.  Visit their MicroView Kickstarter page.  Big thanks!

Advertisements