Skip to content

Commit

Permalink
Merge pull request #13 from 1oginov/dev
Browse files Browse the repository at this point in the history
Release v1.4.0
  • Loading branch information
loginov-rocks committed Sep 3, 2018
2 parents 21a7cf5 + 721f6d9 commit edd2211
Show file tree
Hide file tree
Showing 14 changed files with 292 additions and 211 deletions.
25 changes: 25 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"C_Cpp.default.defines": [
// Fixes `Serial1`, `Serial2`, `Serial3` undefined.
"UBRR1H",
"UBRR2H",
"UBRR3H",
// Fixes `Serial` undefined.
"USBCON",
],
"C_Cpp.default.includePath": [
// Fixes `Arduino.h` and related headers undefined.
"C:/Program Files (x86)/Arduino/hardware/arduino/avr/cores/arduino",
"C:/Program Files (x86)/Arduino/hardware/arduino/avr/variants/standard",
"C:/Program Files (x86)/Arduino/hardware/tools/avr/avr/include",
"C:/Program Files (x86)/Arduino/hardware/tools/avr/lib/gcc/avr/5.4.0/include",
// Fixes `SoftwareSerial.h` undefined.
"C:/Program Files (x86)/Arduino/hardware/arduino/avr/libraries/SoftwareSerial/src",
// Fixes library files undefined.
"${workspaceFolder}/src",
],
"editor.rulers": [
120,
],
"editor.tabSize": 4,
}
20 changes: 9 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ headingAcc, pDOP, reserved2, reserved3.
*NAV-SOL (Navigation Solution Information):* iTOW, fTOW, week, gpsFix, flags, ecefX, ecefY, ecefZ, pAcc, ecefVX, ecefVY,
ecefVZ, sAcc, pDOP, reserved1, numSV, reserved2.

## Quick Start
## Quick start

