STEP 1
Note: The time between seeing satellites and actually getting a lock is dependent on the satellite. Be in view of the open sky for best results (and even then it may take a while to get a lock). Once the module has a lock, the lock should stay for a while.
Make a directory inside your “tessel-code” folder called “gps”, change directory into that folder, and initialize a tessel project:
mkdir gps; cd gps; t2 init
STEP 2
Plug the GPS module into Tessel port A with the hexagon/icon side down and the electrical components on the top, then plug Tessel into your computer via USB.
STEP 3
Install by typing npm install gps-a2235h
into the command line.
STEP 4
Rename “index.js” to “gps.js” and replace the file’s contents with the following:
// Any copyright is dedicated to the Public Domain.
// http://creativecommons.org/publicdomain/zero/1.0/
/**********************************************************
This gps example logs a stream of data:
coordinates, detected satellites, timestamps, and altitude.
For best results, try it while outdoors.
**********************************************************/
var tessel = require('tessel');
var gpsLib = require('gps-a2235h');
var gps = gpsLib.use(tessel.port['A']);
// Wait until the module is connected
gps.on('ready', function () {
console.log('GPS module powered and ready. Waiting for satellites...');
// Emit coordinates when we get a coordinate fix
gps.on('coordinates', function (coords) {
console.log('Lat:', coords.lat, '\tLon:', coords.lon, '\tTimestamp:', coords.timestamp);
});
// Emit altitude when we get an altitude fix
gps.on('altitude', function (alt) {
console.log('Got an altitude of', alt.alt, 'meters (timestamp: ' + alt.timestamp + ')');
});
// Emitted when we have information about a fix on satellites
gps.on('fix', function (data) {
console.log(data.numSat, 'fixed.');
});
gps.on('dropped', function(){
// we dropped the gps signal
console.log("gps signal dropped");
});
});
gps.on('error', function(err){
console.log("got this error", err);
});
Save the file.
STEP 5
In your command line, t2 run gps.js
Check out your location! If you’re having trouble getting a location fix, try going outside; you probably don’t have satellites indoors.
Bonus: Set up a geofence so that you are inside it. (Hint: you may need to check the documentation.)
STEP 6
What else can you do with a GPS module? Try a community-created project.