Skip navigation
2015
pvalyk

Setting up the system

Posted by pvalyk Oct 15, 2015

     First off, let say thanks for being part of this project. Sorry for the late post.

     A couple of weeks ago I started assembling my project. For starters I choose to setup just the GPS module. The LCD display will come after. I put the system on my fridge, right near the wifi router.

 

WP_20151007_005.jpg

     When I first booted into latest version of Raspbian I ran the Configuration menu . In Advanced Options>Serial  set disable serial. I rebooted, and the ran:

Screen Shot 2015-10-07 at 7.54.32 PM.png

sudo apt-get update && sudo apt-get upgrade


     and

Screen Shot 2015-10-07 at 7.54.16 PM.png

sudo apt-get install python3-microstacknode

 

     and

 sudo apt-get install gpsd gpsd-clients python-gps

Screen Shot 2015-10-07 at 8.38.05 PM.png

     Then I comment out the following line in /etc/inittab by putting # in front of it so that it goes from this:

#T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100

 

     And remove all references to ttyAMA0 in /boot/cmdline.txt so that it goes from this:

 

dwc_otg.lpm_enable=0 console=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2

 

     I removed console = tty1 too.

     Now I configured GPSD:

 sudo dpkg-reconfigure gpsd

 

     -Choose Yes for automatically start gpsd.

     -Choose No for “should gpsd handle attached USB GPS receivers automatically”

     -Enter /dev/ttyAMA0 when asked “Device the GPS receiver is attached to”

     -Choose default for the other options.

sudo poweroff

 

     I unplugged the Raspberry Pi and attached the GPS module.

     My first mistake was that I replaced the GPS antenna with a wifi antenna or did not attached an antenna at all. That didn’t got any fix on satellite.

     I attached the antenna from the kit and got gps location.

     Now I ran

sudo gpsd /dev/ttyAMA0 -F /var/run/gpsd.sock

     and

cgps –s

 

     and got the latitude and longitude of my location.

 

     Use this as a great resource:

     https://github.com/microstack-IoT/python3-microstacknode

 

     To follow: load saved locations and display on the screen. I got a problem with module's switch. It came broken. Any Ideas?

WP_20150914_002.jpg

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...