SparqEE GPS Module for Node.js

Image showing SparqEE GPS Receiver board.

This is a Node.js module that allows you to receive location and fix updates from SparqEE's GPS receiver when connected to the GPIO pins of a Raspberry Pi.

First, I need to throw out a massive thank you to Ras over at Schneide Blog, not only for his wiring guide without which I'd have been scratching my head for weeks, but also linking through to this awesome NMEA sentence information page.


This module is only concerned with location updates, the receiver is capable of returning additional information.

I've had "Create NPM package for this" in my to-do list for almost a year and since I'm not finding the time, this is just the .js file.

Location Updates

Location data is cached to combine data from multiple NMEA sentences, when enough information is gathered, a "locationUpdate" event is triggered; you can expect to receive ~1 location event per second. Each location event includes:

  • longitude and latitude
  • altitude
  • accuracy
  • bearing
  • speed
  • GPS timestamp

The latitude and longitude are converted from DMS to +/- degrees so they can be easily stored in numeric database fields or plugged directly into Google Maps.

Fix Updates

Fix update events (fixStatusChange) are only triggered when the fix status has changed, you can call getFixStatus() to get the current status. Each fix update includes:

  • 'has fix' boolean
  • the fix type (2D or 3D)
  • the number of satellites (both used and visible)

Using the Module

This module depends on node-serialport which requires a newer version of Node than that which ships with Raspbian. There are instructions at the bottom of the node-serialport page explaining how to get an updated version of Node.

Next, you'll need to wire the GPS receiver to your Pi as described in Ras' wiring guide.

Finally, download and extract the zip file below.

You can run the project with: node ./main.js

To use in your own project, copy the sparqee_gps.js file from the com... directory into your project and include it (see the sample below.)

Sample Usage

The module is fully asynchronous and allows easy access to location events from the GPS receiver:

var SparqeeGps = require('./sparqee_gps');
var gps = new SparqeeGps();

/* Register a listener for fix status changes, these include whether a fix
   has been made, the type of fix (2D/3D) and the number of satellites. */
gps.on('fixStatusChange', function(fixStatus) {
    var hasFix = fixStatus.hasFix ? 'Yes' : 'No';
    var fixType = hasFix ? fixStatus.fixMode + 'D' : 'None';
    console.log('Fix status:\r\n  Has fix: ' + hasFix + '\r\n  Fix type: '
            + fixType + '\r\n  Satellites used: ' + fixStatus.satellites.used
            + '\r\n  Satellites visible: ' + fixStatus.satellites.visible);

/* Register for location updates. */
gps.on('locationUpdate', function(location) {
    console.log('Location update:\r\n  Accuracy: ' + location.accuracy
            + '\r\n  Altitude: ' + location.altitude + '\r\n  Bearing: '
            + location.bearing + '\r\n  Latitude: ' + location.latitude
            + '\r\n  Longitude: ' + location.longitude + '\r\n  Speed: '
            + location.speed + '\r\n  Timestamp: ' + location.utcTimestamp);

/* Register for errors, these include GPS sentence errors as well as any
   errors opening the TTY device. */
gps.on('error', function(err) {
});'/dev/ttyAMA0', function() {
    console.log('GPS initialised.');