Brian Moreau

Search my site


Plasma
   Home   
    Solutions    
    Articles   
    Projects   
    Blog   
    Contact   
    Maker Portfolio   
 
 
 
Particle Electron GPS receiver (Location plotted on Google Map)
March 2016

Particle Electron GPS

The Particle Electron

The Particle Electron is a new prototype device for the Internet of things (IoT)
Theirs plenty of these about but this one boasts cellular connectivity.
Yes it can connect to mobile telephone networks allowing your devices to become truly mobile.

The device is based on a powerful 32 Bit processor running at 120MHz.
It is easily programmable using an Arduino like programming language.

Datasheet: https://docs.particle.io/datasheets/electron-datasheet/

Project
Electron GPS

UPDATE FEB/2017
Now with GPS LOCK LED

Background
As this devise is best suited to projects that can be mobile the first thing I decided that would be needed was to know its location. I thus set about adding a GPS Receiver.

GPS Receiver
Many of these devices exist for various IoT platforms so I decided to select one that is Arduino compatible thus ensuring program and connectivity compatibility.
These units vary in price greatly and are generally anywhere between £30 to £60.
I found one that was only £15 and from the specification looked to be a pretty good unit which actually exceeded specifications of some more expensive alternatives.

GP-20U7 GPS Receiver
This is a high sensitivity -163dBm, 56 channel search and 22 channel tracking.
Additionally it only requires 3.3V power @ 30mA which the Electron can supply adequately.

I got mine from Proto-PIC and they even gave me a free packet of sweets :)

The Data Sheet is here https://cdn.sparkfun.com/datasheets/GPS/GP-20U7.pdf

Electron Programming

OTA Programming
The particle website allows you to write programs and flash them over the air (OTA) direct to your device. This uses data bandwidth but for testing a few programs its very convenient and easy.

Serial Programming
To program the device by serial is not quite a easy as programming the Arduino.
First you have to install NODE.JS and then the driver.
You must still use the Particle website to write your programs but instead of flashing them OTA you can compile and download the binary file, you then issue a command line instruction to transfer the binary file to the device.

Here is the connecting and programming guide: https://docs.particle.io/guide/getting-started/connect/electron/

Project Overview
The only hardware parts of the project are the Particle Electron, GPS Unit, 220Ohm Resistor and LED.
The Electron runs a program that reads the required line of GPS data via the Serial port.

If the Data is valid i.e the GPS Unit is LOCKED then an LED is turned on. This enables debugging and gives visual indication of GPS LOCK.

The Data contains the Latitude and Longitude and soem other data which is made available as a web accessible variable.

The variable or data is then grabbed and decoded by the code embedded into a web page.

In order to achieve this you will need to be able to publish a webpage in some webspace somewhere.
I wrote my code in PHP but I guess you would be able to use ASP and or JavaScript.
The last bit of code required on the webpage is the Google Map Embed Function which places a Map Marker at the location of the device.

Circuit
The Electron comes with it own bread board so connecting up is easy.

Simply connect the positive of the GPS unit to +3.3V on the Electron and GND to GND and the TX from the GPS Receive to the RX of Serial Port on the Electron.

For the LOCK LED connect the 220Ohm Resistor from D1 to the Anode of the LED and the Cathode of the LED to GND.

Electron Code

					
// GPSTest

String inWord;
char inByte;
String data;
int LockLED = D1;  


void setup() {
    // cloud variable
    Particle.variable("STU", data);
    // GPS Serial
    Serial1.begin(9600);
    pinMode(LockLED, OUTPUT);
    digitalWrite(LockLED, HIGH);
    delay(2000);
    digitalWrite(LockLED, LOW);
}



void loop() {
    while (Serial1.available() > 0) {
        inByte = Serial1.read();
        
        if (inByte == '\n') {
            // END OF LINE
            
            // check is data we want
            // you can change this to get any data line values
            if (inWord.startsWith("$GPRMC")) {
                // put data string in variable
                data = inWord;
                // clear the inword variable
                inWord = "";
                
                // does the GPS Receiver have lock?
                // get the char at pos 17 and test to see if it is an A i.e VALID V = INVALID
                char lock = data.charAt(17);
                if (lock == 'A') {
                    // YES Switch on Lock LED
                    digitalWrite(LockLED, HIGH);
                } else {
                    // NO turn off lock led
                    digitalWrite(LockLED, LOW);  
                }
                
                
            } else {
                // clear the inword variable as not the data we want
                inWord = "";
            }
            
        } else {
            // build data string
            inWord += inByte;   
        }
        
    } // end if serial
} // end loop

 

Website Code

