A few weeks since the last post, mainly due to the tenacious cold & flu-like bug circulating around the family. Since that's now gone I was keen to look at more GPS coding on the Pi.


My last attempt had reading of the serial port running fine until it was interrupted, then it produced errors on reading caused by the serial stream being read off of a character boundary.

Furthermore once the stream has been read for a while it then only produced 8 or so characters per read - pointing to a buffer starvation as the read terminated before the characters from the GPS could be read in. Both of these were fixed by treating the GPS as a serial stream device with a defined timeout:


gpsStream = serial.Serial(gpsDevice, 9600, timeout=1)


At this point I wanted to auto-mount my USB device so I edited the /etc/fstab and added a line for the USB drive, now this mounts automatically.

Then being conscious of the need to keep software up to date I then performed a apt-get update/upgrade cycle, noting that the microstack code was listed among the packages being updated.


Bad move. Once the new software had installed my code now refused to run - an error being reported at the GPS module import...


import microstacknode.gps.l80gps


and saying this module could not be found.

After an hour or so of googling this and not getting anywhere I had a look inside the /usr/lib structure where all of these libraries live and found the microstacknode folder area.

I noticed that the folder path to the l80gps module included a 'hardware' folder that wasn't represented in the import path.

Sure enough once I changed the import statement to:


import microstacknode.hardware.gps.l80gps


... and the code once again ran happily. I have no idea if the update actually changed anything in the folder path - all I know is that it ran OK prior to the update and didn't afterwards until I made the change to the import statement, so if this also happened in your project that might help you out.


Now I was able to modify and debug the code to watch for an active fix, extract the lat and long and save these to a file for the client to inspect as well as display these on the LCD. At the same time I experimented with using the piFace switches so that rather than killing the code from a Ctrl-C I can now exit gracefully by pressing a LCD board button. All pretty much Pi-101 I'm sure for most but new to me and useful in working out what I can and can't do with this set of boards.


This means that the GPS interface code is fairly complete for now and I need to remove its access to the LCD and package it up to be run automatically when the Pi boots. It will write its results to a file for the client to read. It also writes a log file to the USB so that if I ever need to see what the GPS is outputting I have a trace of that (and with a 64GB USB stick to play with there's plenty of space for logs!).


The next job is to think more about what the GPS client is going to look like. Like some of the other examples I'm thinking of reading in a list of caches and allowing the user to select one using the switches on the LCD board, whereupon the distance to the cache will be calculated. This is where I might add some electronics to display a LED bar graph based on the distance to go once the unit is within, say, 50m of the cache. I'll think some more about that and post something next week...