Brad Buskey
Published © GPL3+

GPS Info To OLED

Send the GPS output to the OLED screen to show location.

BeginnerShowcase (no instructions)15 minutes3,350
GPS Info To OLED

Things used in this project

Hardware components

Omega2 Plus
Onion Corporation Omega2 Plus
×1
Expansion Dock
Onion Corporation Expansion Dock
×1
OLED Expansion
Onion Corporation OLED Expansion
×1
Onion Corporation Onion GPS Expansion
×1

Story

Read more

Code

OPKG Installs

SH
Please run the commands below to install the required packages. You can cut/paste this straight into the command line if you are using PuTTY. The Onion Cloud terminal program does not allow for cut/paste.
opkg update
opkg install python3 python-light pyOledExp pyOmegaExpansion oled-exp ogps

getgps.sh

SH
Shell script to read the output from the GPS chip and put it in a text file to be read by another (python) script to be written to the OLED.
#!/bin/ash

# Get the GPS information and write it to a file.
ubus -S call gps info > /root/gpsinfo.txt

# Call the python script to write to the OLED.
python /root/showgps.py

# Exit the script
exit 0

showgps.py

Python
This is the meat of the project. This script reads the file created by the shell script, pulls the appropriate data and formats it in a readable way to be displayed on the OLED script.

TODO: Has been done. It now takes into account for a 0 byte file and for a file showing no signal.
#!/usr/bin/env python

#======================================================
# Show GPS Location on the OLED Screen on the Omega 2+
# Written By: Brad Buskey
# Contact Me: deckyon@gmail.com
#======================================================

#Initialize the script and pull in the required libraries.
from OmegaExpansion import oledExp
import time
import json
import os

# Initialize and clear the OLED screen
oledExp.setVerbosity(0)
oledExp.setTextColumns()
oledExp.driverInit()

# Draw the header for the display
oledExp.setCursor(0, 0)
oledExp.write("__Current GPS Info__")
oledExp.setCursor(1, 0)
oledExp.write("====================")

# Check fo the file size of gpsinfo.txt and exit if < 1
if os.path.getsize('/root/gpsinfo.txt') == 0:
	# File is empty or doesnt exist
	oledExp.setCursor(3, 0)
	oledExp.write("GPS Info doesnt seem")
	oledExp.setCursor(4, 0)
	oledExp.write("to exist.")
	oledExp.setCursor(6, 0)
	oledExp.write("Check GPSInfo file.")
	exit()

# Get the data fro mthe file written to in the shell script.
with file('/root/gpsinfo.txt', 'r') as gpsfile:
	gpsinfo = json.load(gpsfile)
	
# Pause the script and pretend to look stuff up.
time.sleep(2)

# Test for the existence of a GPS signal
if gpsinfo.has_key('signal'):
	# No GPS Signal, let the OLED reflect that
	oledExp.setCursor(3, 0)
	oledExp.write("No GPS signal found")
	oledExp.setCursor(4, 0)
	oledExp.write("Please try later!")
elif gpsinfo.has_key('latitude'):
	# Pull out the data from the desired fields in the dictionary 'gpsinfo'
	lat=gpsinfo['latitude']
	lon=gpsinfo['longitude']
	elv=gpsinfo['elevation']
	cou=gpsinfo['course']
	spd=gpsinfo['speed']
	# Build the data strings to be written to the OLED
	lat="Latitude : "+lat
	lon="Longitude: "+lon
	elv="Elevation: "+elv
	cou="Course   : "+cou
	spd="Speed    : "+spd
	# Draw out the rest of the information gathered from 'gpsinfo'
	oledExp.setCursor(2, 0)
	oledExp.write(lat)
	oledExp.setCursor(3, 0)
	oledExp.write(lon)
	oledExp.setCursor(4, 0)
	oledExp.write(elv)
	oledExp.setCursor(5, 0)
	oledExp.write(cou)
	oledExp.setCursor(6, 0)
	oledExp.write(spd)
	
# Exit the script cleanly
exit()

gpsinfo.txt

Plain text
This is the file created by the Shell script and read by the Python script. This is just an example of when there is a good GPS signal and it can get a lock and return the location.
{"age":6357,"latitude":"38.1234","longitude":"-80.1234","elevation":"1234.5","course":"12.34","speed":"N"}

gpsinfo.txt (No Signal)

Plain text
This is the output if there is no GPS signal. This is the final piece for me to do for this project to work completely. The script will check for this instance of the file, as well as an empty gpsinfo.txt
{"signal":"false"}

Credits

Brad Buskey

Brad Buskey

6 projects • 14 followers
Just getting started.. Currently have the Onion Omega 2+, Raspberry Pi 3 B +, Raspberry Pi Zero W. Working in Python.

Comments