Autostart OpenCPN on Boot

Since this project’s main intent is to create a dedicated chartplotter/autopilot, it doesn’t make sense that I need to open a terminal window, start the gpsd service, and then double-click the OpenCPN icon on the desktop to get everything up and running. It should all just start up once the RPi boots up, and since it’s simply a Linux computer, this is possible, and really quite easy

First, the gpsd service needs to be started. As mentioned previously, there are a few terminal commands that are used to start the service. I simply created a pearl script in /etc/init.d/  that performs those steps:

#! /bin/sh
# /etc/init.d/startgps
#
### BEGIN INIT INFO
# Provides: 			noip
# Required-Start:		$remote_fs $syslog
# Required-Stop:		$remote_fs $syslog
# Default-Start:		2 3 4 5
# Default-Stop:			0 1 6
# Short-Description:	Simple script to start a program at boot
# Description:			A simple star/stop script
### END INIT INFO

echo 'Starting GPSD'
sudo service gpsd restart
sudo killall gpsd
sudo gpsd /dev/ttyAMA0 -F /var/run/gpsd.sock

exit 0

Then, I registered it to run at startup using the update-rc.d command. After a reboot, I was able to simply open a terminal window and execute xgps successfully, proving that the GPS stream was available.

The next step was to launch OpenCPN. I tried many different ways, but many had difficulties reading the user config settings. The simplest way, that worked great, was to create a launcher and place it in an autostart folder inside /home/pi/.config. The launcher file was already on the desktop, so it was a simple copy/paste process.

And with that, on reboot, OpenCPN launches, and after a minute or two GPS acquires the satellites and the chartplotter portion of the project is complete.

Resources:

Advertisements

Detailed Raspberry Pi Setup Documentation

This is the detailed documentation of every step necessary to create the Raspberry Pi chartplotter computer. I upsized my SD card to an 8-gig version so I could have more room for charts and other programs, and when I did so, I documented the process. This is the same process that was done before, but this time it is documented much more thoroughly.

Setting Up Raspberry Pi

  1. Format a new SD card.
    On my windows machine, I used the SDCard.org application as the OOB Windows format apparently doesn’t work (I didn’t try it, just going off of forum posts).The only option I changed was to set FORMAT SIZE ADJUSTMENT = ON and give the volume a name.
  2. Download the NOOBS package from raspberrypi.org and extract onto the SD card
  3. Connect the RPI hardware
    • HDMI connection to a monitor
    • Ethernet connection to a router with internet connectivity
    • USB Keyboard & Mouse
  4. Insert the SD card into the Raspberry Pi and boot. Install the OS of your choice (I used Raspbian)
    Confirm overwriting of the data
  5. On first load, set a few settings. I used the following:
    • Boot to Desktop: ON
    • Overclock: Medium (950MHz ARM, 250MHz Core, 2 overvolt)
    • Update internationalization for US
      • Raspberry pi is a UK product, set the Locale, timezone, and keyboard layout to the US versions.
    • Reboot
  6. It’s always smart to get the latest updates for the OS, so:
    • sudo apt-get update
    • sudo apt-get upgrade
  7. Next I want to set the video resolution to something fast, and yet of high quality. I settled on 1280×720@60Hz (720p CEA : Group 1, Mode 4)
  8. I also don’t want the screen to get turned off, since it’s probable that the chartplotter will run for long periods unattended. I found a forum post that fixed it, by editing lightdm.conf
  9. I want to use a wireless keyboard with built in trackpad, so the next step is to set that up
    • This was a very rigorous and difficult process that entailed inserting the USB dongle and turning on the power switch on the keyboard!
  10. Up to this point, I was using wired Ethernet for internet access. I don’t have a hub on the boat, so I got a wireless USB adapter to connect through instead. Setup was a 2-minute task:
    • Turn off the Pi
    • Plug the adapter into the Pi, and disconnect Ethernet
    • Reboot
    • Open the WiFi Gui
    • Click scan. double-click the network you want to connect to.
    • Enter WiFi password
    • Click connect
  11. Install Geany for C/C++/Python development
    • sudo apt-get install geany
  12. Enable I2C communication (for Arduino and sensors)
    • edit /etc/modules
      • add i2c-bcm2708 and i2c-dev
    • edit /etc/modprobe.d/raspi-blacklist.conf
      • #blacklist i2c-bcm2708
    • sudo apt-get install python-smbus i2c-tools

At this point I have a RPI device up and running.

Setup OpenCPN

  1. Rather than replicate the instructions, and to make sure that they stay up to date as new versions are released, I refer to the instructions at http://www.agurney.com/raspberry-pi/pi-chart  since that is line-for-line what I did to install OpenCPN
    • I did update config.txt for vector charts so that if I change my mind it won’t crash
    • I did update opencpn.config for MEMCacheLimit=40 NCacheLimit=10 (Must be done after running OpenCPN for the first time)
  2. Reboot
  3. Download the appropriate NOAA charts, and extract them into a directory
    • You can use Raster or Vector charts. I use raster charts as I think they look cool, and they seem to perform better on the Raspberry Pi
  4. Add the directory to the charts directory in OpenCPN, and allow them to be scanned and indexed
  5. As you zoom in and pan, more charts will be indexed and scanned. This takes a while on the RPI, but it seems to be pretty stable. Spend some time getting the most common areas in your cruising grounds stored, I simply pan, zoom, and wait until the charts are indexed. I took 3 iterations until I got all the charts indexed
  6. Install the Konni Logbook plugin from http://opencpn.org/ocpn/downloadplugins

References

Chartplotter/Autopilot Design Overview

Over the past few weeks I haven’t had much opportunity to work on this project, but I have tossed around some ideas.

I have found that the project is now complicated enough that I needed to mock up a design for what I plan to do. Here’s the current design, mocked up on Fritzing :
Design

This way I can make sure that the required (and desired) components would be available without needing to add expansion boards. For example, by doing this exercise, I have discovered that a future capability – to be able to consume AIS signals – would require additional components. Most likely in the form of a powered USB hub, but possibly as additional Arduino-based devices to save on power.