GPS - dtex/johnny-five GitHub Wiki
The GPS
class constructs objects that represent a single GPS (Global Positioning System) receiver attached to the physical board. The receiver can be used to find current latitude, longitude, altitude, course and ground speed. GPS receivers get their signals from an array of 32 satellites orbiting the Earth at an altitude of 12,600 miles. In other words, you can use Johnny-Five to talk to things in outer space (Is that cool or what?)
Supported chipsets, modules and breakouts:
Any GPS Module that by default transmits NMEA sentences over serial at 9600bps should "just work". If your device automatically transmits NMEA sentences at a different baud rate, you can set a custom baud rate in the configuration options.
The universe of breakouts, modules, receivers and chip sets can be confusing. Just because you don't see your device listed here doesn't mean it won't work. If you have a device that is not explicitly listed here, open an issue with links to as much documentation you can find on your device and we will take a look. If you have a device not explicitly listed here and it works, please update our list above and add and example to the eg folder.
This list will continue to be updated as more component support is implemented and tested.
Parameters
- General Options
Property | Type | Value/Description | Default | Required |
---|---|---|---|---|
port | string | The microcontroller's serial port to use. See more below | io.SERIAL_PORT_IDs.DEFAULT | no |
pins | array | { tx: ?, rx: ?[, onOff: ?]} | none | no |
breakout | string | The breakout or shield being used | none | no |
receiver | string | The receiver module being used | none | no |
chip | string | The chipset being used on the receiver module | none | no |
fixed | integer | The number of digits after the decimal | 6 | no |
baud | integer | The baud rate for communication over serial | 9600 | no |
frequency | integer | The frequency of updates in hz (per second) | 1 | no |
Shape
Property Name | Description | Read Only |
---|---|---|
latitude | Current latitude | Yes |
longitude | Current longitude | Yes |
altitude | Current altitude | Yes |
sat | Satellite operation details {pdop, hdop, vdop} | Yes |
course | Current course | Yes |
speed | Current ground speed | Yes |
time | Time of last fix | Yes |
Component Initialization
Default
// U-Blox NEO-6M attached to Arduino UNO on Software Serial 0, pins 10 and 11
new five.GPS([10,11]);
Adafruit Ultimate GPS Breakout
// Adafruit Ultimate GPS attached to Arduino UNO on Software Serial 0, pins 10 and 11
new five.GPS({
pins: [10,11],
breakout: "ADAFRUIT_ULTIMATE_GPS"
});
Usage
var five = require("johnny-five");
var board = new five.Board();
board.on("ready", function() {
var gps = new five.GPS({
pins: {tx: 10, rx: 11}
});
// If lat, long, course or speed change log it
gps.on("change", function() {
console.log(this.longitude, this.latitude);
});
});
API
-
sendCommand(commandString) Send a command to the GPS chipset. The checksum and CR/LF will be automatically appended.
var gps = new five.GPS([10,11]); // Warm reboot gps.sendCommand("$PMTK103");
-
restart(coldRestart) Reboot the receiver. If coldRestart is true, all cached positioning data is flushed. If you do this, it could take up to 60 seconds to get a new fix.
var gps = new five.GPS([10,11]); // Warm reboot gps.restart();
Events
-
message A valid message (NMEA Sentence) was received from the GPS.
-
operations Satellite operating details have received.
-
acknowledge An "acknowledge" message was received from the GPS chipset.
-
unknown An valid but unrecognized message was received from the GPS chipset.
-
change The position has changed.
-
navigation The speed or direction has changed.
Notes on Serial
GPS is the first class in Johnny-Five to leverage firmata's new support for serial. Other IO plugins are following suit and adding their own support for serial.
The Arduino Uno has a single UART. Assuming your Arduino is connected to a computer via USB, that UART is already in use. By default the GPS class will try and use software serial to connect but please note that software serial does not work reliably above 57600bps. Other boards such as the Arduino Mega have multiple UART's so hardware serial is the better option on those boards.
Arduino boards that use the SAM and SAMD architectures (i.e. the Due and Zero) do not support Software Serial at all.