Tuesday, April 17, 2018

OLED GPS display on Arduino with a little C++

 The Arduino language is actually C++ but you never see that unless you look at library source code which tends to be a C++ class. I've written a little code to read the $4.10 GPS and display a bit of info on a small OLED display using the excellent Adafruit library.

To avoid spaghetti code I put the parsing of the NMEA string into a class. This is a quick hack but you don't see many examples like this so here you go.

Just for fun I've boxed this little project up all held together with hot glue and running from a 3.3V LiPo cell. The low price of the GPS along with the low price of an Arduino Nano Pro makes this a very attractive platform for building embedded computing devices.

Display info from a cheap GPS on an Adafruit OLD display

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_SSD1306.h>
#include <SoftwareSerial.h>

SoftwareSerial GPS(2,3); // rx pin = 2, tx pin for GPS

#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

class NmeaRecord {
    NmeaRecord(char * line);
    // GPGGA fields
    enum {
    // string lengths, +1 for null terminator
    enum {
      kLabelLen = 7,
      kTimeStampLen = 11,
      kLatLen = 9,
      kLatNSLen = 2,
      kLonLen = 10,
      kLonEWLen = 2,
      kFixLen = 2,
      kSatellitesLen = 3,
      kHorizontalDilutionLen = 4,
      kAltitudeLen = 7
    char label[kLabelLen];
    char timeStamp[kTimeStampLen];
    char lat[kLatLen];
    char latNS[kLatNSLen];
    char lon[kLonLen];
    char lonEW[kLonEWLen];
    char fix[kFixLen];
    char satellites[kSatellitesLen];
    char horizontalDilution[kHorizontalDilutionLen];
    char altitude[kAltitudeLen];
    NmeaRecord::storeField(int index, char*field);

void setup()   { 
  // by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3C (for the 128x32)
  // init done

void loop() {
  String line = GPS.readStringUntil('$');
  NmeaRecord rec = NmeaRecord(line.c_str());
  // GPGGA,054540.000,3346.7737,S,15113.2178,E,2,12,0.99,94.2,M,21.9
  display.print("UTC: ");
  display.print(" sats=");

  display.print("Lat: ");

  display.print("Lng: ");

  display.print("Alt: ");
  display.print("m   fix=");

NmeaRecord::NmeaRecord(char *line) {
  char *token;
  token = strtok(line, ",");
  if(strcmp(token, "GPGGA") != 0) {
    return; // don't parse
  int fieldIndex = 0;
  while(token != NULL) {
    Serial.print("index = ");
    Serial.print(", token = ");
    this->storeField(fieldIndex, token);
    token = strtok(NULL, ",");

NmeaRecord::storeField(int index, char*field) {
  Serial.print("Storefield index = ");
    Serial.print(", field = ");
  switch(index) {
    case eLabel:
      strncpy(label, field, kLabelLen);
    case eTimeStamp:
      strncpy(timeStamp, field, kTimeStampLen);
      Serial.print("got timeStamp = ");
    case eLat:
      strncpy(lat, field, kLatLen);
    case eLatNS:
      strncpy(latNS, field, kLatNSLen);
    case eLon:
      strncpy(lon, field, kLonLen);
    case eLonEW:
      strncpy(lonEW, field, kLonEWLen);
    case eFix:
      strncpy(fix, field, kFixLen);
    case eSatellites:
      strncpy(satellites, field, kSatellitesLen);
    case eHorizDilution:
      strncpy(horizontalDilution, field, kHorizontalDilutionLen);
    case eAltitude:
      strncpy(altitude, field, kAltitudeLen);

String formatTime(String timeString) {
  String newTime = timeString.substring(0,2);
  newTime += ":";
  newTime += timeString.substring(2,4);
  newTime += ":";
  newTime += timeString.substring(4,6);
  return newTime;

String formatLat(String raw) {
  // 4807.038,N   Latitude 48 deg 07.038' N
  String result = raw.substring(0,2);
  result += " deg ";
  result += raw.substring(2,7);
  return result;

String formatLng(String raw) {
  //  01131.000,E  Longitude 11 deg 31.000' E
  String result = raw.substring(0,3);
  result += " deg ";
  result += raw.substring(3,8);
  return result;

Monday, April 16, 2018

The VK3ZZC "Horror" transmitter

A fond memory from my early days of ham radio was talking with Ralph, VK3ZZC, on 2m as he drifted up and down. To my amazement he was using a home brew valve transmitter he dubbed the "horror mitters".

I just noticed that he has written a post about this project here. It's worth having a look through all of Ralph's site as there's lots of good stuff.

In my view this transmitter is a thing of beauty.

(Photo from Ralph's site, used with permission).

Low cost Neo-6M GPS works well

Ross, VK1UN, tipped me off to these GPS modules available from Aliexpress for AU$4.10. At that price I ordered 2. Here's the ad as it appears at the moment.

Here's me running it via a USB serial device supplying 3.3V. The specs say it will run from 3.3 - 5V. Default baud rate is 9600 and amazingly these devices have the 1Hz PPM output which used to only be available on the more expensive modules.

With a little bit of tinkering I've now got it displaying on an OLED display. Makes a nice clock for the shack.

Amazing that a device costing $4 can receive satellites.

Sunday, April 15, 2018

Vanlife: another tour south

I'm back from a tour south from Sydney ending up in Melbourne. Gradually I'm learning how to find places to stay that I like.

My preference is for places that are very quiet and look out at water or nice bush. The most up to date reference is the WikiCamps app. (This is a very poorly designed app, but the information in it is good). Reviews of camp sites are naturally in terms of what the reviewer likes so you tend to find great reviews for crowded sites that happen to have clean toilets.

Caravan parks can be nice if the unpowered sites are well away from the powered sites where the giant caravans tend to go.

The trick seems to be to find locations on WikiCamps and then check them out from Google's satellite view to get an idea of the layout.

On this trip I met up with my sister Jane and her partner Paul who have a lovely "teardrop" trailer.

It's very compact and presumably easy to tow. You sleep inside but it's pretty cramped but comfortable.

I also met a wonderful French Canadian couple who had sailed to Australia and are now touring around in a van.

It's fascinating to see how vans are configured. They shared red wine with me which they gleefully said had come from Aldi and wasn't too bad for $5.

One trick I've discovered is sleeping in the bush and then visiting the sea for breakfast and a swim.

It's lovely sitting in the van and having vastly different views from day to day.

The configuration is gradually changing. These days, when parked, I fold the passenger seat down and place the fridge there so there's more cabin space. I have a small folding chair from Banggood and this was great on a day when there was rain.

The mosquito net (there were mosquitoes and wasps at this site) is held up with magnets.

The van is going pretty well but the oil light came on and it needed a bit over a litre of oil to be filled up again. It's now done 378,000 Km and I'm not sure if it's normal to be using some oil like this.

Tuesday, April 03, 2018

WSPR Watch iOS app updated

Since retiring from full time work over a year ago, I've had a break from iOS programming. Doing something as a job is a great way to lose interest in it as a hobby.

Recently, after a dalliance with Google's excellent cross platform framework Flutter (and the Dart language),  I decided to have a play with the latest version of Swift, 4.1. I'm pretty familiar with the Cocoa frameworks but in line with Swift conventions many of the APIs have changed. Happily, Apple's documentation browser is excellent these days.

WSPR Watch is a free app I wrote some years ago basically for myself to provide a quick way to check for WSPR (Weak Signal Propagation Reporter) signal reports from a phone without having to use a web browser.

Over the past week or so I re-wrote the app in Swift 4.1 and found this a very pleasant environment to work in. A problem with the rapid changes in the Swift language in recent years is that when you search for how to do something you'll find a version of the code that isn't quite right with the latest Swift. This problem will hopefully diminish over time.

The other thing that's changed dramatically for the better is the whole process of submitting an app to the Apple store. What used to take a week now takes hours and the process is much more straight forward than it used to be. App signing used to be a buggy mess but now seems to work reliably too.

Thanks to my beta testers and particularly Ross, VK1UN, for bug reports and feature suggestions.

Saturday, March 31, 2018

Leadstar D12 TV with Raspberry Pi

The Leadstar 12V TV I bought for the van has HDMI input and it's an obvious possible display for a Raspberry Pi.

The screen's native resolution is 1280x800 but by default the Raspberry Pi doesn't offer this resolution in the GUI configuration software.

By default the Pi outputs 1080 lines which is readable on this screen but a little fuzzy.

To get the Pi to output the native resolution I edited /boot/config.txt as follows:


This now boots up in 1280x800 at 60Hz and works nicely. As mentioned in a previous post this TV cost $130 on eBay and seems decent. It runs on 12V and has an internal re-chargeable battery. The built-in software doesn't know about the Australian band plan. The seller sent me a RAR archive with new software but for some reason it doesn't like it and won't update.

Anyhow, this is a good screen for a small Raspberry Pi setup.

Friday, March 30, 2018

Increasingly irritating trying to read text on the web

Presumably desperate measures to fund journalism are leading to increasingly intrusive ads but I'm finding reading text on line is getting difficult. Here's what it's like opening a story on Vice.com:

Ads load above content, scrolling down what I'm reading. Ads slide up from the bottom obscuring the text and animation down the right draw my eye. To top it off, Safari now warns that significant energy is being used - maybe they're mining crypto-currency too?

Safari now won't auto-play videos with sound and soon Google Chrome will do the same thing plus block other annoying styles of ads. This is a war for our attention and I doubt it will stop there.

The answer on macOS and iOS is to use "reader view" which works well on most sites but strips away all the design. I've set reader view as on by default on some sites and maybe that's the answer.

Sorry for the rant but reading the news shouldn't be irritating. Note that I pay for Fairfax and Guardian but like to read more widely.

Tuesday, March 27, 2018

Vanlife: Improved electric system

The van came with a big box of batteries and wires in the middle of the space behind the driver's seat.

This box was a bit of a mess and contained two different sorts of batteries in parallel. There was a Redarc SBI12 relay that lets the auxiliary battery charge from the alternator but it avoids flattening the starter battery by only connecting when the motor is running and the alternator voltage is good.

Mysteriously though the 60A fuse was blown...

I ripped all the old stuff out and have been gradually re-using bits and getting things going again.

This week I figured out the correct wiring for the Redarc SBI12 and confirmed that it's working correctly. This will be particularly important if I'm out and not getting enough sun to run the fridge.

The 12V cable from the starter battery emerged from a hole in the floor and this morning I paid a few hundred dollars at an auto-electrician to run a new cable and remove the old one. Also I've mounted the old switch box in a plastic case screwed to the wall. All looks much neater now.

There is still room for improvement but it feels more spacious and I'm happy that I now understand how everything is wired.

The auto-electrician put the van up on a hoist which let me take a good look underneath for the first time. There's a few mystery wires hanging down and I can see the replaced differential but otherwise it looks pretty good for a van that's done 378,000Km.

In other news, I've purchased a 12 inch TV that runs on 12V for the van. $130 on eBay. It seems to be a Leadstar D12 and has the ability to play from USB or SD card and can record off air. Having HDMI in means that it might be useful as a portable screen for a Raspberry Pi project.

The TV is re-chargeable but I read reviews saying that it only runs about 2 hours. It came without the Australian band plan but I scanned in Czech and it seemed to find channels. The seller has sent me new firmware which I'll flash shortly.


I took the TV but never used it and will keep it for Raspberry Pi use.