<?PHP
# particle-map.php
// GPS UNIT
// https://cdn.sparkfun.com/datasheets/GPS/GP-20U7.pdf

$deviceID = "YOUR_PARTICLE_DEVIC_ID";
$access_token = "YOUR_PARTICLE_ACCESS_TOKEN";

$url = "https://api.particle.io/v1/devices/$deviceID/";
$formed_url ='?access_token='.$access_token;
$variable_name = "STU";

$headers = array( 
  	"GET /v1/devices/".$variable_name.$formed_url." HTTP/1.1",
  	"Host: api.particle.io");

  	// setup and make HTTP GET REQUEST
	$ch = curl_init();  
	curl_setopt($ch, CURLOPT_URL,$url.$variable_name.$formed_url);
	curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // return output
	$retrievedhtml = curl_exec ($ch); 
	curl_close($ch); 
	$json = json_decode($retrievedhtml,true);

	// see if there was an error connecting with electron
	if ($json['error'] != "") {
	    echo ("ERROR = " . $json['error'] . "<br>");
	} else {
	   // read the data into a variable
	   $DATA = $json['result'];
	   // output to screen
	   echo ("<b>result: </b>" . $DATA . "<br>");
	   // split data into array  is comma delimited
	   $pieces = explode(",", $DATA);
	   // A = valid, V = not valid
	   $status = $pieces[2];
	   if ($status == "V") {
			echo ("Data not valid<br>Can the GPS unit see the sky?");
	   } else {
			// put data in variables
			$LAT = $pieces[3];
			$NS = $pieces[4];
			$LON = $pieces[5];
			$EW = $pieces[6];
			// Convert LAT
			$deg = substr($LAT, 0, 2);
			$min = substr($LAT, 2, 8);
			$sec = '';
			$resultLAT = $deg+((($min*60)+($sec))/3600);

			// Convert Longitude
			$deg = substr($LON, 0, 3);
			$min = substr($LON, 3, 8);
			$sec='';
			$resultLON = $deg+((($min*60)+($sec))/3600);

			// Is it East or West
			if ($EW == "W") {
			   $resultLON = $resultLON * -1;
			}
			
			// Is it North or South
			if ($NS == "S") {
				$resultLAT = $resultLAT * -1;
			}
			
			print ("Latitude " . $resultLAT . "<br>");
			print ("Longitude " . $resultLON . "<br>");
		}
	}
?>

<iframe
width="400"
height="400"
frameborder="0" style="border:0"
src="https://www.google.com/maps/embed/v1/place?key=YOUR_GOOGLE_MAP_API_KEY
&q=<?=$resultLAT?>,<?=$resultLON?>">
</iframe>

 

Operation
Simply use any web browser to access the page from the internet and the GPS Location of your device will be visible on a map.

My Electron Location Map: http://www.brianmoreau.com/apps/particle/particle-map.php

Lastly
Sorry almost forgot to mention but to use Google MAP API which is what my project is based on you will need to sign up for an API access key.
I do understand there are alternative mapping options.

Improvements
Exploring the Google Mapping options should allow for a continuous route plotting and the access webpage could be modified to automatically refresh so location plotting is continuous.

DEBUGGING
If you fail to get a map position have alook at the data coming from the GPS unit.
If it has a 'GPS LOCK' the full data string will look something like...
$GPRMC,202935.00,A,5135.91581,N,00008.33889,W,2.612,92.02,050217,,,A*4B

If 'LOCK' has not yet been acheived the data will be incomplete and look something like...
$GPRMC,204536.00,V,,,,,,,050217,,,N*7A
And report DATA NOT VAILID in the Browser
A Visual GPS LOCK LED is now used in the circuit

If your device is not connected to the GMS Mobile Network the no data will be received at all.
More GPS INFO http://aprs.gids.nl/nmea/#rmc

 
 
 

Readers comments >

ERROR Could not connect to MySQL server!
It may be bizy, please try again

ERROR Could not change into the database
Sorry there are no comments, be the first to leave a comment.
 
 
 

Leave a comment or ask me a question >

You don’t need to register to leave a comment because I feel people should not be forced to register to have their say.
All comments are checked prior to publishing to prevent spam.
Don’t worry this wont take long.
If you supply your email address below you will automatically be notified when I approve your comment.

Full name > *
eMail address > (not published)
Website > (http://...)
Location > (town or city)
Comment or question > *
Human *
  * feilds required  
 
 
 
 
Particle Electron GPS receiver an IOT Project 2016
© 2008 - 2021 - Brian Moreau

Valid XHTML 1.0 Transitional Valid CSS!