Download `UbxGps` and place it to the Arduino libraries directory. Refer to
[How to install Libraries](https://www.arduino.cc/en/Guide/Libraries) for details.
Expand All @@ -50,7 +50,7 @@ After that you can use included examples or play with the following simple sketc
```cpp
#include "UbxGpsNavPvt.h"

UbxGpsNavPvt gps(Serial3);
UbxGpsNavPvt<HardwareSerial> gps(Serial3);

void setup()
{
Expand Down Expand Up @@ -117,7 +117,7 @@ send some data.
### Step 3. Meet u-center
For u-blox GPS module configuration we will use **u-center** program that you can find
[here](https://www.u-blox.com/en/product/u-center-windows). It parses data from GPS module and provides useful tools to
[here](https://www.u-blox.com/en/product/u-center). It parses data from GPS module and provides useful tools to
work with it. Launch program, choose appropriate COM port and set baudrate, 9600 for default. It will start getting some
data.
Expand Down Expand Up @@ -183,17 +183,15 @@ More details about u-blox GPS module configuration are in ***Receiver Descriptio
## Compatible GPS modules
* NEO-7M — tested
* Other u-blox GPS modules, which supports UBX protocol
* *Please, notice me if it works with your GPS module*
* NEO-7M
* Other u-blox GPS modules supporting UBX protocol
* *Please notice (create an issue) if it works with your GPS module*
## Contribution
Feel free to add something useful to this library :relaxed: For example new classes for UBX packets!
Please use the [dev](https://github.com/1oginov/UbxGps/tree/dev) branch and feel free to contribute!
Please, use the [dev](https://github.com/1oginov/UbxGps/tree/dev) branch for contribution.
## Links
## Reference
* [u-blox Website](https://www.u-blox.com)
* [u-center Download page](https://www.u-blox.com/en/product/u-center-windows)
* [u-center Download page](https://www.u-blox.com/en/product/u-center)
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@
* GND - GND
*/

#include "UbxGpsNavPvt.h"
#include <Arduino.h>
#include <UbxGpsNavPvt.h>

#define GPS_BAUDRATE 115200L
#define PC_BAUDRATE 115200L

#define PC_BAUDRATE 9600
#define GPS_BAUDRATE 9600
#define DATETIME_FORMAT "%04d.%02d.%02d %02d:%02d:%02d"
#define DATETIME_LENGTH 20

UbxGpsNavPvt gps(Serial3);
UbxGpsNavPvt<HardwareSerial> gps(Serial3);

char datetime[DATETIME_LENGTH];

Expand Down
56 changes: 56 additions & 0 deletions examples/UbxGpsNavPvtUno/UbxGpsNavPvtUno.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* The sketch parses UBX messages from u-blox NEO-7M and outputs ready GPS data to a serial port in a CSV format.
*
* u-blox NEO-7M - Arduino Uno
* VCC - 5V
* RX - 3
* TX - 2
* GND - GND
*/

#include <Arduino.h>
#include <SoftwareSerial.h>
#include <UbxGpsNavPvt.h>

#define GPS_BAUDRATE 115200L
#define GPS_RX 3
#define GPS_TX 2
#define PC_BAUDRATE 115200L

#define DATETIME_FORMAT "%04d.%02d.%02d %02d:%02d:%02d"
#define DATETIME_LENGTH 20

SoftwareSerial ss(GPS_TX, GPS_RX);
UbxGpsNavPvt<SoftwareSerial> gps(ss);

char datetime[DATETIME_LENGTH];

void setup()
{
Serial.begin(PC_BAUDRATE);
gps.begin(GPS_BAUDRATE);
}

void loop()
{
if (gps.ready())
{
snprintf(datetime, DATETIME_LENGTH, DATETIME_FORMAT, gps.year, gps.month, gps.day, gps.hour, gps.min, gps.sec);

Serial.print(datetime);
Serial.print(',');
Serial.print(gps.lon / 10000000.0, 7);
Serial.print(',');
Serial.print(gps.lat / 10000000.0, 7);
Serial.print(',');
Serial.print(gps.height / 1000.0, 3);
Serial.print(',');
Serial.print(gps.gSpeed * 0.0036, 5);
Serial.print(',');
Serial.print(gps.heading / 100000.0, 5);
Serial.print(',');
Serial.print(gps.fixType);
Serial.print(',');
Serial.println(gps.numSV);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@
* GND - GND
*/

#define PC_SERIAL Serial
#include <Arduino.h>

#define PC_SERIAL Serial
#define PC_BAUDRATE 115200L
#define GPS_SERIAL Serial3
#define GPS_SERIAL Serial3

// Default baudrate is determined by the receiver manufacturer.
#define GPS_DEFAULT_BAUDRATE 9600L
#define GPS_DEFAULT_BAUDRATE 9600L

// Wanted buadrate at the moment can be 9600L (not changed after defaults) or 115200L (changed by the
// `changeBaudrate()` function with a prepared message).
#define GPS_WANTED_BAUDRATE 115200L
#define GPS_WANTED_BAUDRATE 115200L

// Array of possible baudrates that can be used by the receiver, sorted descending to prevent excess Serial flush/begin
// after restoring defaults. You can uncomment values that can be used by your receiver before the auto-configuration.
Expand All @@ -40,7 +42,7 @@ void setup()
PC_SERIAL.begin(PC_BAUDRATE);
PC_SERIAL.println("Starting auto-configuration...");

// Restore the receiver default configuration
// Restore the receiver default configuration.
for (byte i = 0; i < sizeof(possibleBaudrates) / sizeof(*possibleBaudrates); i++)
{
PC_SERIAL.print("Trying to restore defaults at ");
Expand All @@ -49,31 +51,31 @@ void setup()

if (i != 0)
{
delay(100); // Little delay before flushing
delay(100); // Little delay before flushing.
GPS_SERIAL.flush();
}

GPS_SERIAL.begin(possibleBaudrates[i]);
restoreDefaults();
}

// Switch the receiver serial to the default baudrate
// Switch the receiver serial to the default baudrate.
if (possibleBaudrates[sizeof(possibleBaudrates) / sizeof(*possibleBaudrates) - 1] != GPS_DEFAULT_BAUDRATE)
{
PC_SERIAL.print("Switching to the default baudrate which is ");
PC_SERIAL.print(GPS_DEFAULT_BAUDRATE);
PC_SERIAL.println("...");

delay(100); // Little delay before flushing
delay(100); // Little delay before flushing.
GPS_SERIAL.flush();
GPS_SERIAL.begin(GPS_DEFAULT_BAUDRATE);
}

// Disable NMEA messages by sending appropriate packets
// Disable NMEA messages by sending appropriate packets.
PC_SERIAL.println("Disabling NMEA messages...");
disableNmea();

// Switch the receiver serial to the wanted baudrate
// Switch the receiver serial to the wanted baudrate.
if (GPS_WANTED_BAUDRATE != GPS_DEFAULT_BAUDRATE)
{
PC_SERIAL.print("Switching receiver to the wanted baudrate which is ");
Expand All @@ -82,33 +84,33 @@ void setup()

changeBaudrate();

delay(100); // Little delay before flushing
delay(100); // Little delay before flushing.
GPS_SERIAL.flush();
GPS_SERIAL.begin(GPS_WANTED_BAUDRATE);
}

// Increase frequency to 100 ms
// Increase frequency to 100 ms.
PC_SERIAL.println("Changing receiving frequency to 100 ms...");
changeFrequency();

// Disable unnecessary channels like SBAS or QZSS
// Disable unnecessary channels like SBAS or QZSS.
PC_SERIAL.println("Disabling unnecessary channels...");
disableUnnecessaryChannels();

// Enable NAV-PVT messages
// Enable NAV-PVT messages.
PC_SERIAL.println("Enabling NAV-PVT messages...");
enableNavPvt();

PC_SERIAL.println("Auto-configuration is complete!");

delay(100); // Little delay before flushing
delay(100); // Little delay before flushing.
GPS_SERIAL.flush();
}

// Send a packet to the receiver to restore default configuration
// Send a packet to the receiver to restore default configuration.
void restoreDefaults()
{
// CFG-CFG packet
// CFG-CFG packet.
byte packet[] = {
0xB5, // sync char 1
0x62, // sync char 2
Expand Down Expand Up @@ -136,10 +138,10 @@ void restoreDefaults()
sendPacket(packet, sizeof(packet));
}

// Send a set of packets to the receiver to disable NMEA messages
// Send a set of packets to the receiver to disable NMEA messages.
void disableNmea()
{
// Array of two bytes for CFG-MSG packets payload
// Array of two bytes for CFG-MSG packets payload.
byte messages[][2] = {
{0xF0, 0x0A},
{0xF0, 0x09},
Expand All @@ -163,7 +165,7 @@ void disableNmea()
{0xF1, 0x06},
};

// CFG-MSG packet buffer
// CFG-MSG packet buffer.
byte packet[] = {
0xB5, // sync char 1
0x62, // sync char 2
Expand All @@ -179,23 +181,23 @@ void disableNmea()
};
byte packetSize = sizeof(packet);

// Offset to the place where payload starts
// Offset to the place where payload starts.
byte payloadOffset = 6;

// Iterate over the messages array
// Iterate over the messages array.
for (byte i = 0; i < sizeof(messages) / sizeof(*messages); i++)
{
// Copy two bytes of payload to the packet buffer
// Copy two bytes of payload to the packet buffer.
for (byte j = 0; j < sizeof(*messages); j++)
{
packet[payloadOffset + j] = messages[i][j];
}

// Set checksum bytes to the null
// Set checksum bytes to the null.
packet[packetSize - 2] = 0x00;
packet[packetSize - 1] = 0x00;

// Calculate checksum over the packet buffer excluding sync (first two) and checksum chars (last two)
// Calculate checksum over the packet buffer excluding sync (first two) and checksum chars (last two).
for (byte j = 0; j < packetSize - 4; j++)
{
packet[packetSize - 2] += packet[2 + j];
Expand All @@ -206,10 +208,10 @@ void disableNmea()
}
}

// Send a packet to the receiver to change baudrate to 115200
// Send a packet to the receiver to change baudrate to 115200.
void changeBaudrate()
{
// CFG-PRT packet
// CFG-PRT packet.
byte packet[] = {
0xB5, // sync char 1
0x62, // sync char 2
Expand Down Expand Up @@ -244,10 +246,10 @@ void changeBaudrate()
sendPacket(packet, sizeof(packet));
}

// Send a packet to the receiver to change frequency to 100 ms
// Send a packet to the receiver to change frequency to 100 ms.
void changeFrequency()
{
// CFG-RATE packet
// CFG-RATE packet.
byte packet[] = {
0xB5, // sync char 1
0x62, // sync char 2
Expand All @@ -268,10 +270,10 @@ void changeFrequency()
sendPacket(packet, sizeof(packet));
}

// Send a packet to the receiver to disable unnecessary channels
// Send a packet to the receiver to disable unnecessary channels.
void disableUnnecessaryChannels()
{
// CFG-GNSS packet
// CFG-GNSS packet.
byte packet[] = {
0xB5, // sync char 1
0x62, // sync char 2
Expand All @@ -293,10 +295,10 @@ void disableUnnecessaryChannels()
sendPacket(packet, sizeof(packet));
}

// Send a packet to the receiver to enable NAV-PVT messages
// Send a packet to the receiver to enable NAV-PVT messages.
void enableNavPvt()
{
// CFG-MSG packet
// CFG-MSG packet.
byte packet[] = {
0xB5, // sync char 1
0x62, // sync char 2
Expand All @@ -314,7 +316,7 @@ void enableNavPvt()
sendPacket(packet, sizeof(packet));
}

// Send the packet specified to the receiver
// Send the packet specified to the receiver.
void sendPacket(byte *packet, byte len)
{
for (byte i = 0; i < len; i++)
Expand All @@ -325,7 +327,7 @@ void sendPacket(byte *packet, byte len)
printPacket(packet, len);
}

// Print the packet specified to the PC serial in a hexadecimal form
// Print the packet specified to the PC serial in a hexadecimal form.
void printPacket(byte *packet, byte len)
{
char temp[3];
Expand All @@ -344,7 +346,7 @@ void printPacket(byte *packet, byte len)
PC_SERIAL.println();
}

// If there is a data from the receiver, read it and send to the PC or vice versa
// If there is a data from the receiver, read it and send to the PC or vice versa.
void loop()
{
if (GPS_SERIAL.available())
Expand Down
Loading

0 comments on commit edd2211

Please sign in to comment.