Code Monkey home page Code Monkey logo

ubloxgps.swift's Introduction

UBloxGPS.swift

A Swift library for boards with the u-Blox 6/7/8 family of A-GPS receivers with an UART serial connection.

Linux-only Swift 4 compatible License: MIT

Summary

This library interfaces with boards based on u-Blox 6/7/8 A-GPS receivers, that use the NMEA0183 protocol to provide GPS data over an UART serial connection (for a low cost option, search for some NEO6M-based board that usually cost around a measly $20). UBX configuration commands and connection via I2C are not supported at the moment.

You'll be able to retrieve your current location, elevation, speed, status data on the currently reachable satellites and more.

The first time you'll use the receiver it will need a few minutes to find some satellites and provide a position, but after that a few seconds will be enough to obtain a valid position.

NEO6M board

Supported Boards

Every board supported by SwiftyGPIO with support for UART interfaces.

To use this library, you'll need a Linux ARM board with Swift 3.x.

The example below will use a RaspberryPi 2 board but you can easily modify the example to use one the the other supported boards, a full working demo projects for the RaspberryPi2 is available in the Examples directory.

Usage

If you are using a RaspberryPi, run raspi-config and enable the serial port but disable the Linux login support in Interfacing Options > Serial.

The first thing we need to do is to obtain an instance of UARTInterface from SwiftyGPIO and use it to initialize the UBloxGPS object:

import SwiftyGPIO
import UBloxGPS

let uarts = SwiftyGPIO.UARTs(for:.RaspberryPi2)!
var uart = uarts[0]

let gps = UBloxGPS(uart)

We must then start the background thread that will update the GPS location and other information calling startUpdating. The library allows to print a quick recap of all available data with printStatus:

gps.startUpdating()

// We'll simply clear the screen and print a recap of the current gps data
while true {
   system("clear")
   gps.printStatus()
   sleep(2)
}

The UBloxGPS object has some accessible properties that you can use to retrieve the specific data you need:

Property Description
isDataValid Is the current GPS data valid? True when a valid position is obtained
datetime Date and time in stringified format
latitude Latitude in degrees
longitude Longitude in degrees
satellitesNum Number of visible satellites
satellitesActiveNum Number of active satellites (visible and with a signal strong enough to used)
altitude Altitude from sea level
altitudeUnit Unit for altitude
satellites Information about the satellites that are currently in the line of sight (max 12), the structure contains: a numerical id, elevation (0..60 in degrees), azimuth (0..360 in degrees) and an snr(dB) value for an indication of the noise affecting the signal

When you don't need to update the location data anymore or to pause updates just call stopUpdating().

Installation

Please refer to the SwiftyGPIO readme for Swift installation instructions.

Once your board runs Swift, if your version support the Swift Package Manager, you can simply add this library as a dependency of your project and compile with swift build:

  let package = Package(
      name: "MyProject",
      dependencies: [
    .Package(url: "https://github.com/uraimo/UBloxGPS.swift.git", majorVersion: 1),
    ...
      ]
      ...
  ) 

The directory Examples contains sample projects that uses SPM, compile it and run the sample with ./.build/debug/TestNEO6M.

If SPM is not supported, you'll need to manually download the library and its dependencies:

wget https://raw.githubusercontent.com/uraimo/UBloxGPS.swift/master/Sources/UBloxGPS.swift https://raw.githubusercontent.com/uraimo/SwiftyGPIO/master/Sources/SwiftyGPIO.swift https://raw.githubusercontent.com/uraimo/SwiftyGPIO/master/Sources/Presets.swift https://raw.githubusercontent.com/uraimo/SwiftyGPIO/master/Sources/UART.swift https://raw.githubusercontent.com/uraimo/SwiftyGPIO/master/Sources/SunXi.swift  

And once all the files have been downloaded, create an additional file that will contain the code of your application (e.g. main.swift). When your code is ready, compile it with:

swiftc *.swift

The compiler will create a main executable.

ubloxgps.swift's People

Contributors

uraimo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

datishans

ubloxgps.swift's Issues

USB

Would it be possible to make it work with USB to TTL?

I have the Adafruit Ultimate GPS and FTDI Serial TTL-232 USB Cable.
If I use 'cgps -s' on the Raspberry Pi I can see the data.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.